diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-05-05 06:34:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-05 06:34:43 (GMT) |
commit | 0c605244a8f91b96b87eb5000bfe9e64428b8084 (patch) | |
tree | 492e6f9fd3cd903e1752d4d5f57da3e7388e890d /Lib/test | |
parent | 53e8bdd1e6434a06ac67ae0dd250d1abf7d2dc4c (diff) | |
download | cpython-0c605244a8f91b96b87eb5000bfe9e64428b8084.zip cpython-0c605244a8f91b96b87eb5000bfe9e64428b8084.tar.gz cpython-0c605244a8f91b96b87eb5000bfe9e64428b8084.tar.bz2 |
[3.12] gh-118164: str(10**10000) hangs if the C _decimal module is missing (GH-118503) (GH-118584)
Serhiy and I independently concluded that exact powers of 10
aren't possible in these contexts, so just checking the
string length is sufficient.
(cherry picked from commit 999f0c512281995fb61a0d9eda075fd846e8c505)
Co-authored-by: Tim Peters <tim.peters@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_decimal.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py index ea74f6c..1feaf2e 100644 --- a/Lib/test/test_decimal.py +++ b/Lib/test/test_decimal.py @@ -4722,9 +4722,33 @@ class PyWhitebox(unittest.TestCase): c.prec = 1 x = Decimal("152587890625") ** Decimal('-0.5') + self.assertEqual(x, Decimal('3e-6')) + c.prec = 2 + x = Decimal("152587890625") ** Decimal('-0.5') + self.assertEqual(x, Decimal('2.6e-6')) + c.prec = 3 + x = Decimal("152587890625") ** Decimal('-0.5') + self.assertEqual(x, Decimal('2.56e-6')) + c.prec = 28 + x = Decimal("152587890625") ** Decimal('-0.5') + self.assertEqual(x, Decimal('2.56e-6')) + c.prec = 201 x = Decimal(2**578) ** Decimal("-0.5") + # See https://github.com/python/cpython/issues/118027 + # Testing for an exact power could appear to hang, in the Python + # version, as it attempted to compute 10**(MAX_EMAX + 1). + # Fixed via https://github.com/python/cpython/pull/118503. + c.prec = P.MAX_PREC + c.Emax = P.MAX_EMAX + c.Emin = P.MIN_EMIN + c.traps[P.Inexact] = 1 + D2 = Decimal(2) + # If the bug is still present, the next statement won't complete. + res = D2 ** 117 + self.assertEqual(res, 1 << 117) + def test_py_immutability_operations(self): # Do operations and check that it didn't change internal objects. Decimal = P.Decimal @@ -5737,7 +5761,6 @@ class CWhitebox(unittest.TestCase): with C.localcontext(rounding=C.ROUND_DOWN): self.assertEqual(format(y, '#.1f'), '6.0') - @requires_docstrings @requires_cdecimal class SignatureTest(unittest.TestCase): |