Author: Antonio Cuni <[email protected]>
Branch: hpy
Changeset: r98107:be9be5d98bb9
Date: 2019-11-18 11:37 +0100
http://bitbucket.org/pypy/pypy/changeset/be9be5d98bb9/
Log: reduce code duplication and reuse most of the logic which is already
in support.py
diff --git a/pypy/module/hpy_universal/test/support.py
b/pypy/module/hpy_universal/test/support.py
--- a/pypy/module/hpy_universal/test/support.py
+++ b/pypy/module/hpy_universal/test/support.py
@@ -6,38 +6,27 @@
from pypy.module.hpy_universal._vendored.test import support as _support
+class HPyTest(object):
-class ExtensionCompiler(object):
- def __init__(self, base_dir):
- self.base_dir = base_dir
-
- def get_builddir(self, name='mytest'):
- builddir = py.path.local.make_numbered_dir(
- rootdir=py.path.local(self.base_dir),
- prefix=name + '-',
- keep=0) # keep everything
- return builddir
-
-
-class HPyTest(object):
def setup_class(cls):
if cls.runappdirect:
pytest.skip()
- cls.compiler = ExtensionCompiler(udir)
+
+ def setup_method(self, meth):
+ # we don't have fixtures in AppTests, so setup_method is a poor's man
+ # way of providing the 'make_module' fixture that HPyTest expects. In
+ # theory it would be nice to call interp2app only once for the entire
+ # class instead of once per method, but I quickly benchmarked it and
+ # it does not seem to have a noticeable impact on the total time
+ # needed to run the tests
+ tmpdir = py.path.local.make_numbered_dir(rootdir=udir,
+ prefix=meth.__name__ + '-',
+ keep=0) # keep everything
+ compiler = _support.ExtensionCompiler(tmpdir, 'universal', INCLUDE_DIR)
@unwrap_spec(source_template='text', name='text')
def descr_make_module(space, source_template, name='mytest'):
- source = _support.expand_template(source_template, name)
- tmpdir = cls.compiler.get_builddir()
- filename = tmpdir.join(name+ '.c')
- filename.write(source)
- #
- ext = _support.get_extension(str(filename), name,
include_dirs=[INCLUDE_DIR],
- extra_compile_args=['-Wfatal-errors', '-g',
'-Og'],
- extra_link_args=['-g'])
- so_filename = _support.c_compile(str(tmpdir), ext,
compiler_verbose=False,
- universal_mode=True)
- #
+ so_filename = compiler.compile_module(source_template, name)
w_mod = space.appexec([space.newtext(so_filename),
space.newtext(name)],
"""(path, modname):
import hpy_universal
@@ -45,5 +34,4 @@
"""
)
return w_mod
- cls.w_make_module = cls.space.wrap(interp2app(descr_make_module))
-
+ self.w_make_module = self.space.wrap(interp2app(descr_make_module))
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit