|
24 | 24 | with the corresponding argument. |
25 | 25 | """ |
26 | 26 |
|
| 27 | +import contextlib |
27 | 28 | import logging |
28 | 29 | import math |
29 | 30 | import os, sys |
@@ -4493,6 +4494,15 @@ def test_decimal_attributes(self): |
4493 | 4494 |
|
4494 | 4495 | class Coverage: |
4495 | 4496 |
|
| 4497 | + @contextlib.contextmanager |
| 4498 | + def unbound_context(self, prec=None, Emax=None, Emin=None): |
| 4499 | + with self.decimal.localcontext() as c: |
| 4500 | + c.prec = self.decimal.MAX_PREC if prec is None else prec |
| 4501 | + c.Emax = self.decimal.MAX_EMAX if Emax is None else Emax |
| 4502 | + c.Emin = self.decimal.MIN_EMIN if Emin is None else Emin |
| 4503 | + c.traps[self.decimal.Inexact] = 1 |
| 4504 | + yield c |
| 4505 | + |
4496 | 4506 | def test_adjusted(self): |
4497 | 4507 | Decimal = self.decimal.Decimal |
4498 | 4508 |
|
@@ -4660,6 +4670,22 @@ def test_divmod(self): |
4660 | 4670 | self.assertTrue(c.flags[InvalidOperation] and |
4661 | 4671 | c.flags[DivisionByZero]) |
4662 | 4672 |
|
| 4673 | + def test_divide_unbound_context(self): |
| 4674 | + with self.unbound_context() as c: |
| 4675 | + x = self.decimal.Decimal('1') |
| 4676 | + y = x // 1 # should be fast |
| 4677 | + |
| 4678 | + def test_remainder_near(self): |
| 4679 | + L = 1000 |
| 4680 | + limit = sys.get_int_max_str_digits() |
| 4681 | + sys.set_int_max_str_digits(L) |
| 4682 | + self.addCleanup(sys.set_int_max_str_digits, limit) |
| 4683 | + |
| 4684 | + with self.unbound_context(prec=2 * L) as c: |
| 4685 | + self.assertEqual(c.prec, 2 * L) |
| 4686 | + x = self.decimal.Decimal(f'1e{L}') |
| 4687 | + y = x.remainder_near(1) # must not raise a ValueError |
| 4688 | + |
4663 | 4689 | def test_power(self): |
4664 | 4690 | Decimal = self.decimal.Decimal |
4665 | 4691 | localcontext = self.decimal.localcontext |
|
0 commit comments