summaryrefslogtreecommitdiff
path: root/Lib/test/test_cmath.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_cmath.py')
-rw-r--r--Lib/test/test_cmath.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/Lib/test/test_cmath.py b/Lib/test/test_cmath.py
index 1f884e52a2..0451fb0aa2 100644
--- a/Lib/test/test_cmath.py
+++ b/Lib/test/test_cmath.py
@@ -4,6 +4,8 @@ import test.test_math as test_math
import unittest
import cmath, math
from cmath import phase, polar, rect, pi
+import platform
+import sys
import sysconfig
INF = float('inf')
@@ -154,6 +156,23 @@ class CMathTests(unittest.TestCase):
self.assertAlmostEqual(cmath.e, e_expected, places=9,
msg="cmath.e is {}; should be {}".format(cmath.e, e_expected))
+ def test_infinity_and_nan_constants(self):
+ self.assertEqual(cmath.inf.real, math.inf)
+ self.assertEqual(cmath.inf.imag, 0.0)
+ self.assertEqual(cmath.infj.real, 0.0)
+ self.assertEqual(cmath.infj.imag, math.inf)
+
+ self.assertTrue(math.isnan(cmath.nan.real))
+ self.assertEqual(cmath.nan.imag, 0.0)
+ self.assertEqual(cmath.nanj.real, 0.0)
+ self.assertTrue(math.isnan(cmath.nanj.imag))
+
+ # Check consistency with reprs.
+ self.assertEqual(repr(cmath.inf), "inf")
+ self.assertEqual(repr(cmath.infj), "infj")
+ self.assertEqual(repr(cmath.nan), "nan")
+ self.assertEqual(repr(cmath.nanj), "nanj")
+
def test_user_object(self):
# Test automatic calling of __complex__ and __float__ by cmath
# functions
@@ -315,6 +334,18 @@ class CMathTests(unittest.TestCase):
@requires_IEEE_754
def test_specific_values(self):
+ # Some tests need to be skipped on ancient OS X versions.
+ # See issue #27953.
+ SKIP_ON_TIGER = {'tan0064'}
+
+ osx_version = None
+ if sys.platform == 'darwin':
+ version_txt = platform.mac_ver()[0]
+ try:
+ osx_version = tuple(map(int, version_txt.split('.')))
+ except ValueError:
+ pass
+
def rect_complex(z):
"""Wrapped version of rect that accepts a complex number instead of
two float arguments."""
@@ -328,6 +359,12 @@ class CMathTests(unittest.TestCase):
for id, fn, ar, ai, er, ei, flags in parse_testfile(test_file):
arg = complex(ar, ai)
expected = complex(er, ei)
+
+ # Skip certain tests on OS X 10.4.
+ if osx_version is not None and osx_version < (10, 5):
+ if id in SKIP_ON_TIGER:
+ continue
+
if fn == 'rect':
function = rect_complex
elif fn == 'polar':