diff options
author | Stefan Krah <skrah@bytereef.org> | 2012-03-23 13:46:48 (GMT) |
---|---|---|
committer | Stefan Krah <skrah@bytereef.org> | 2012-03-23 13:46:48 (GMT) |
commit | b6405efd1bf8031fc3f15fbeba4f0e048844a50d (patch) | |
tree | b78f15d0ea428616cd0158317b56fac671f5921d /Lib/test/test_decimal.py | |
parent | 4b0215fd997cbdc714cb7515e121be96b9087cf4 (diff) | |
download | cpython-b6405efd1bf8031fc3f15fbeba4f0e048844a50d.zip cpython-b6405efd1bf8031fc3f15fbeba4f0e048844a50d.tar.gz cpython-b6405efd1bf8031fc3f15fbeba4f0e048844a50d.tar.bz2 |
Use the same exception hierarchy as decimal.py. FloatOperation now also
inherits from TypeError. Cleanup in module initialization to make repeated
import failures robust.
Diffstat (limited to 'Lib/test/test_decimal.py')
-rw-r--r-- | Lib/test/test_decimal.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py index af31b38..4a352e5 100644 --- a/Lib/test/test_decimal.py +++ b/Lib/test/test_decimal.py @@ -2378,6 +2378,46 @@ class PythonAPItests(unittest.TestCase): self.assertRaises(TypeError, D("-1").copy_abs, context=xc) self.assertRaises(TypeError, D("-1").copy_negate, context=xc) + def test_exception_hierarchy(self): + + decimal = self.decimal + DecimalException = decimal.DecimalException + InvalidOperation = decimal.InvalidOperation + FloatOperation = decimal.FloatOperation + DivisionByZero = decimal.DivisionByZero + Overflow = decimal.Overflow + Underflow = decimal.Underflow + Subnormal = decimal.Subnormal + Inexact = decimal.Inexact + Rounded = decimal.Rounded + Clamped = decimal.Clamped + + self.assertTrue(issubclass(DecimalException, ArithmeticError)) + + self.assertTrue(issubclass(InvalidOperation, DecimalException)) + self.assertTrue(issubclass(FloatOperation, DecimalException)) + self.assertTrue(issubclass(FloatOperation, TypeError)) + self.assertTrue(issubclass(DivisionByZero, DecimalException)) + self.assertTrue(issubclass(DivisionByZero, ZeroDivisionError)) + self.assertTrue(issubclass(Overflow, Rounded)) + self.assertTrue(issubclass(Overflow, Inexact)) + self.assertTrue(issubclass(Overflow, DecimalException)) + self.assertTrue(issubclass(Underflow, Inexact)) + self.assertTrue(issubclass(Underflow, Rounded)) + self.assertTrue(issubclass(Underflow, Subnormal)) + self.assertTrue(issubclass(Underflow, DecimalException)) + + self.assertTrue(issubclass(Subnormal, DecimalException)) + self.assertTrue(issubclass(Inexact, DecimalException)) + self.assertTrue(issubclass(Rounded, DecimalException)) + self.assertTrue(issubclass(Clamped, DecimalException)) + + self.assertTrue(issubclass(decimal.ConversionSyntax, InvalidOperation)) + self.assertTrue(issubclass(decimal.DivisionImpossible, InvalidOperation)) + self.assertTrue(issubclass(decimal.DivisionUndefined, InvalidOperation)) + self.assertTrue(issubclass(decimal.DivisionUndefined, ZeroDivisionError)) + self.assertTrue(issubclass(decimal.InvalidContext, InvalidOperation)) + class CPythonAPItests(PythonAPItests): decimal = C class PyPythonAPItests(PythonAPItests): |