Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve int test coverage #104024

Merged
merged 3 commits into from
May 1, 2023
Merged
Changes from 2 commits
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
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_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)

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