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 (152 lines) | stat: -rw-r--r-- 5,518 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import sys
import os
import types
import pytest
from pypy.conftest import APPLEVEL_FN

THIS_DIR = os.path.dirname(__file__)

# ================================
# Customization of applevel tests
# ================================
#
# The various AppTestFoo classes are automatically collected and generated by
# make_hpy_apptest below. Additionally, it is possible to customize the body
# of the generated AppTest* classes by creating extra_AppTest* classes below

# to skip a specific test, you can do the following:
## class extra_AppTestBasic:
##     def test_exception_occurred(self):
##         import pytest
##         pytest.skip('fixme')

disable = False

if sys.platform.startswith('linux') and sys.maxsize <= 2**31:
    # skip all tests on linux32
    disable = True
if sys.platform == "win32":
    # skip all tests on windows, they take around 2 hours
    disable = True


# Monkeypatch distutils.sysconfig.get_config_var for the parse_ext_suffix
# check in devel/abitag.py. Needed for "cross-compilation" when
# untranslated so the distutils machinery can get at the "pypy39-pp73"
# ABI tag. Note EXT_SUFFIX does not exist in python2
from distutils import sysconfig
d = sysconfig.get_config_vars()
d['EXT_SUFFIX'] = ".pypy39-pp73-x86_64-linux-gnu.so"

 
# ========================================================================
# pytest hooks to automatically generate AppTests from HPy vendored tests
# ========================================================================

def pytest_pycollect_makemodule(path, parent):
    if path.fnmatch(APPLEVEL_FN):
        if parent.config.getoption('direct_apptest'):
            return

        from pypy.tool.pytest.apptest2 import AppTestModule
        from ..state import State

        class AppTestModuleHPy(AppTestModule):
            def setup(self):
                space = None
                for item in self.session.items:
                    try:
                        space = item.w_obj.space
                        break
                    except AttributeError:
                        continue
                else:
                    # cannot happen: there must be at least one apptest test
                    raise ValueError("no apptest but AppTestModuleHPy called??")
                state = space.fromcache(State)
                state.reset()

        rewrite = parent.config.getoption('applevel_rewrite')
        return AppTestModuleHPy(path, parent, rewrite_asserts=rewrite)
    # Let the default collect handle it
    return
    

def pytest_pycollect_makeitem(collector, name, obj):
    from pypy.tool.pytest.apptest import AppClassCollector
    from pypy.module._hpy_universal.test._vendored.support import HPyTest
    if (collector.istestclass(obj, name) and
            issubclass(obj, HPyTest) and
            not name.startswith('App')):
        appname = make_hpy_apptest(collector, name, obj)
        return AppClassCollector(appname, parent=collector)

def pytest_ignore_collect(path, config):
    if (config.getoption('runappdirect') or config.getoption('direct_apptest')
            or disable):
        # workaround for pytest issue #2016 (fixed in 3.0.5)
        if os.path.commonprefix([str(path), THIS_DIR]) == THIS_DIR:
            return True
    if path == config.rootdir.join('pypy', 'module', '_hpy_universal', 'test',
                                   '_vendored', 'test_support.py'):
        return True
    if "/trace/" in str(path) or r'\trace\t' in str(path):
        return True


def pytest_collect_file(path, parent):
    if (parent.config.getoption('runappdirect') or parent.config.getoption('direct_apptest')
            or disable):
        pytest.skip("_hpy_universal tests skipped, module not active")


def make_hpy_apptest(collector, name, cls):
    """
    Automatically create HPy AppTests from the _vendored tests.
    This is more or less equivalent of doing the following:

        from pypy.module._hpy_universal.test._vendored.test_basic import TestBasic
        class AppTestBasic(HPyAppTest, TestBasic):
            pass

    """
    from pypy.module._hpy_universal.test._vendored.support import HPyDebugTest
    from pypy.module._hpy_universal.test.support import (HPyAppTest, HPyCPyextAppTest,
                                                         HPyDebugAppTest)
    appname = 'App' + name

    # the original HPy test classes might contain helper methods such as
    # TestParseItem.make_parse_item: to make them available inside AppTests,
    # we need to prefix them with w_. Here it's a generic way to make
    # available at applevel all the non-test methods which are found
    d = {}
    for name, value in cls.__dict__.iteritems():
        if (not name.startswith('test_') and
            not name.startswith('__') and
            isinstance(value, types.FunctionType)):
            d['w_%s' % name] = value
    #
    # cpyext tests need a different base class
    use_cpyext = getattr(cls, 'USE_CPYEXT', False)
    use_hpydebug = issubclass(cls, HPyDebugTest)
    if use_cpyext:
        bases = (HPyCPyextAppTest, cls)
    elif use_hpydebug:
        bases = (HPyDebugAppTest, cls)
    else:
        bases = (HPyAppTest, cls)
    #
    # finally, we can create the new AppTest class
    appcls = type(appname, bases, d)
    setattr(collector.obj, appname, appcls)
    return appname

@pytest.fixture(scope='class')
def python_subprocess(request):
    pytest.skip("no subprocess available")

@pytest.fixture(scope='class')
def fatal_exit_code(request):
    return -1