Author: Antonio Cuni <[email protected]>
Branch: hpy
Changeset: r98108:0fee85415527
Date: 2019-11-18 12:09 +0100
http://bitbucket.org/pypy/pypy/changeset/0fee85415527/
Log: remove the test duplication: we can now reuse directly the tests
which we vendored from hpy
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,19 +6,21 @@
from pypy.module.hpy_universal._vendored.test import support as _support
-class HPyTest(object):
+class HPyAppTest(object):
+
+ @pytest.fixture
+ def compiler(self):
+ # see setup_method below
+ return 'The fixture "compiler" is not used on pypy'
def setup_class(cls):
if cls.runappdirect:
pytest.skip()
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
+ # it would be nice to use the 'compiler' fixture to provide
+ # make_module as the std HPyTest do. Howwever, we don't have the space
+ # yet, so it is much easier to prove make_module() here
tmpdir = py.path.local.make_numbered_dir(rootdir=udir,
prefix=meth.__name__ + '-',
keep=0) # keep everything
diff --git a/pypy/module/hpy_universal/test/test_basic.py
b/pypy/module/hpy_universal/test/test_basic.py
--- a/pypy/module/hpy_universal/test/test_basic.py
+++ b/pypy/module/hpy_universal/test/test_basic.py
@@ -1,133 +1,6 @@
-from .support import HPyTest
+import pytest
+from pypy.module.hpy_universal._vendored.test.test_basic import TestBasic as
_TestBasic
+from .support import HPyAppTest
-class AppTestBasic(HPyTest):
+class AppTestBasic(HPyAppTest, _TestBasic):
spaceconfig = {'usemodules': ['hpy_universal']}
- def test_import(self):
- import hpy_universal
-
- def test_empty_module(self):
- import sys
- mod = self.make_module("""
- @INIT
- """)
- assert type(mod) is type(sys)
-
- def test_empty_module_initialization(self):
- skip("FIXME")
- import sys
- mod = self.make_module("""
- @INIT
- """)
- assert type(mod) is type(sys)
- assert mod.__loader__.name == 'mytest'
- assert mod.__spec__.loader is mod.__loader__
- assert mod.__file__
-
- def test_different_name(self):
- mod = self.make_module("""
- @INIT
- """, name="foo")
- assert mod.__name__ == "foo"
-
- def test_noop_function(self):
- mod = self.make_module("""
- HPy_FUNCTION(f)
- static HPy f_impl(HPyContext ctx, HPy self, HPy args)
- {
- return HPyNone_Get(ctx);
- }
- @EXPORT f METH_NOARGS
- @INIT
- """)
- assert mod.f() is None
-
- def test_self_is_module(self):
- mod = self.make_module("""
- HPy_FUNCTION(f)
- static HPy f_impl(HPyContext ctx, HPy self, HPy args)
- {
- return HPy_Dup(ctx, self);
- }
- @EXPORT f METH_NOARGS
- @INIT
- """)
- assert mod.f() is mod
-
- def test_identity_function(self):
- mod = self.make_module("""
- HPy_FUNCTION(f)
- static HPy f_impl(HPyContext ctx, HPy self, HPy arg)
- {
- return HPy_Dup(ctx, arg);
- }
- @EXPORT f METH_O
- @INIT
- """)
- x = object()
- assert mod.f(x) is x
-
- def test_long_aslong(self):
- mod = self.make_module("""
- HPy_FUNCTION(f)
- static HPy f_impl(HPyContext ctx, HPy self, HPy arg)
- {
- long a = HPyLong_AsLong(ctx, arg);
- return HPyLong_FromLong(ctx, a * 2);
- }
- @EXPORT f METH_O
- @INIT
- """)
- assert mod.f(45) == 90
-
- def test_wrong_number_of_arguments(self):
- # XXX: this test was manually modified to turn pytest.raises into
raises :(
- mod = self.make_module("""
- HPy_FUNCTION(f_noargs)
- static HPy f_noargs_impl(HPyContext ctx, HPy self, HPy args)
- {
- return HPyNone_Get(ctx);
- }
- HPy_FUNCTION(f_o)
- static HPy f_o_impl(HPyContext ctx, HPy self, HPy args)
- {
- return HPyNone_Get(ctx);
- }
- @EXPORT f_noargs METH_NOARGS
- @EXPORT f_o METH_O
- @INIT
- """)
- with raises(TypeError):
- mod.f_noargs(1)
- with raises(TypeError):
- mod.f_o()
- with raises(TypeError):
- mod.f_o(1, 2)
-
- def test_close(self):
- mod = self.make_module("""
- HPy_FUNCTION(f)
- static HPy f_impl(HPyContext ctx, HPy self, HPy arg)
- {
- HPy one = HPyLong_FromLong(ctx, 1);
- if (HPy_IsNull(one))
- return HPy_NULL;
- HPy res = HPyNumber_Add(ctx, arg, one);
- HPy_Close(ctx, one);
- return res;
- }
- @EXPORT f METH_O
- @INIT
- """)
- assert mod.f(41.5) == 42.5
-
- def test_string(self):
- mod = self.make_module("""
- HPy_FUNCTION(f)
- static HPy f_impl(HPyContext ctx, HPy self, HPy args)
- {
- return HPyUnicode_FromString(ctx, "foobar");
- }
- @EXPORT f METH_NOARGS
- @INIT
- """)
- assert mod.f() == "foobar"
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit