Skip to content

Commit 2bee583

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

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
@@ -149,6 +149,8 @@ def test_basic(self):
149149
self.assertEqual(int(' 0O123 ', 0), 83)
150150
self.assertEqual(int(' 0X123 ', 0), 291)
151151
self.assertEqual(int(' 0B100 ', 0), 4)
152+
with self.assertRaises(ValueError):
153+
int('010', 0)
152154

153155
# without base still base 10
154156
self.assertEqual(int('0123'), 123)
@@ -215,6 +217,24 @@ def test_basic(self):
215217
self.assertEqual(int('2br45qc', 35), 4294967297)
216218
self.assertEqual(int('1z141z5', 36), 4294967297)
217219

220+
def test_invalid_signs(self):
221+
with self.assertRaises(ValueError):
222+
int('+')
223+
with self.assertRaises(ValueError):
224+
int('-')
225+
with self.assertRaises(ValueError):
226+
int('- 1')
227+
with self.assertRaises(ValueError):
228+
int('+ 1')
229+
with self.assertRaises(ValueError):
230+
int(' + 1 ')
231+
232+
def test_unicode(self):
233+
self.assertEqual(int("१२३४५६७८९०1234567890"), 12345678901234567890)
234+
self.assertEqual(int('١٢٣٤٥٦٧٨٩٠'), 1234567890)
235+
self.assertEqual(int("१२३४५६७८९०1234567890", 0), 12345678901234567890)
236+
self.assertEqual(int('١٢٣٤٥٦٧٨٩٠', 0), 1234567890)
237+
218238
def test_underscores(self):
219239
for lit in VALID_UNDERSCORE_LITERALS:
220240
if any(ch in lit for ch in '.eEjJ'):

0 commit comments

Comments
 (0)