From 1340811c9d5ee0b74e218afd8ea2efd503b43288 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Tue, 15 Oct 2024 18:46:59 +0100 Subject: [PATCH 1/3] gh-125522: rewrite test_math.testTan to clarify intention --- Lib/test/test_math.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index e2e2a419c7778c..678c422c304e98 100644 --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -1899,14 +1899,22 @@ def testTan(self): self.ftest('tan(0)', math.tan(0), 0) self.ftest('tan(pi/4)', math.tan(math.pi/4), 1) self.ftest('tan(-pi/4)', math.tan(-math.pi/4), -1) - try: - self.assertTrue(math.isnan(math.tan(INF))) - self.assertTrue(math.isnan(math.tan(NINF))) - except: - self.assertRaises(ValueError, math.tan, INF) - self.assertRaises(ValueError, math.tan, NINF) self.assertTrue(math.isnan(math.tan(NAN))) + try: + tan = math.tan(INF) + except ValueError: + pass + else: + self.assertTrue(math.isnan(tan)) + + try: + ntan = math.tan(NINF) + except ValueError: + pass + else: + self.assertTrue(math.isnan(ntan)) + def testTanh(self): self.assertRaises(TypeError, math.tanh) self.ftest('tanh(0)', math.tanh(0), 0) From a22534e4e7108191d65d413d7d464e67bceb6d99 Mon Sep 17 00:00:00 2001 From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Date: Sat, 19 Oct 2024 00:15:12 +0100 Subject: [PATCH 2/3] Update Lib/test/test_math.py Co-authored-by: Sergey B Kirpichev --- Lib/test/test_math.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index 678c422c304e98..1c868cf93ac181 100644 --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -1902,19 +1902,11 @@ def testTan(self): self.assertTrue(math.isnan(math.tan(NAN))) try: - tan = math.tan(INF) + self.assertTrue(math.isnan(math.tan(INF))) + self.assertTrue(math.isnan(math.tan(NINF))) except ValueError: - pass - else: - self.assertTrue(math.isnan(tan)) - - try: - ntan = math.tan(NINF) - except ValueError: - pass - else: - self.assertTrue(math.isnan(ntan)) - + self.assertRaises(ValueError, math.tan, INF) + self.assertRaises(ValueError, math.tan, NINF) def testTanh(self): self.assertRaises(TypeError, math.tanh) self.ftest('tanh(0)', math.tanh(0), 0) From f08ea8abcdadb75f8f6bf21bf0c7699dc49e4a8d Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Sat, 19 Oct 2024 00:17:28 +0100 Subject: [PATCH 3/3] tweak --- Lib/test/test_math.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index 1c868cf93ac181..fecafd53aa6e6f 100644 --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -1899,14 +1899,14 @@ def testTan(self): self.ftest('tan(0)', math.tan(0), 0) self.ftest('tan(pi/4)', math.tan(math.pi/4), 1) self.ftest('tan(-pi/4)', math.tan(-math.pi/4), -1) - self.assertTrue(math.isnan(math.tan(NAN))) - try: self.assertTrue(math.isnan(math.tan(INF))) self.assertTrue(math.isnan(math.tan(NINF))) except ValueError: self.assertRaises(ValueError, math.tan, INF) self.assertRaises(ValueError, math.tan, NINF) + self.assertTrue(math.isnan(math.tan(NAN))) + def testTanh(self): self.assertRaises(TypeError, math.tanh) self.ftest('tanh(0)', math.tanh(0), 0)