gh-116303: Skip test module dependent tests if test modules are unavailable (#117341)

This commit is contained in:
Erlend E. Aasland 2024-04-03 15:11:36 +02:00 committed by GitHub
parent 2ec6bb4111
commit ea94b3b149
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
57 changed files with 255 additions and 123 deletions

View file

@ -1,6 +1,6 @@
import unittest
from test.support import (cpython_only, is_wasi, requires_limited_api, Py_DEBUG,
set_recursion_limit, skip_on_s390x)
set_recursion_limit, skip_on_s390x, import_helper)
try:
import _testcapi
except ImportError:
@ -244,6 +244,7 @@ class CFunctionCallsErrorMessages(unittest.TestCase):
self.assertRaisesRegex(TypeError, msg, mod)
@unittest.skipIf(_testcapi is None, "requires _testcapi")
class TestCallingConventions(unittest.TestCase):
"""Test calling using various C calling conventions (METH_*) from Python
@ -441,6 +442,7 @@ PYTHON_INSTANCE = PythonClass()
NULL_OR_EMPTY = object()
class FastCallTests(unittest.TestCase):
"""Test calling using various callables from C
"""
@ -484,42 +486,43 @@ class FastCallTests(unittest.TestCase):
]
# Add all the calling conventions and variants of C callables
_instance = _testcapi.MethInstance()
for obj, expected_self in (
(_testcapi, _testcapi), # module-level function
(_instance, _instance), # bound method
(_testcapi.MethClass, _testcapi.MethClass), # class method on class
(_testcapi.MethClass(), _testcapi.MethClass), # class method on inst.
(_testcapi.MethStatic, None), # static method
):
CALLS_POSARGS.extend([
(obj.meth_varargs, (1, 2), (expected_self, (1, 2))),
(obj.meth_varargs_keywords,
(1, 2), (expected_self, (1, 2), NULL_OR_EMPTY)),
(obj.meth_fastcall, (1, 2), (expected_self, (1, 2))),
(obj.meth_fastcall, (), (expected_self, ())),
(obj.meth_fastcall_keywords,
(1, 2), (expected_self, (1, 2), NULL_OR_EMPTY)),
(obj.meth_fastcall_keywords,
(), (expected_self, (), NULL_OR_EMPTY)),
(obj.meth_noargs, (), expected_self),
(obj.meth_o, (123, ), (expected_self, 123)),
])
if _testcapi:
_instance = _testcapi.MethInstance()
for obj, expected_self in (
(_testcapi, _testcapi), # module-level function
(_instance, _instance), # bound method
(_testcapi.MethClass, _testcapi.MethClass), # class method on class
(_testcapi.MethClass(), _testcapi.MethClass), # class method on inst.
(_testcapi.MethStatic, None), # static method
):
CALLS_POSARGS.extend([
(obj.meth_varargs, (1, 2), (expected_self, (1, 2))),
(obj.meth_varargs_keywords,
(1, 2), (expected_self, (1, 2), NULL_OR_EMPTY)),
(obj.meth_fastcall, (1, 2), (expected_self, (1, 2))),
(obj.meth_fastcall, (), (expected_self, ())),
(obj.meth_fastcall_keywords,
(1, 2), (expected_self, (1, 2), NULL_OR_EMPTY)),
(obj.meth_fastcall_keywords,
(), (expected_self, (), NULL_OR_EMPTY)),
(obj.meth_noargs, (), expected_self),
(obj.meth_o, (123, ), (expected_self, 123)),
])
CALLS_KWARGS.extend([
(obj.meth_varargs_keywords,
(1, 2), {'x': 'y'}, (expected_self, (1, 2), {'x': 'y'})),
(obj.meth_varargs_keywords,
(), {'x': 'y'}, (expected_self, (), {'x': 'y'})),
(obj.meth_varargs_keywords,
(1, 2), {}, (expected_self, (1, 2), NULL_OR_EMPTY)),
(obj.meth_fastcall_keywords,
(1, 2), {'x': 'y'}, (expected_self, (1, 2), {'x': 'y'})),
(obj.meth_fastcall_keywords,
(), {'x': 'y'}, (expected_self, (), {'x': 'y'})),
(obj.meth_fastcall_keywords,
(1, 2), {}, (expected_self, (1, 2), NULL_OR_EMPTY)),
])
CALLS_KWARGS.extend([
(obj.meth_varargs_keywords,
(1, 2), {'x': 'y'}, (expected_self, (1, 2), {'x': 'y'})),
(obj.meth_varargs_keywords,
(), {'x': 'y'}, (expected_self, (), {'x': 'y'})),
(obj.meth_varargs_keywords,
(1, 2), {}, (expected_self, (1, 2), NULL_OR_EMPTY)),
(obj.meth_fastcall_keywords,
(1, 2), {'x': 'y'}, (expected_self, (1, 2), {'x': 'y'})),
(obj.meth_fastcall_keywords,
(), {'x': 'y'}, (expected_self, (), {'x': 'y'})),
(obj.meth_fastcall_keywords,
(1, 2), {}, (expected_self, (1, 2), NULL_OR_EMPTY)),
])
def check_result(self, result, expected):
if isinstance(expected, tuple) and expected[-1] is NULL_OR_EMPTY:
@ -527,6 +530,7 @@ class FastCallTests(unittest.TestCase):
expected = (*expected[:-1], result[-1])
self.assertEqual(result, expected)
@unittest.skipIf(_testcapi is None, "requires _testcapi")
def test_vectorcall_dict(self):
# Test PyObject_VectorcallDict()
@ -546,6 +550,7 @@ class FastCallTests(unittest.TestCase):
result = _testcapi.pyobject_fastcalldict(func, args, kwargs)
self.check_result(result, expected)
@unittest.skipIf(_testcapi is None, "requires _testcapi")
def test_vectorcall(self):
# Test PyObject_Vectorcall()
@ -610,6 +615,7 @@ def testfunction_kw(self, *, kw):
ADAPTIVE_WARMUP_DELAY = 2
@unittest.skipIf(_testcapi is None, "requires _testcapi")
class TestPEP590(unittest.TestCase):
def test_method_descriptor_flag(self):
@ -1022,6 +1028,7 @@ class TestRecursion(unittest.TestCase):
@skip_on_s390x
@unittest.skipIf(is_wasi and Py_DEBUG, "requires deep stack")
@unittest.skipIf(_testcapi is None, "requires _testcapi")
def test_super_deep(self):
def recurse(n):