Issue #10337: skip tests of tanh() sign in test_math and test_cmath if tanh()
doesn't preserve the zero sign (if TANH_PRESERVES_ZERO_SIGN define is 0).
diff --git a/Lib/test/test_cmath.py b/Lib/test/test_cmath.py
index a803363..e3cf03e 100644
--- a/Lib/test/test_cmath.py
+++ b/Lib/test/test_cmath.py
@@ -1,8 +1,9 @@
from test.support import run_unittest
-from test.test_math import parse_testfile, test_file
+from test.test_math import parse_testfile, test_file, requires_IEEE_754
import unittest
import cmath, math
from cmath import phase, polar, rect, pi
+import sysconfig
INF = float('inf')
NAN = float('nan')
@@ -61,6 +62,12 @@
def tearDown(self):
self.test_values.close()
+ def assertComplexIdentical(self, a, b):
+ """Fail if two complex numbers value or sign is different."""
+ self.assertEqual(a, b)
+ self.assertEqual(math.copysign(1., a.real), math.copysign(1., b.real))
+ self.assertEqual(math.copysign(1., a.imag), math.copysign(1., b.imag))
+
def rAssertAlmostEqual(self, a, b, rel_err = 2e-15, abs_err = 5e-323,
msg=None):
"""Fail if the two floating-point numbers are not almost equal.
@@ -473,6 +480,15 @@
self.assertTrue(cmath.isinf(complex(NAN, INF)))
self.assertTrue(cmath.isinf(complex(INF, NAN)))
+ @requires_IEEE_754
+ @unittest.skipIf(sysconfig.get_config_var('TANH_PRESERVES_ZERO_SIGN') == 0,
+ "system tanh() function doesn't copy the sign")
+ def testTanhSign(self):
+ self.assertComplexIdentical(cmath.tanh(complex(0., .0j)), complex(0., .0j))
+ self.assertComplexIdentical(cmath.tanh(complex(0., -.0j)), complex(0., -.0j))
+ self.assertComplexIdentical(cmath.tanh(complex(-0., .0j)), complex(-0., .0j))
+ self.assertComplexIdentical(cmath.tanh(complex(-0., -.0j)), complex(-0., -.0j))
+
def test_main():
run_unittest(CMathTests)