Debian Codegraph @

pypy/module/_cppyy/test/conftest.py

raw symbols SCIP
1 import pytest, sys
2 from os.path import abspath, commonprefix, dirname
3
4 THIS_DIR = dirname(__file__)
5
6 @pytest.mark.tryfirst
7 def pytest_runtest_setup(item):
8 if not disabled:
9 try:
10 import genreflex
11 return
12 except ImportError:
13 pass
14 import pypy.module._cppyy.capi.loadable_capi as lcapi
15 if 'dummy' in lcapi.backend_library:
16 # run only tests that are covered by the dummy backend and tests
17 # that do not rely on reflex
18 import os
19 infomsg = 'backend is not installed'
20 tst = os.path.basename(item.location[0])
21 if not tst in ('test_helper.py', 'test_cppyy.py', 'test_pythonify.py',
22 'test_cpp11features.py', 'test_datatypes.py',
23 'test_pythonization.py'):
24 pytest.skip(infomsg)
25 import re
26 if tst == 'test_pythonify.py' and \
27 not re.search("AppTestPYTHONIFY.test0[1-5]", item.location[2]):
28 pytest.skip(infomsg)
29 elif tst == 'test_cpp11features.py' and \
30 not re.search("AppTestCPP11FEATURES.test02", item.location[2]):
31 pytest.skip(infomsg)
32 elif tst == 'test_datatypes.py' and \
33 not re.search("AppTestDATATYPES.test0[1-7]", item.location[2]):
34 pytest.skip(infomsg)
35 elif tst == 'test_pythonization.py' and \
36 not re.search("AppTestPYTHONIZATION.test0[0]", item.location[2]):
37 pytest.skip(infomsg)
38
39 def pytest_ignore_collect(path, config):
40 path = str(path)
41 if disabled:
42 if commonprefix([path, THIS_DIR]) == THIS_DIR: # workaround for bug in pytest<3.0.5
43 return True
44
45 disabled = None
46 if sys.maxsize > 2**32 and sys.platform == 'win32':
47 # cppyy not yet supported on windows 64 bit
48 disabled = True
49
50 def pytest_configure(config):
51 global disabled
52 try:
53 import genreflex
54 except ImportError:
55 genreflex = None
56 if disabled or config.getoption('runappdirect') or config.getoption('direct_apptest'):
57 if genreflex is None:
58 disabled = True # can't run dummy tests in -A
59 return
60 if genreflex is None:
61 import pypy.module._cppyy.capi.loadable_capi as lcapi
62 try:
63 import ctypes
64 ctypes.CDLL(lcapi.backend_library)
65 except Exception as e:
66 # build dummy backend (which has reflex info and calls hard-wired)
67 import os
68 import py
69 from rpython.translator.tool.cbuild import ExternalCompilationInfo
70 from rpython.translator.platform import platform, CompilationError
71 from rpython.translator import cdir
72
73 from rpython.rtyper.lltypesystem import rffi
74
75 pkgpath = py.path.local(__file__).dirpath().join(os.pardir)
76 srcpath = pkgpath.join('src')
77 incpath = pkgpath.join('include')
78 tstpath = pkgpath.join('test')
79 compile_extra = ['-DRPY_EXTERN=RPY_EXPORTED', '-DCPPYY_DUMMY_BACKEND']
80 if platform.name == 'msvc':
81 compile_extra += ['-std:c++14']
82 else:
83 compile_extra += ['-fno-strict-aliasing', '-std=c++14']
84
85 eci = ExternalCompilationInfo(
86 separate_module_files=[srcpath.join('dummy_backend.cxx')],
87 include_dirs=[incpath, tstpath, cdir],
88 compile_extra=compile_extra,
89 use_cpp_linker=True,
90 )
91
92 try:
93 soname = platform.compile(
94 [], eci,
95 outputfilename='libcppyy_dummy_backend',
96 standalone=False)
97 except CompilationError as e:
98 if '-std=c++14' in str(e):
99 disabled = str(e)
100 return
101 raise
102
103 lcapi.backend_library = str(soname)