@@ -643,6 +643,51 @@ def test_long_getsign(self):
643643
644644 # CRASHES getsign(NULL)
645645
646+ def test_long_ispositive (self ):
647+ # Test PyLong_IsPositive()
648+ ispositive = _testcapi .pylong_ispositive
649+ self .assertEqual (ispositive (1 ), 1 )
650+ self .assertEqual (ispositive (123 ), 1 )
651+ self .assertEqual (ispositive (- 1 ), 0 )
652+ self .assertEqual (ispositive (0 ), 0 )
653+ self .assertEqual (ispositive (True ), 1 )
654+ self .assertEqual (ispositive (False ), 0 )
655+ self .assertEqual (ispositive (IntSubclass (- 1 )), 0 )
656+ self .assertRaises (TypeError , ispositive , 1.0 )
657+ self .assertRaises (TypeError , ispositive , Index (123 ))
658+
659+ # CRASHES ispositive(NULL)
660+
661+ def test_long_isnegative (self ):
662+ # Test PyLong_IsNegative()
663+ isnegative = _testcapi .pylong_isnegative
664+ self .assertEqual (isnegative (1 ), 0 )
665+ self .assertEqual (isnegative (123 ), 0 )
666+ self .assertEqual (isnegative (- 1 ), 1 )
667+ self .assertEqual (isnegative (0 ), 0 )
668+ self .assertEqual (isnegative (True ), 0 )
669+ self .assertEqual (isnegative (False ), 0 )
670+ self .assertEqual (isnegative (IntSubclass (- 1 )), 1 )
671+ self .assertRaises (TypeError , isnegative , 1.0 )
672+ self .assertRaises (TypeError , isnegative , Index (123 ))
673+
674+ # CRASHES isnegative(NULL)
675+
676+ def test_long_iszero (self ):
677+ # Test PyLong_IsZero()
678+ iszero = _testcapi .pylong_iszero
679+ self .assertEqual (iszero (1 ), 0 )
680+ self .assertEqual (iszero (- 1 ), 0 )
681+ self .assertEqual (iszero (0 ), 1 )
682+ self .assertEqual (iszero (True ), 0 )
683+ self .assertEqual (iszero (False ), 1 )
684+ self .assertEqual (iszero (IntSubclass (- 1 )), 0 )
685+ self .assertEqual (iszero (IntSubclass (0 )), 1 )
686+ self .assertRaises (TypeError , iszero , 1.0 )
687+ self .assertRaises (TypeError , iszero , Index (123 ))
688+
689+ # CRASHES iszero(NULL)
690+
646691 def test_long_asint32 (self ):
647692 # Test PyLong_AsInt32() and PyLong_FromInt32()
648693 to_int32 = _testlimitedcapi .pylong_asint32
0 commit comments