Skip to content

Commit 69bc86c

Browse files
Improve int test coverage (#104024)
Following discussion in https://discuss.python.org/t/bug-in-int-42/26360/5 This tests some of the things documented in #100436 Co-authored-by: Gregory P. Smith <[email protected]>
1 parent 74a2b79 commit 69bc86c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Lib/test/test_int.py

+20
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ def test_basic(self):
155155
self.assertEqual(int(' 0O123 ', 0), 83)
156156
self.assertEqual(int(' 0X123 ', 0), 291)
157157
self.assertEqual(int(' 0B100 ', 0), 4)
158+
with self.assertRaises(ValueError):
159+
int('010', 0)
158160

159161
# without base still base 10
160162
self.assertEqual(int('0123'), 123)
@@ -221,6 +223,24 @@ def test_basic(self):
221223
self.assertEqual(int('2br45qc', 35), 4294967297)
222224
self.assertEqual(int('1z141z5', 36), 4294967297)
223225

226+
def test_invalid_signs(self):
227+
with self.assertRaises(ValueError):
228+
int('+')
229+
with self.assertRaises(ValueError):
230+
int('-')
231+
with self.assertRaises(ValueError):
232+
int('- 1')
233+
with self.assertRaises(ValueError):
234+
int('+ 1')
235+
with self.assertRaises(ValueError):
236+
int(' + 1 ')
237+
238+
def test_unicode(self):
239+
self.assertEqual(int("१२३४५६७८९०1234567890"), 12345678901234567890)
240+
self.assertEqual(int('١٢٣٤٥٦٧٨٩٠'), 1234567890)
241+
self.assertEqual(int("१२३४५६७८९०1234567890", 0), 12345678901234567890)
242+
self.assertEqual(int('١٢٣٤٥٦٧٨٩٠', 0), 1234567890)
243+
224244
def test_underscores(self):
225245
for lit in VALID_UNDERSCORE_LITERALS:
226246
if any(ch in lit for ch in '.eEjJ'):

0 commit comments

Comments
 (0)