fabscript 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. # -*- python -*-
  2. #
  3. # Copyright (c) 2016 Stefan Seefeld
  4. # All rights reserved.
  5. #
  6. # Distributed under the Boost Software License, Version 1.0.
  7. # (See accompanying file LICENSE_1_0.txt or copy at
  8. # http://www.boost.org/LICENSE_1_0.txt)
  9. from faber import platform
  10. from faber.feature import set
  11. from faber.tools.compiler import runpath
  12. from faber.tools.python import python, pythonpath
  13. from faber.artefacts.object import object
  14. from faber.artefacts.binary import binary
  15. from faber.artefacts.python import extension
  16. from faber.test import test, report, fail
  17. src = module('..src')
  18. python_libs=python.instance().libs
  19. features |= runpath(src.bpl.path, base='')
  20. def extension_test(name, ext=[], script=None, np=False,
  21. features=features, condition=None):
  22. """Create a Python extension test `name`.
  23. Arguments:
  24. * name: the name of the test.
  25. * ext: extensions to be compiled, <name> if none are given.
  26. * script: the test script to execute, <name>.py if none is given.
  27. * np: if true, add boost_numpy to sources
  28. * features: pre-defined features
  29. * condition: any condition under which to run the test
  30. Return:
  31. * the test artefact"""
  32. features=features.copy()
  33. extensions = []
  34. libs = [src.bnl, src.bpl] if np else [src.bpl]
  35. for e in ext or [name]:
  36. if type(e) is str: # build from a single source file
  37. n = e if e != name else e + '_ext'
  38. s = [e + '.cpp']
  39. else: # build from a list of source files
  40. n = e[0] if e[0] != name else e[0] + '_ext'
  41. s = [n + '.cpp' for n in e]
  42. e = extension(n, s + libs, features=features)
  43. features |= pythonpath(e.path, base='')
  44. extensions.append(e)
  45. if not script:
  46. script = name+'.py'
  47. return test(name, script, run=python.run, dependencies=extensions,
  48. features=features, condition=condition)
  49. tests = []
  50. for t in [('injected',),
  51. ('properties',),
  52. ('return_arg',),
  53. ('staticmethod',),
  54. ('boost_shared_ptr',),
  55. ('enable_shared_from_this',),
  56. ('andreas_beyer',),
  57. ('polymorphism',),
  58. ('polymorphism2',),
  59. ('wrapper_held_type',),
  60. ('minimal',),
  61. ('args',),
  62. ('raw_ctor',),
  63. ('exception_translator',),
  64. ('test_enum', ['enum_ext']),
  65. ('test_cltree', ['cltree']),
  66. ('newtest', ['m1', 'm2']),
  67. ('const_argument',),
  68. ('keywords_test', ['keywords']),
  69. ('test_pointer_adoption',),
  70. ('operators',),
  71. ('operators_wrapper',),
  72. ('callbacks',),
  73. ('defaults',),
  74. ('object',),
  75. ('list',),
  76. ('long',),
  77. ('dict',),
  78. ('tuple',),
  79. ('str',),
  80. ('slice',),
  81. ('virtual_functions',),
  82. ('back_reference',),
  83. ('implicit',),
  84. ('data_members',),
  85. ('ben_scott1',),
  86. ('bienstman1',),
  87. ('bienstman2',),
  88. ('bienstman3',),
  89. ('multi_arg_constructor',),
  90. ('iterator', ['iterator', 'input_iterator']),
  91. ('stl_iterator',),
  92. ('extract',),
  93. ('crossmod_opaque', ['crossmod_opaque_a', 'crossmod_opaque_b']),
  94. ('opaque',),
  95. ('voidptr',),
  96. ('pickle1',),
  97. ('pickle2',),
  98. ('pickle3',),
  99. ('pickle4',),
  100. ('nested',),
  101. ('docstring',),
  102. ('pytype_function',),
  103. ('vector_indexing_suite',),
  104. ('pointer_vector',),
  105. ('builtin_converters', [], 'test_builtin_converters.py'),
  106. ('map_indexing_suite',
  107. [['map_indexing_suite', 'int_map_indexing_suite', 'a_map_indexing_suite']])]:
  108. tests.append(extension_test(*t))
  109. tests.append(extension_test('shared_ptr',
  110. condition=set.define.contains('HAS_CXX11')))
  111. tests.append(extension_test('polymorphism2_auto_ptr',
  112. condition=set.define.contains('HAS_CXX11').not_()))
  113. tests.append(extension_test('auto_ptr',
  114. condition=set.define.contains('HAS_CXX11')))
  115. import_ = binary('import_', ['import_.cpp', src.bpl], features=features|python_libs)
  116. if platform.os == 'Windows':
  117. command = """set PATH=$(runpath);%PATH%
  118. $(>[1]) $(>[2])"""
  119. else:
  120. command = 'LD_LIBRARY_PATH=$(runpath) $(>[1]) $(>[2])'
  121. tests.append(test('import', [import_, 'import_.py'],
  122. run=action('run', command),
  123. features=features))
  124. tests.append(extension_test('calling_conventions',
  125. condition=platform.os == 'Windows'))
  126. tests.append(extension_test('calling_conventions_mf',
  127. condition=platform.os == 'Windows'))
  128. for t in ['destroy_test',
  129. 'pointer_type_id_test',
  130. 'bases',
  131. 'pointee',
  132. 'if_else',
  133. 'pointee',
  134. 'result',
  135. 'upcast',
  136. 'select_from_python_test']:
  137. tests.append(test(t, binary(t, [t + '.cpp', src.bpl], features=features), features=features, run=True))
  138. for t in ['indirect_traits_test',
  139. 'string_literal',
  140. 'borrowed',
  141. 'object_manager',
  142. 'copy_ctor_mutates_rhs',
  143. 'select_holder',
  144. 'select_arg_to_python_test']:
  145. tests.append(test(t, object(t, [t + '.cpp'], features=features)))
  146. for t in ['raw_pyobject_fail1',
  147. 'raw_pyobject_fail2',
  148. 'as_to_python_function',
  149. 'object_fail1']:
  150. tests.append(test(t, object(t, [t + '.cpp'], features=features), expected=fail))
  151. for t in ['numpy/dtype',
  152. 'numpy/ufunc',
  153. 'numpy/templates',
  154. 'numpy/ndarray',
  155. 'numpy/indexing',
  156. 'numpy/shapes']:
  157. tests.append(extension_test(t, np=True,
  158. condition=set.define.contains('HAS_NUMPY')))
  159. default = report('report', tests, fail_on_failures=True)