Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Improve int test coverage
Following discussion in https://discuss.python.org/t/bug-in-int-42/26360/5

This tests some of the things documented in #100436
  • Loading branch information
hauntsaninja committed Apr 30, 2023
commit df988c198bd7719c2164c5e87ed86b8b4b86929e
18 changes: 18 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,22 @@ def test_basic(self):
self.assertEqual(int('2br45qc', 35), 4294967297)
self.assertEqual(int('1z141z5', 36), 4294967297)

def test_sign(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)

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