| 1 |
import sys |
| 2 |
import os |
| 3 |
import types |
| 4 |
import pytest |
| 5 |
from pypy.conftest import APPLEVEL_FN |
| 6 |
|
| 7 |
THIS_DIR = os.path.dirname(__file__) |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
disable = False |
| 24 |
|
| 25 |
if sys.platform.startswith('linux') and sys.maxsize <= 2**31: |
| 26 |
|
| 27 |
disable = True |
| 28 |
if sys.platform == "win32": |
| 29 |
|
| 30 |
disable = True |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
from distutils import sysconfig |
| 38 |
d = sysconfig.get_config_vars() |
| 39 |
d['EXT_SUFFIX'] = ".pypy39-pp73-x86_64-linux-gnu.so" |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
def pytest_pycollect_makemodule(path, parent): |
| 47 |
if path.fnmatch(APPLEVEL_FN): |
| 48 |
if parent.config.getoption('direct_apptest'): |
| 49 |
return |
| 50 |
|
| 51 |
from pypy.tool.pytest.apptest2 import AppTestModule |
| 52 |
from ..state import State |
| 53 |
|
| 54 |
class AppTestModuleHPy(AppTestModule): |
| 55 |
def setup(self): |
| 56 |
space = None |
| 57 |
for item in self.session.items: |
| 58 |
try: |
| 59 |
space = item.w_obj.space |
| 60 |
break |
| 61 |
except AttributeError: |
| 62 |
continue |
| 63 |
else: |
| 64 |
|
| 65 |
raise ValueError("no apptest but AppTestModuleHPy called??") |
| 66 |
state = space.fromcache(State) |
| 67 |
state.reset() |
| 68 |
|
| 69 |
rewrite = parent.config.getoption('applevel_rewrite') |
| 70 |
return AppTestModuleHPy(path, parent, rewrite_asserts=rewrite) |
| 71 |
|
| 72 |
return |
| 73 |
|
| 74 |
|
| 75 |
def pytest_pycollect_makeitem(collector, name, obj): |
| 76 |
from pypy.tool.pytest.apptest import AppClassCollector |
| 77 |
from pypy.module._hpy_universal.test._vendored.support import HPyTest |
| 78 |
if (collector.istestclass(obj, name) and |
| 79 |
issubclass(obj, HPyTest) and |
| 80 |
not name.startswith('App')): |
| 81 |
appname = make_hpy_apptest(collector, name, obj) |
| 82 |
return AppClassCollector(appname, parent=collector) |
| 83 |
|
| 84 |
def pytest_ignore_collect(path, config): |
| 85 |
if (config.getoption('runappdirect') or config.getoption('direct_apptest') |
| 86 |
or disable): |
| 87 |
|
| 88 |
if os.path.commonprefix([str(path), THIS_DIR]) == THIS_DIR: |
| 89 |
return True |
| 90 |
if path == config.rootdir.join('pypy', 'module', '_hpy_universal', 'test', |
| 91 |
'_vendored', 'test_support.py'): |
| 92 |
return True |
| 93 |
if "/trace/" in str(path) or r'\trace\t' in str(path): |
| 94 |
return True |
| 95 |
|
| 96 |
|
| 97 |
def pytest_collect_file(path, parent): |
| 98 |
if (parent.config.getoption('runappdirect') or parent.config.getoption('direct_apptest') |
| 99 |
or disable): |
| 100 |
pytest.skip("_hpy_universal tests skipped, module not active") |
| 101 |
|
| 102 |
|
| 103 |
def make_hpy_apptest(collector, name, cls): |
| 104 |
""" |
| 105 |
Automatically create HPy AppTests from the _vendored tests. |
| 106 |
This is more or less equivalent of doing the following: |
| 107 |
|
| 108 |
from pypy.module._hpy_universal.test._vendored.test_basic import TestBasic |
| 109 |
class AppTestBasic(HPyAppTest, TestBasic): |
| 110 |
pass |
| 111 |
|
| 112 |
""" |
| 113 |
from pypy.module._hpy_universal.test._vendored.support import HPyDebugTest |
| 114 |
from pypy.module._hpy_universal.test.support import (HPyAppTest, HPyCPyextAppTest, |
| 115 |
HPyDebugAppTest) |
| 116 |
appname = 'App' + name |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
d = {} |
| 123 |
for name, value in cls.__dict__.iteritems(): |
| 124 |
if (not name.startswith('test_') and |
| 125 |
not name.startswith('__') and |
| 126 |
isinstance(value, types.FunctionType)): |
| 127 |
d['w_%s' % name] = value |
| 128 |
|
| 129 |
|
| 130 |
use_cpyext = getattr(cls, 'USE_CPYEXT', False) |
| 131 |
use_hpydebug = issubclass(cls, HPyDebugTest) |
| 132 |
if use_cpyext: |
| 133 |
bases = (HPyCPyextAppTest, cls) |
| 134 |
elif use_hpydebug: |
| 135 |
bases = (HPyDebugAppTest, cls) |
| 136 |
else: |
| 137 |
bases = (HPyAppTest, cls) |
| 138 |
|
| 139 |
|
| 140 |
appcls = type(appname, bases, d) |
| 141 |
setattr(collector.obj, appname, appcls) |
| 142 |
return appname |
| 143 |
|
| 144 |
def pytest_sessionstart(session): |
| 145 |
from pypy.module._hpy_universal.test import support as _support |
| 146 |
from pypy.module._hpy_universal._vendored.hpy.devel import HPyDevel |
| 147 |
from pypy.module._hpy_universal.llapi import BASE_DIR |
| 148 |
if 'libs' not in _support._static_lib_cache: |
| 149 |
hpy_devel = HPyDevel(str(BASE_DIR)) |
| 150 |
result = _support._try_build_static_lib(hpy_devel, 'universal') |
| 151 |
_support._static_lib_cache['libs'] = result |
| 152 |
if not result: |
| 153 |
import warnings |
| 154 |
warnings.warn( |
| 155 |
"HPy static-lib build failed; " |
| 156 |
"falling back to per-test source compilation.", |
| 157 |
stacklevel=1, |
| 158 |
) |
| 159 |
|
| 160 |
|
| 161 |
@pytest.fixture(scope='class') |
| 162 |
def python_subprocess(request): |
| 163 |
pytest.skip("no subprocess available") |
| 164 |
|
| 165 |
@pytest.fixture(scope='class') |
| 166 |
def fatal_exit_code(request): |
| 167 |
return -1 |
| 168 |
|
| 169 |
|