]> granicus.if.org Git - python/commitdiff
Issue #10624: Use support.requires_IEEE_754 in all appropriate tests.
authorEric Smith <eric@trueblade.com>
Sat, 4 Dec 2010 15:17:38 +0000 (15:17 +0000)
committerEric Smith <eric@trueblade.com>
Sat, 4 Dec 2010 15:17:38 +0000 (15:17 +0000)
Lib/test/datetimetester.py
Lib/test/test_cmath.py
Lib/test/test_complex.py
Lib/test/test_decimal.py
Lib/test/test_float.py
Lib/test/test_fractions.py
Lib/test/test_long.py

index e91eb673a4d7a1b0bde1c07b9630cb91c889920a..48e5095f3d648acc9171ce3b4282e506d9cae9e1 100644 (file)
@@ -38,11 +38,6 @@ OTHERSTUFF = (10, 34.5, "abc", {}, [], ())
 INF = float("inf")
 NAN = float("nan")
 
-# decorator for skipping tests on non-IEEE 754 platforms
-requires_IEEE_754 = unittest.skipUnless(
-    float.__getformat__("double").startswith("IEEE"),
-    "test requires IEEE 754 doubles")
-
 
 #############################################################################
 # module tests
@@ -407,7 +402,7 @@ class TestTimeDelta(HarmlessMixedComparison, unittest.TestCase):
         self.assertRaises(ZeroDivisionError, lambda: a / 0.0)
         self.assertRaises(TypeError, lambda: a / '')
 
-    @requires_IEEE_754
+    @support.requires_IEEE_754
     def test_disallowed_special(self):
         a = timedelta(42)
         self.assertRaises(ValueError, a.__mul__, NAN)
@@ -589,7 +584,7 @@ class TestTimeDelta(HarmlessMixedComparison, unittest.TestCase):
         self.assertRaises(OverflowError, day.__truediv__, 1e-10)
         self.assertRaises(OverflowError, day.__truediv__, 9e-10)
 
-    @requires_IEEE_754
+    @support.requires_IEEE_754
     def _test_overflow_special(self):
         day = timedelta(1)
         self.assertRaises(OverflowError, day.__mul__, INF)
index 168b513bbd54d9538a2c7d2de2cb36badf8af0c9..4e93be47add653f47bcf3bde80507f7669142c47 100644 (file)
@@ -1,5 +1,5 @@
-from test.support import run_unittest
-from test.test_math import parse_testfile, test_file, requires_IEEE_754
+from test.support import run_unittest, requires_IEEE_754
+from test.test_math import parse_testfile, test_file
 import unittest
 import cmath, math
 from cmath import phase, polar, rect, pi
@@ -312,10 +312,8 @@ class CMathTests(unittest.TestCase):
                 self.rAssertAlmostEqual(math.log(v, base), z.real)
                 self.assertEqual(0., z.imag)
 
+    @requires_IEEE_754
     def test_specific_values(self):
-        if not float.__getformat__("double").startswith("IEEE"):
-            return
-
         def rect_complex(z):
             """Wrapped version of rect that accepts a complex number instead of
             two float arguments."""
@@ -460,9 +458,11 @@ class CMathTests(unittest.TestCase):
         self.assertEqual(abs(complex(INF, NAN)), INF)
         self.assertTrue(math.isnan(abs(complex(NAN, NAN))))
 
+
+    @requires_IEEE_754
+    def test_abs_overflows(self):
         # result overflows
-        if float.__getformat__("double").startswith("IEEE"):
-            self.assertRaises(OverflowError, abs, complex(1.4e308, 1.4e308))
+        self.assertRaises(OverflowError, abs, complex(1.4e308, 1.4e308))
 
     def assertCEqual(self, a, b):
         eps = 1E-7
index 548726be9b24cdba54dd7c09bc0ac2f34f5ee53d..f9bed06a00fcd42da84c40f65d5bf58495394e1a 100644 (file)
@@ -435,15 +435,14 @@ class ComplexTest(unittest.TestCase):
         self.assertEqual(complex(0, INF).__getnewargs__(), (0.0, INF))
         self.assertEqual(complex(INF, 0).__getnewargs__(), (INF, 0.0))
 
