From 6370883acbad1f0513b53b2f2f3a052f3f893d9d Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Tue, 2 Apr 2024 12:24:59 +0300 Subject: [PATCH 1/2] gh-109802: Add coverage test for complex_abs() This tests overflow on L594. // line numbers wrt to 0f2fa6150b --- Lib/test/test_complex.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py index b057121f285dc7..0ec9e0d8ca99c6 100644 --- a/Lib/test/test_complex.py +++ b/Lib/test/test_complex.py @@ -10,6 +10,7 @@ INF = float("inf") NAN = float("nan") +DBL_MAX = sys.float_info.max # These tests ensure that complex math does the right thing ZERO_DIVISION = ( @@ -597,6 +598,8 @@ def test_abs(self): for num in nums: self.assertAlmostEqual((num.real**2 + num.imag**2) ** 0.5, abs(num)) + self.assertRaises(OverflowError, abs, complex(*[DBL_MAX]*2)) + def test_repr_str(self): def test(v, expected, test_fn=self.assertEqual): test_fn(repr(v), expected) From 6d38965e6a610927e6aff1ef7ce3ea7ad36342dc Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Thu, 4 Apr 2024 16:25:11 +0200 Subject: [PATCH 2/2] Simplify a bit --- Lib/test/test_complex.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py index 0ec9e0d8ca99c6..fa3017b24e16c8 100644 --- a/Lib/test/test_complex.py +++ b/Lib/test/test_complex.py @@ -598,7 +598,7 @@ def test_abs(self): for num in nums: self.assertAlmostEqual((num.real**2 + num.imag**2) ** 0.5, abs(num)) - self.assertRaises(OverflowError, abs, complex(*[DBL_MAX]*2)) + self.assertRaises(OverflowError, abs, complex(DBL_MAX, DBL_MAX)) def test_repr_str(self): def test(v, expected, test_fn=self.assertEqual):