@@ -425,6 +425,34 @@ def test_long_asvoidptr(self):
425
425
self .assertRaises (OverflowError , asvoidptr , - 2 ** 1000 )
426
426
# CRASHES asvoidptr(NULL)
427
427
428
+ def _test_long_aspid (self , aspid ):
429
+ # Test PyLong_AsPid()
430
+ from _testcapi import SIZEOF_PID_T
431
+ bits = 8 * SIZEOF_PID_T
432
+ PID_T_MIN = - 2 ** (bits - 1 )
433
+ PID_T_MAX = 2 ** (bits - 1 ) - 1
434
+ # round trip (object -> long -> object)
435
+ for value in (PID_T_MIN , PID_T_MAX , - 1 , 0 , 1 , 1234 ):
436
+ with self .subTest (value = value ):
437
+ self .assertEqual (aspid (value ), value )
438
+
439
+ self .assertEqual (aspid (IntSubclass (42 )), 42 )
440
+ self .assertEqual (aspid (Index (42 )), 42 )
441
+ self .assertEqual (aspid (MyIndexAndInt ()), 10 )
442
+
443
+ self .assertRaises (OverflowError , aspid , PID_T_MIN - 1 )
444
+ self .assertRaises (OverflowError , aspid , PID_T_MAX + 1 )
445
+ self .assertRaises (TypeError , aspid , 1.0 )
446
+ self .assertRaises (TypeError , aspid , b'2' )
447
+ self .assertRaises (TypeError , aspid , '3' )
448
+ self .assertRaises (SystemError , aspid , NULL )
449
+
450
+ def test_long_aspid (self ):
451
+ self ._test_long_aspid (_testcapi .pylong_aspid )
452
+
453
+ def test_long_aspid_limited (self ):
454
+ self ._test_long_aspid (_testlimitedcapi .pylong_aspid )
455
+
428
456
def test_long_asnativebytes (self ):
429
457
import math
430
458
from _testcapi import (
0 commit comments