-    if float.__getformat__("double").startswith("IEEE"):
-        def test_plus_minus_0j(self):
-            # test that -0j and 0j literals are not identified
-            z1, z2 = 0j, -0j
-            self.assertEqual(atan2(z1.imag, -1.), atan2(0., -1.))
-            self.assertEqual(atan2(z2.imag, -1.), atan2(-0., -1.))
-
-    @unittest.skipUnless(float.__getformat__("double").startswith("IEEE"),
-                         "test requires IEEE 754 doubles")
+    @support.requires_IEEE_754
+    def test_plus_minus_0j(self):
+        # test that -0j and 0j literals are not identified
+        z1, z2 = 0j, -0j
+        self.assertEqual(atan2(z1.imag, -1.), atan2(0., -1.))
+        self.assertEqual(atan2(z2.imag, -1.), atan2(-0., -1.))
+
+    @support.requires_IEEE_754
     def test_negated_imaginary_literal(self):
         z0 = -0j
         z1 = -7j
@@ -459,15 +458,13 @@ class ComplexTest(unittest.TestCase):
         self.assertFloatsAreIdentical(z2.real, -0.0)
         self.assertFloatsAreIdentical(z2.imag, -INF)
 
-    @unittest.skipUnless(float.__getformat__("double").startswith("IEEE"),
-                         "test requires IEEE 754 doubles")
+    @support.requires_IEEE_754
     def test_overflow(self):
         self.assertEqual(complex("1e500"), complex(INF, 0.0))
         self.assertEqual(complex("-1e500j"), complex(0.0, -INF))
         self.assertEqual(complex("-1e500+1.8e308j"), complex(-INF, INF))
 
-    @unittest.skipUnless(float.__getformat__("double").startswith("IEEE"),
-                         "test requires IEEE 754 doubles")
+    @support.requires_IEEE_754
     def test_repr_roundtrip(self):
         vals = [0.0, 1e-500, 1e-315, 1e-200, 0.0123, 3.1415, 1e50, INF, NAN]
         vals += [-v for v in vals]
index 3036170aeb83c77038d2f9ff43838ea47d3ca8c7..8f1f8638ff61a1b85a5ca998f0c32277879d9cfb 100644 (file)
@@ -32,7 +32,8 @@ import pickle, copy
 import unittest
 from decimal import *
 import numbers
-from test.support import run_unittest, run_doctest, is_resource_enabled
+from test.support import (run_unittest, run_doctest, is_resource_enabled,
+                          requires_IEEE_754)
 from test.support import check_warnings
 import random
 try:
@@ -61,11 +62,6 @@ def init():
         )
     setcontext(DefaultTestContext)
 
-# decorator for skipping tests on non-IEEE 754 platforms
-requires_IEEE_754 = unittest.skipUnless(
-    float.__getformat__("double").startswith("IEEE"),
-    "test requires IEEE 754 doubles")
-
 TESTDATADIR = 'decimaltestdata'
 if __name__ == '__main__':
     file = sys.argv[0]
index ddf93bcf8773f269923951d61e27e9139b029479..30cb4b91674c3b141117f49822a41b28b94bc6a5 100644 (file)
@@ -16,10 +16,6 @@ requires_getformat = unittest.skipUnless(have_getformat,
                                          "requires __getformat__")
 requires_setformat = unittest.skipUnless(hasattr(float, "__setformat__"),
                                          "requires __setformat__")
-# decorator for skipping tests on non-IEEE 754 platforms
-requires_IEEE_754 = unittest.skipUnless(have_getformat and
-    float.__getformat__("double").startswith("IEEE"),
-    "test requires IEEE 754 doubles")
 
 #locate file with float format test values
 test_dir = os.path.dirname(__file__) or os.curdir
@@ -196,7 +192,7 @@ class GeneralFloatCases(unittest.TestCase):
         # distingishes -0.0 and 0.0.
         self.assertEqual((a, copysign(1.0, a)), (b, copysign(1.0, b)))
 
-    @requires_IEEE_754
+    @support.requires_IEEE_754
     def test_float_mod(self):
         # Check behaviour of % operator for IEEE 754 special cases.
         # In particular, check signs of zeros.
@@ -216,7 +212,7 @@ class GeneralFloatCases(unittest.TestCase):
         self.assertEqualAndEqualSign(mod(1e-100, -1.0), -1.0)
         self.assertEqualAndEqualSign(mod(1.0, -1.0), -0.0)
 
