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