diff options
author | Kirill Podoprigora <kirill.bast9@mail.ru> | 2024-02-10 14:37:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-10 14:37:19 (GMT) |
commit | 5319c66550a6d6c6698dea75c0a0ee005873ce61 (patch) | |
tree | 6aab2c3b999e17a9e625157f81d226838c307927 /Lib/test/test_fractions.py | |
parent | 597fad07f7bf709ac7084ac20aa3647995759b01 (diff) | |
download | cpython-5319c66550a6d6c6698dea75c0a0ee005873ce61.zip cpython-5319c66550a6d6c6698dea75c0a0ee005873ce61.tar.gz cpython-5319c66550a6d6c6698dea75c0a0ee005873ce61.tar.bz2 |
gh-102840: Fix confused traceback when floordiv or mod operations happens between Fraction and complex objects (GH-102842)
Diffstat (limited to 'Lib/test/test_fractions.py')
-rw-r--r-- | Lib/test/test_fractions.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_fractions.py b/Lib/test/test_fractions.py index af3cb21..b45bd09 100644 --- a/Lib/test/test_fractions.py +++ b/Lib/test/test_fractions.py @@ -1314,6 +1314,33 @@ class FractionTest(unittest.TestCase): self.assertEqual(float(format(f, fmt2)), float(rhs)) self.assertEqual(float(format(-f, fmt2)), float('-' + rhs)) + def test_complex_handling(self): + # See issue gh-102840 for more details. + + a = F(1, 2) + b = 1j + message = "unsupported operand type(s) for %s: '%s' and '%s'" + # test forward + self.assertRaisesMessage(TypeError, + message % ("%", "Fraction", "complex"), + operator.mod, a, b) + self.assertRaisesMessage(TypeError, + message % ("//", "Fraction", "complex"), + operator.floordiv, a, b) + self.assertRaisesMessage(TypeError, + message % ("divmod()", "Fraction", "complex"), + divmod, a, b) + # test reverse + self.assertRaisesMessage(TypeError, + message % ("%", "complex", "Fraction"), + operator.mod, b, a) + self.assertRaisesMessage(TypeError, + message % ("//", "complex", "Fraction"), + operator.floordiv, b, a) + self.assertRaisesMessage(TypeError, + message % ("divmod()", "complex", "Fraction"), + divmod, b, a) + if __name__ == '__main__': unittest.main() |