diff options
author | Stefan Krah <skrah@bytereef.org> | 2012-04-05 13:21:58 (GMT) |
---|---|---|
committer | Stefan Krah <skrah@bytereef.org> | 2012-04-05 13:21:58 (GMT) |
commit | 0774e9b9f57197380c796d36353344cb95ed07bf (patch) | |
tree | 89d37955fb4526cf0f2a561b369788971746e93f /Lib/test | |
parent | e7eee01f3697835d168f82357a6a97d7ca40d99a (diff) | |
download | cpython-0774e9b9f57197380c796d36353344cb95ed07bf.zip cpython-0774e9b9f57197380c796d36353344cb95ed07bf.tar.gz cpython-0774e9b9f57197380c796d36353344cb95ed07bf.tar.bz2 |
Raise InvalidOperation if exponents of zeros are clamped during exact
conversion in the Decimal constructor. Exact here refers to the
representation and not to the value (clamping does not change the value).
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_decimal.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py index 694b959..90f4015 100644 --- a/Lib/test/test_decimal.py +++ b/Lib/test/test_decimal.py @@ -4953,6 +4953,30 @@ class CWhitebox(unittest.TestCase): self.assertRaises(ValueError, get_fmt, 12345, invalid_dot, 'g') self.assertRaises(ValueError, get_fmt, 12345, invalid_sep, 'g') + def test_exact_conversion(self): + Decimal = C.Decimal + localcontext = C.localcontext + InvalidOperation = C.InvalidOperation + + with localcontext() as c: + + c.traps[InvalidOperation] = True + + # Clamped + x = "0e%d" % sys.maxsize + self.assertRaises(InvalidOperation, Decimal, x) + + x = "0e%d" % (-sys.maxsize-1) + self.assertRaises(InvalidOperation, Decimal, x) + + # Overflow + x = "1e%d" % sys.maxsize + self.assertRaises(InvalidOperation, Decimal, x) + + # Underflow + x = "1e%d" % (-sys.maxsize-1) + self.assertRaises(InvalidOperation, Decimal, x) + all_tests = [ CExplicitConstructionTest, PyExplicitConstructionTest, |