summaryrefslogtreecommitdiff
path: root/Lib/test/test_int.py
diff options
context:
space:
mode:
authorShantanu <12621235+hauntsaninja@users.noreply.github.com>2023-04-30 17:16:38 -0700
committerGitHub <noreply@github.com>2023-04-30 17:16:38 -0700
commit69bc86cb1aed49db27afc0095e0f4bcd8f1f3983 (patch)
treef713ba53465b9d9339eb72e2069ad1776e5797f2 /Lib/test/test_int.py
parent74a2b79c6265c92ef381b5ff0dc63903bf0178ac (diff)
downloadcpython-git-69bc86cb1aed49db27afc0095e0f4bcd8f1f3983.tar.gz
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 https://github.com/python/cpython/pull/100436 Co-authored-by: Gregory P. Smith <greg@krypto.org>
Diffstat (limited to 'Lib/test/test_int.py')
-rw-r--r--Lib/test/test_int.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py
index 334fea0774..5545ee39d8 100644
--- a/Lib/test/test_int.py
+++ b/Lib/test/test_int.py
@@ -155,6 +155,8 @@ class IntTestCases(unittest.TestCase):
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)
@@ -221,6 +223,24 @@ class IntTestCases(unittest.TestCase):
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'):