@@ -49,7 +49,7 @@ class BitBucket:
49
49
def write (self , line ):
50
50
pass
51
51
52
- L = [
52
+ test_conv_no_sign = [
53
53
('0' , 0 ),
54
54
('1' , 1 ),
55
55
('9' , 9 ),
@@ -71,6 +71,28 @@ def write(self, line):
71
71
(chr (0x200 ), ValueError ),
72
72
]
73
73
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
+
74
96
class TestFailingBool :
75
97
def __bool__ (self ):
76
98
raise RuntimeError
@@ -641,8 +663,18 @@ def test_int(self):
641
663
# Different base:
642
664
self .assertEqual (int ("10" ,16 ), 16 )
643
665
# 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 "+" , "-" :
646
678
for prefix in "" , " " , "\t " , " \t \t " :
647
679
ss = prefix + sign + s
648
680
vv = v
0 commit comments