From df988c198bd7719c2164c5e87ed86b8b4b86929e Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Sun, 30 Apr 2023 16:23:22 -0700 Subject: [PATCH 1/3] 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 https://github.com/python/cpython/pull/100436 --- Lib/test/test_int.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py index 334fea0774be51..2ac1f8f263b928 100644 --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -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) @@ -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'): From 59e4ff1d87a1598ddfe4d5f4a5ab875814745df9 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Sun, 30 Apr 2023 16:45:19 -0700 Subject: [PATCH 2/3] rename the method to test_invalid_signs --- Lib/test/test_int.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py index 2ac1f8f263b928..aede92014cde8a 100644 --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -223,7 +223,7 @@ def test_basic(self): self.assertEqual(int('2br45qc', 35), 4294967297) self.assertEqual(int('1z141z5', 36), 4294967297) - def test_sign(self): + def test_invalid_signs(self): with self.assertRaises(ValueError): int('+') with self.assertRaises(ValueError): From 51f93b704fe8097c1d6d745699dd36ce7ff2452b Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Sun, 30 Apr 2023 16:48:25 -0700 Subject: [PATCH 3/3] test unicode in base 0 as well --- Lib/test/test_int.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py index aede92014cde8a..5545ee39d8e942 100644 --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -238,6 +238,8 @@ def test_invalid_signs(self): 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: pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy