@@ -49,7 +49,7 @@ class BitBucket:
4949 def write (self , line ):
5050 pass
5151
52- L = [
52+ test_conv_no_sign = [
5353 ('0' , 0 ),
5454 ('1' , 1 ),
5555 ('9' , 9 ),
@@ -71,6 +71,28 @@ def write(self, line):
7171 (chr (0x200 ), ValueError ),
7272]
7373
74+ test_conv_sign = [
75+ ('0' , 0 ),
76+ ('1' , 1 ),
77+ ('9' , 9 ),
78+ ('10' , 10 ),
79+ ('99' , 99 ),
80+ ('100' , 100 ),
81+ ('314' , 314 ),
82+ (' 314' , ValueError ),
83+ ('314 ' , 314 ),
84+ (' \t \t 314 \t \t ' , ValueError ),
85+ (repr (sys .maxsize ), sys .maxsize ),
86+ (' 1x' , ValueError ),
87+ (' 1 ' , ValueError ),
88+ (' 1\02 ' , ValueError ),
89+ ('' , ValueError ),
90+ (' ' , ValueError ),
91+ (' \t \t ' , ValueError ),
92+ (str (b'\u0663\u0661\u0664 ' ,'raw-unicode-escape' ), 314 ),
93+ (chr (0x200 ), ValueError ),
94+ ]
95+
7496class TestFailingBool :
7597 def __bool__ (self ):
7698 raise RuntimeError
@@ -641,8 +663,18 @@ def test_int(self):
641663 # Different base:
642664 self .assertEqual (int ("10" ,16 ), 16 )
643665 # Test conversion from strings and various anomalies
644- for s , v in L :
645- for sign in "" , "+" , "-" :
666+ # Testing with no sign at front
667+ for s , v in test_conv_no_sign :
668+ for prefix in "" , " " , "\t " , " \t \t " :
669+ ss = prefix + s
670+ vv = v
671+ try :
672+ self .assertEqual (int (ss ), vv )
673+ except v :
674+ pass
675+ # No whitespaces allowed between + or - sign and the number
676+ for s , v in test_conv_sign :
677+ for sign in "+" , "-" :
646678 for prefix in "" , " " , "\t " , " \t \t " :
647679 ss = prefix + sign + s
648680 vv = v
0 commit comments