-    @requires_IEEE_754
+    @support.requires_IEEE_754
     def test_float_pow(self):
         # test builtin pow and ** operator for IEEE 754 special cases.
         # Special cases taken from section F.9.4.4 of the C99 specification
@@ -503,7 +499,7 @@ class UnknownFormatTestCase(unittest.TestCase):
 
 class IEEEFormatTestCase(unittest.TestCase):
 
-    @requires_IEEE_754
+    @support.requires_IEEE_754
     def test_double_specials_do_unpack(self):
         for fmt, data in [('>d', BE_DOUBLE_INF),
                           ('>d', BE_DOUBLE_NAN),
@@ -511,7 +507,7 @@ class IEEEFormatTestCase(unittest.TestCase):
                           ('<d', LE_DOUBLE_NAN)]:
             struct.unpack(fmt, data)
 
-    @requires_IEEE_754
+    @support.requires_IEEE_754
     def test_float_specials_do_unpack(self):
         for fmt, data in [('>f', BE_FLOAT_INF),
                           ('>f', BE_FLOAT_NAN),
@@ -574,7 +570,7 @@ class FormatTestCase(unittest.TestCase):
         self.assertEqual(format(INF, 'f'), 'inf')
         self.assertEqual(format(INF, 'F'), 'INF')
 
-    @requires_IEEE_754
+    @support.requires_IEEE_754
     def test_format_testfile(self):
         with open(format_testfile) as testfile:
             for line in testfile:
@@ -658,7 +654,7 @@ class ReprTestCase(unittest.TestCase):
             self.assertEqual(repr(float(s)), str(float(s)))
             self.assertEqual(repr(float(negs)), str(float(negs)))
 
-@requires_IEEE_754
+@support.requires_IEEE_754
 class RoundTestCase(unittest.TestCase):
 
     def test_inf_nan(self):
index a63ee89ed9717067c8b55e33cc8f8638fb450105..26e132f4e564b6f1d4c6105504f66514bf67702c 100644 (file)
@@ -1,7 +1,7 @@
 """Tests for Lib/fractions.py."""
 
 from decimal import Decimal
-from test.support import run_unittest
+from test.support import run_unittest, requires_IEEE_754
 import math
 import numbers
 import operator
@@ -12,11 +12,6 @@ from pickle import dumps, loads
 F = fractions.Fraction
 gcd = fractions.gcd
 
-# decorator for skipping tests on non-IEEE 754 platforms
-requires_IEEE_754 = unittest.skipUnless(
-    float.__getformat__("double").startswith("IEEE"),
-    "test requires IEEE 754 doubles")
-
 class DummyFloat(object):
     """Dummy float class for testing comparisons with Fractions"""
 
index 12197ee638f363c16f8b18a4f5061aebbd3b5b8d..04066ec1e79a5f28fea6bb55225bcf1c37a44254 100644 (file)
@@ -1,5 +1,6 @@
 import unittest
 from test import support
+
 import sys
 
 import random
@@ -15,11 +16,6 @@ class Frm(object):
     def __str__(self):
         return self.format % self.args
 
-# decorator for skipping tests on non-IEEE 754 platforms
-requires_IEEE_754 = unittest.skipUnless(
-    float.__getformat__("double").startswith("IEEE"),
-    "test requires IEEE 754 doubles")
-
 # SHIFT should match the value in longintrepr.h for best testing.
 SHIFT = sys.int_info.bits_per_digit
 BASE = 2 ** SHIFT
@@ -371,8 +367,7 @@ class LongTest(unittest.TestCase):
                 return 1729
         self.assertEqual(int(LongTrunc()), 1729)
 
-    @unittest.skipUnless(float.__getformat__("double").startswith("IEEE"),
-                         "test requires IEEE 754 doubles")
+    @support.requires_IEEE_754
     def test_float_conversion(self):
 
         exact_values = [0, 1, 2,
@@ -703,7 +698,7 @@ class LongTest(unittest.TestCase):
         self.assertEqual(expected, got, "Incorrectly rounded division {}/{}: "
                          "expected {}, got {}".format(a, b, expected, got))
 
-    @requires_IEEE_754
+    @support.requires_IEEE_754
     def test_correctly_rounded_true_division(self):
         # more stringent tests than those above, checking that the
         # result of true division of ints is always correctly rounded.