diff options
author | Stefan Krah <skrah@bytereef.org> | 2012-04-05 13:46:19 (GMT) |
---|---|---|
committer | Stefan Krah <skrah@bytereef.org> | 2012-04-05 13:46:19 (GMT) |
commit | ff3eca0cc3c2b0e57079140af313682eecc5f4cc (patch) | |
tree | 1fb0ca20e28298b4c608843184a418c1fe999e94 /Lib/test/test_decimal.py | |
parent | 0774e9b9f57197380c796d36353344cb95ed07bf (diff) | |
download | cpython-ff3eca0cc3c2b0e57079140af313682eecc5f4cc.zip cpython-ff3eca0cc3c2b0e57079140af313682eecc5f4cc.tar.gz cpython-ff3eca0cc3c2b0e57079140af313682eecc5f4cc.tar.bz2 |
Allow printing a leading '-' and the maximum number of exponent digits
rather than raising RuntimeError (allocated space is sufficient for the
additional character).
Diffstat (limited to 'Lib/test/test_decimal.py')
-rw-r--r-- | Lib/test/test_decimal.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py index 90f4015..781df1f 100644 --- a/Lib/test/test_decimal.py +++ b/Lib/test/test_decimal.py @@ -4977,6 +4977,54 @@ class CWhitebox(unittest.TestCase): x = "1e%d" % (-sys.maxsize-1) self.assertRaises(InvalidOperation, Decimal, x) + def test_from_tuple(self): + Decimal = C.Decimal + localcontext = C.localcontext + InvalidOperation = C.InvalidOperation + Overflow = C.Overflow + Underflow = C.Underflow + + with localcontext() as c: + + c.traps[InvalidOperation] = True + c.traps[Overflow] = True + c.traps[Underflow] = True + + # SSIZE_MAX + x = (1, (), sys.maxsize) + self.assertEqual(str(c.create_decimal(x)), '-0E+999999') + self.assertRaises(InvalidOperation, Decimal, x) + + x = (1, (0, 1, 2), sys.maxsize) + self.assertRaises(Overflow, c.create_decimal, x) + self.assertRaises(InvalidOperation, Decimal, x) + + # SSIZE_MIN + x = (1, (), -sys.maxsize-1) + self.assertEqual(str(c.create_decimal(x)), '-0E-1000026') + self.assertRaises(InvalidOperation, Decimal, x) + + x = (1, (0, 1, 2), -sys.maxsize-1) + self.assertRaises(Underflow, c.create_decimal, x) + self.assertRaises(InvalidOperation, Decimal, x) + + # OverflowError + x = (1, (), sys.maxsize+1) + self.assertRaises(OverflowError, c.create_decimal, x) + self.assertRaises(OverflowError, Decimal, x) + + x = (1, (), -sys.maxsize-2) + self.assertRaises(OverflowError, c.create_decimal, x) + self.assertRaises(OverflowError, Decimal, x) + + # Specials + x = (1, (), "N") + self.assertEqual(str(Decimal(x)), '-sNaN') + x = (1, (0,), "N") + self.assertEqual(str(Decimal(x)), '-sNaN') + x = (1, (0, 1), "N") + self.assertEqual(str(Decimal(x)), '-sNaN1') + all_tests = [ CExplicitConstructionTest, PyExplicitConstructionTest, |