Skip to content

Commit

Permalink
pythongh-71339: Use assertIsSubclass() and assertNotIsSubclass() in t…
Browse files Browse the repository at this point in the history
…est_decimal
  • Loading branch information
serhiy-storchaka committed Jan 14, 2025
1 parent eefd4a0 commit eddc43e
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions Lib/test/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ def test_explicit_context_create_decimal(self):
for v in [-2**63-1, -2**63, -2**31-1, -2**31, 0,
2**31-1, 2**31, 2**63-1, 2**63]:
d = nc.create_decimal(v)
self.assertTrue(isinstance(d, Decimal))
self.assertIsInstance(d, Decimal)
self.assertEqual(int(d), v)

nc.prec = 3
Expand Down Expand Up @@ -2590,8 +2590,8 @@ class PythonAPItests:
def test_abc(self):
Decimal = self.decimal.Decimal

self.assertTrue(issubclass(Decimal, numbers.Number))
self.assertFalse(issubclass(Decimal, numbers.Real))
self.assertIsSubclass(Decimal, numbers.Number)
self.assertNotIsSubclass(Decimal, numbers.Real)
self.assertIsInstance(Decimal(0), numbers.Number)
self.assertNotIsInstance(Decimal(0), numbers.Real)

Expand Down Expand Up @@ -2690,7 +2690,7 @@ class MyDecimal(Decimal):
def __init__(self, _):
self.x = 'y'

self.assertTrue(issubclass(MyDecimal, Decimal))
self.assertIsSubclass(MyDecimal, Decimal)

r = MyDecimal.from_float(0.1)
self.assertEqual(type(r), MyDecimal)
Expand Down Expand Up @@ -2908,31 +2908,31 @@ def test_exception_hierarchy(self):
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))
self.assertIsSubclass(DecimalException, ArithmeticError)

self.assertIsSubclass(InvalidOperation, DecimalException)
self.assertIsSubclass(FloatOperation, DecimalException)
self.assertIsSubclass(FloatOperation, TypeError)
self.assertIsSubclass(DivisionByZero, DecimalException)
self.assertIsSubclass(DivisionByZero, ZeroDivisionError)
self.assertIsSubclass(Overflow, Rounded)
self.assertIsSubclass(Overflow, Inexact)
self.assertIsSubclass(Overflow, DecimalException)
self.assertIsSubclass(Underflow, Inexact)
self.assertIsSubclass(Underflow, Rounded)
self.assertIsSubclass(Underflow, Subnormal)
self.assertIsSubclass(Underflow, DecimalException)

self.assertIsSubclass(Subnormal, DecimalException)
self.assertIsSubclass(Inexact, DecimalException)
self.assertIsSubclass(Rounded, DecimalException)
self.assertIsSubclass(Clamped, DecimalException)

self.assertIsSubclass(decimal.ConversionSyntax, InvalidOperation)
self.assertIsSubclass(decimal.DivisionImpossible, InvalidOperation)
self.assertIsSubclass(decimal.DivisionUndefined, InvalidOperation)
self.assertIsSubclass(decimal.DivisionUndefined, ZeroDivisionError)
self.assertIsSubclass(decimal.InvalidContext, InvalidOperation)

@requires_cdecimal
class CPythonAPItests(PythonAPItests, unittest.TestCase):
Expand Down

0 comments on commit eddc43e

Please sign in to comment.