File: conftest.py

package info (click to toggle)
pypy3 7.3.19%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 212,236 kB
  • sloc: python: 2,098,316; ansic: 540,565; sh: 21,462; asm: 14,419; cpp: 4,451; makefile: 4,209; objc: 761; xml: 530; exp: 499; javascript: 314; pascal: 244; lisp: 45; csh: 12; awk: 4
file content (103 lines) | stat: -rw-r--r-- 3,975 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import pytest, sys
from os.path import abspath, commonprefix, dirname

THIS_DIR = dirname(__file__)

@pytest.mark.tryfirst
def pytest_runtest_setup(item):
    if not disabled:
        try:
            import genreflex
            return
        except ImportError:
            pass
        import pypy.module._cppyy.capi.loadable_capi as lcapi
        if 'dummy' in lcapi.backend_library:
            # run only tests that are covered by the dummy backend and tests
            # that do not rely on reflex
            import os
            infomsg = 'backend is not installed'
            tst = os.path.basename(item.location[0])
            if not tst in ('test_helper.py', 'test_cppyy.py', 'test_pythonify.py',
                           'test_cpp11features.py', 'test_datatypes.py',
                           'test_pythonization.py'):
                pytest.skip(infomsg)
            import re
            if tst == 'test_pythonify.py' and \
                not re.search("AppTestPYTHONIFY.test0[1-5]", item.location[2]):
                pytest.skip(infomsg)
            elif tst == 'test_cpp11features.py' and \
                not re.search("AppTestCPP11FEATURES.test02", item.location[2]):
                pytest.skip(infomsg)
            elif tst == 'test_datatypes.py' and \
                not re.search("AppTestDATATYPES.test0[1-7]", item.location[2]):
                pytest.skip(infomsg)
            elif tst == 'test_pythonization.py' and \
                not re.search("AppTestPYTHONIZATION.test0[0]", item.location[2]):
                pytest.skip(infomsg)

def pytest_ignore_collect(path, config):
    path = str(path)
    if disabled:
        if commonprefix([path, THIS_DIR]) == THIS_DIR:  # workaround for bug in pytest<3.0.5
            return True

disabled = None
if sys.maxsize > 2**32 and sys.platform == 'win32':
    # cppyy not yet supported on windows 64 bit
    disabled = True

def pytest_configure(config):
    global disabled
    try:
        import genreflex
    except ImportError:
        genreflex = None
    if disabled or config.getoption('runappdirect') or config.getoption('direct_apptest'):
        if genreflex is None:
            disabled = True  # can't run dummy tests in -A
        return
    if genreflex is None:
        import pypy.module._cppyy.capi.loadable_capi as lcapi
        try:
            import ctypes
            ctypes.CDLL(lcapi.backend_library)
        except Exception as e:
            # build dummy backend (which has reflex info and calls hard-wired)
            import os
            import py
            from rpython.translator.tool.cbuild import ExternalCompilationInfo
            from rpython.translator.platform import platform, CompilationError
            from rpython.translator import cdir

            from rpython.rtyper.lltypesystem import rffi

            pkgpath = py.path.local(__file__).dirpath().join(os.pardir)
            srcpath = pkgpath.join('src')
            incpath = pkgpath.join('include')
            tstpath = pkgpath.join('test')
            compile_extra = ['-DRPY_EXTERN=RPY_EXPORTED', '-DCPPYY_DUMMY_BACKEND']
            if platform.name == 'msvc':
                compile_extra += ['-std:c++14']
            else:
                compile_extra += ['-fno-strict-aliasing', '-std=c++14']

            eci = ExternalCompilationInfo(
                separate_module_files=[srcpath.join('dummy_backend.cxx')],
                include_dirs=[incpath, tstpath, cdir],
                compile_extra=compile_extra,
                use_cpp_linker=True,
            )

            try:
                soname = platform.compile(
                    [], eci,
                    outputfilename='libcppyy_dummy_backend',
                    standalone=False)
            except CompilationError as e:
                if '-std=c++14' in str(e):
                    disabled = str(e)
                    return
                raise

            lcapi.backend_library = str(soname)