summaryrefslogtreecommitdiff
path: root/Lib/test/test_int.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_int.py')
-rw-r--r--Lib/test/test_int.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py
index 625c388cd9..f484c59f67 100644
--- a/Lib/test/test_int.py
+++ b/Lib/test/test_int.py
@@ -795,5 +795,52 @@ class IntSubclassStrDigitLimitsTests(IntStrDigitLimitsTests):
int_class = IntSubclass
+class PyLongModuleTests(unittest.TestCase):
+ # Tests of the functions in _pylong.py. Those get used when the
+ # number of digits in the input values are large enough.
+
+ def setUp(self):
+ super().setUp()
+ self._previous_limit = sys.get_int_max_str_digits()
+ sys.set_int_max_str_digits(0)
+
+ def tearDown(self):
+ sys.set_int_max_str_digits(self._previous_limit)
+ super().tearDown()
+
+ def test_pylong_int_to_decimal(self):
+ n = (1 << 100_000) - 1
+ suffix = '9883109375'
+ s = str(n)
+ assert s[-10:] == suffix
+ s = str(-n)
+ assert s[-10:] == suffix
+ s = '%d' % n
+ assert s[-10:] == suffix
+ s = b'%d' % n
+ assert s[-10:] == suffix.encode('ascii')
+
+ def test_pylong_int_divmod(self):
+ n = (1 << 100_000)
+ a, b = divmod(n*3 + 1, n)
+ assert a == 3 and b == 1
+
+ def test_pylong_str_to_int(self):
+ v1 = 1 << 100_000
+ s = str(v1)
+ v2 = int(s)
+ assert v1 == v2
+ v3 = int(' -' + s)
+ assert -v1 == v3
+ v4 = int(' +' + s + ' ')
+ assert v1 == v4
+ with self.assertRaises(ValueError) as err:
+ int(s + 'z')
+ with self.assertRaises(ValueError) as err:
+ int(s + '_')
+ with self.assertRaises(ValueError) as err:
+ int('_' + s)
+
+
if __name__ == "__main__":
unittest.main()