[Python-checkins] [3.11] Improve int test coverage (GH-104024) (#104026)
hauntsaninja
webhook-mailer at python.org
Sun Apr 30 20:50:07 EDT 2023
https://github.com/python/cpython/commit/2be3656855268dcfabec2c55cdb679038db33e29
commit: 2be3656855268dcfabec2c55cdb679038db33e29
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: hauntsaninja <12621235+hauntsaninja at users.noreply.github.com>
date: 2023-05-01T00:50:01Z
summary:
[3.11] Improve int test coverage (GH-104024) (#104026)
Improve int test coverage (GH-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
(cherry picked from commit 69bc86cb1aed49db27afc0095e0f4bcd8f1f3983)
Co-authored-by: Shantanu <12621235+hauntsaninja at users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg at krypto.org>
files:
M Lib/test/test_int.py
diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py
index c972b8afb48d..a1c4a04f5e08 100644
--- a/Lib/test/test_int.py
+++ b/Lib/test/test_int.py
@@ -149,6 +149,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)
@@ -215,6 +217,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'):
More information about the Python-checkins
mailing list