1
1
import unittest
2
2
from test .support import (cpython_only , is_wasi , requires_limited_api , Py_DEBUG ,
3
- set_recursion_limit , skip_on_s390x )
3
+ set_recursion_limit , skip_on_s390x , import_helper )
4
4
try :
5
5
import _testcapi
6
6
except ImportError :
@@ -244,6 +244,7 @@ def test_module_not_callable_suggestion(self):
244
244
self .assertRaisesRegex (TypeError , msg , mod )
245
245
246
246
247
+ @unittest .skipIf (_testcapi is None , "requires _testcapi" )
247
248
class TestCallingConventions (unittest .TestCase ):
248
249
"""Test calling using various C calling conventions (METH_*) from Python
249
250
@@ -441,6 +442,7 @@ def static_method():
441
442
442
443
NULL_OR_EMPTY = object ()
443
444
445
+
444
446
class FastCallTests (unittest .TestCase ):
445
447
"""Test calling using various callables from C
446
448
"""
@@ -484,49 +486,51 @@ class FastCallTests(unittest.TestCase):
484
486
]
485
487
486
488
# Add all the calling conventions and variants of C callables
487
- _instance = _testcapi .MethInstance ()
488
- for obj , expected_self in (
489
- (_testcapi , _testcapi ), # module-level function
490
- (_instance , _instance ), # bound method
491
- (_testcapi .MethClass , _testcapi .MethClass ), # class method on class
492
- (_testcapi .MethClass (), _testcapi .MethClass ), # class method on inst.
493
- (_testcapi .MethStatic , None ), # static method
494
- ):
495
- CALLS_POSARGS .extend ([
496
- (obj .meth_varargs , (1 , 2 ), (expected_self , (1 , 2 ))),
497
- (obj .meth_varargs_keywords ,
498
- (1 , 2 ), (expected_self , (1 , 2 ), NULL_OR_EMPTY )),
499
- (obj .meth_fastcall , (1 , 2 ), (expected_self , (1 , 2 ))),
500
- (obj .meth_fastcall , (), (expected_self , ())),
501
- (obj .meth_fastcall_keywords ,
502
- (1 , 2 ), (expected_self , (1 , 2 ), NULL_OR_EMPTY )),
503
- (obj .meth_fastcall_keywords ,
504
- (), (expected_self , (), NULL_OR_EMPTY )),
505
- (obj .meth_noargs , (), expected_self ),
506
- (obj .meth_o , (123 , ), (expected_self , 123 )),
507
- ])
508
-
509
- CALLS_KWARGS .extend ([
510
- (obj .meth_varargs_keywords ,
511
- (1 , 2 ), {'x' : 'y' }, (expected_self , (1 , 2 ), {'x' : 'y' })),
512
- (obj .meth_varargs_keywords ,
513
- (), {'x' : 'y' }, (expected_self , (), {'x' : 'y' })),
514
- (obj .meth_varargs_keywords ,
515
- (1 , 2 ), {}, (expected_self , (1 , 2 ), NULL_OR_EMPTY )),
516
- (obj .meth_fastcall_keywords ,
517
- (1 , 2 ), {'x' : 'y' }, (expected_self , (1 , 2 ), {'x' : 'y' })),
518
- (obj .meth_fastcall_keywords ,
519
- (), {'x' : 'y' }, (expected_self , (), {'x' : 'y' })),
520
- (obj .meth_fastcall_keywords ,
521
- (1 , 2 ), {}, (expected_self , (1 , 2 ), NULL_OR_EMPTY )),
522
- ])
489
+ if _testcapi :
490
+ _instance = _testcapi .MethInstance ()
491
+ for obj , expected_self in (
492
+ (_testcapi , _testcapi ), # module-level function
493
+ (_instance , _instance ), # bound method
494
+ (_testcapi .MethClass , _testcapi .MethClass ), # class method on class
495
+ (_testcapi .MethClass (), _testcapi .MethClass ), # class method on inst.
496
+ (_testcapi .MethStatic , None ), # static method
497
+ ):
498
+ CALLS_POSARGS .extend ([
499
+ (obj .meth_varargs , (1 , 2 ), (expected_self , (1 , 2 ))),
500
+ (obj .meth_varargs_keywords ,
501
+ (1 , 2 ), (expected_self , (1 , 2 ), NULL_OR_EMPTY )),
502
+ (obj .meth_fastcall , (1 , 2 ), (expected_self , (1 , 2 ))),
503
+ (obj .meth_fastcall , (), (expected_self , ())),
504
+ (obj .meth_fastcall_keywords ,
505
+ (1 , 2 ), (expected_self , (1 , 2 ), NULL_OR_EMPTY )),
506
+ (obj .meth_fastcall_keywords ,
507
+ (), (expected_self , (), NULL_OR_EMPTY )),
508
+ (obj .meth_noargs , (), expected_self ),
509
+ (obj .meth_o , (123 , ), (expected_self , 123 )),
510
+ ])
511
+
512
+ CALLS_KWARGS .extend ([
513
+ (obj .meth_varargs_keywords ,
514
+ (1 , 2 ), {'x' : 'y' }, (expected_self , (1 , 2 ), {'x' : 'y' })),
515
+ (obj .meth_varargs_keywords ,
516
+ (), {'x' : 'y' }, (expected_self , (), {'x' : 'y' })),
517
+ (obj .meth_varargs_keywords ,
518
+ (1 , 2 ), {}, (expected_self , (1 , 2 ), NULL_OR_EMPTY )),
519
+ (obj .meth_fastcall_keywords ,
520
+ (1 , 2 ), {'x' : 'y' }, (expected_self , (1 , 2 ), {'x' : 'y' })),
521
+ (obj .meth_fastcall_keywords ,
522
+ (), {'x' : 'y' }, (expected_self , (), {'x' : 'y' })),
523
+ (obj .meth_fastcall_keywords ,
524
+ (1 , 2 ), {}, (expected_self , (1 , 2 ), NULL_OR_EMPTY )),
525
+ ])
523
526
524
527
def check_result (self , result , expected ):
525
528
if isinstance (expected , tuple ) and expected [- 1 ] is NULL_OR_EMPTY :
526
529
if result [- 1 ] in ({}, None ):
527
530
expected = (* expected [:- 1 ], result [- 1 ])
528
531
self .assertEqual (result , expected )
529
532
533
+ @unittest .skipIf (_testcapi is None , "requires _testcapi" )
530
534
def test_vectorcall_dict (self ):
531
535
# Test PyObject_VectorcallDict()
532
536
@@ -546,6 +550,7 @@ def test_vectorcall_dict(self):
546
550
result = _testcapi .pyobject_fastcalldict (func , args , kwargs )
547
551
self .check_result (result , expected )
548
552
553
+ @unittest .skipIf (_testcapi is None , "requires _testcapi" )
549
554
def test_vectorcall (self ):
550
555
# Test PyObject_Vectorcall()
551
556
@@ -610,6 +615,7 @@ def testfunction_kw(self, *, kw):
610
615
ADAPTIVE_WARMUP_DELAY = 2
611
616
612
617
618
+ @unittest .skipIf (_testcapi is None , "requires _testcapi" )
613
619
class TestPEP590 (unittest .TestCase ):
614
620
615
621
def test_method_descriptor_flag (self ):
@@ -1022,6 +1028,7 @@ class TestRecursion(unittest.TestCase):
1022
1028
1023
1029
@skip_on_s390x
1024
1030
@unittest .skipIf (is_wasi and Py_DEBUG , "requires deep stack" )
1031
+ @unittest .skipIf (_testcapi is None , "requires _testcapi" )
1025
1032
def test_super_deep (self ):
1026
1033
1027
1034
def recurse (n ):
0 commit comments