Skip to content

Commit

Permalink
Improve int test coverage (python#104024)
Browse files Browse the repository at this point in the history
Following discussion in https://discuss.python.org/t/bug-in-int-42/26360/5

This tests some of the things documented in python#100436

Co-authored-by: Gregory P. Smith <greg@krypto.org>
  • Loading branch information
hauntsaninja and gpshead authored May 1, 2023
1 parent 74a2b79 commit 69bc86c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Lib/test/test_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ def test_basic(self):
self.assertEqual(int(' 0O123 ', 0), 83)
self.assertEqual(int(' 0X123 ', 0), 291)
self.assertEqual(int(' 0B100 ', 0), 4)
with self.assertRaises(ValueError):
int('010', 0)

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

def test_invalid_signs(self):
with self.assertRaises(ValueError):
int('+')
with self.assertRaises(ValueError):
int('-')
with self.assertRaises(ValueError):
int('- 1')
with self.assertRaises(ValueError):
int('+ 1')
with self.assertRaises(ValueError):
int(' + 1 ')

def test_unicode(self):
self.assertEqual(int("१२३४५६७८९०1234567890"), 12345678901234567890)
self.assertEqual(int('١٢٣٤٥٦٧٨٩٠'), 1234567890)
self.assertEqual(int("१२३४५६७८९०1234567890", 0), 12345678901234567890)
self.assertEqual(int('١٢٣٤٥٦٧٨٩٠', 0), 1234567890)

def test_underscores(self):
for lit in VALID_UNDERSCORE_LITERALS:
if any(ch in lit for ch in '.eEjJ'):
Expand Down

0 comments on commit 69bc86c

Please sign in to comment.