File: conftest.py

package info (click to toggle)
pypy3 7.0.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 111,848 kB
  • sloc: python: 1,291,746; ansic: 74,281; asm: 5,187; cpp: 3,017; sh: 2,533; makefile: 544; xml: 243; lisp: 45; csh: 21; awk: 4
file content (86 lines) | stat: -rw-r--r-- 3,557 bytes parent folder | download | duplicates (2)
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
import py, sys
from os.path import abspath, commonprefix, dirname

THIS_DIR = dirname(__file__)

@py.test.mark.tryfirst
def pytest_runtest_setup(item):
    if py.path.local.sysfind('genreflex') is None:
        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'):
                py.test.skip(infomsg)
            import re
            if tst == 'test_pythonify.py' and \
                not re.search("AppTestPYTHONIFY.test0[1-5]", item.location[2]):
                py.test.skip(infomsg)
            elif tst == 'test_cpp11features.py' and \
                not re.search("AppTestCPP11FEATURES.test02", item.location[2]):
                py.test.skip(infomsg)
            elif tst == 'test_datatypes.py' and \
                not re.search("AppTestDATATYPES.test0[1-7]", item.location[2]):
                py.test.skip(infomsg)
            elif tst == 'test_pythonization.py' and \
                not re.search("AppTestPYTHONIZATION.test0[0]", item.location[2]):
                py.test.skip(infomsg)

def pytest_ignore_collect(path, config):
    path = str(path)
    if py.path.local.sysfind('genreflex') is None and config.option.runappdirect:
        return commonprefix([path, THIS_DIR]) == THIS_DIR
    if disabled:
        return commonprefix([path, THIS_DIR]) == THIS_DIR

disabled = None

def pytest_configure(config):
    if py.path.local.sysfind('genreflex') is None:
        import pypy.module._cppyy.capi.loadable_capi as lcapi
        try:
            import ctypes
            ctypes.CDLL(lcapi.backend_library)
        except Exception as e:
            if config.option.runappdirect:
                return       # "can't run dummy tests in -A"

            # build dummy backend (which has reflex info and calls hard-wired)
            import os
            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')

            eci = ExternalCompilationInfo(
                separate_module_files=[srcpath.join('dummy_backend.cxx')],
                include_dirs=[incpath, tstpath, cdir],
                compile_extra=['-DRPY_EXTERN=RPY_EXPORTED', '-DCPPYY_DUMMY_BACKEND',
                               '-fno-strict-aliasing', '-std=c++14'],
                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):
                    global disabled
                    disabled = str(e)
                    return
                raise

            lcapi.backend_library = str(soname)