Issue #10624: Use support.requires_IEEE_754 in all appropriate tests.
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index e91eb67..48e5095 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -38,11 +38,6 @@
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 @@
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 @@
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)
diff --git a/Lib/test/test_cmath.py b/Lib/test/test_cmath.py
index 168b513..4e93be4 100644
--- a/Lib/test/test_cmath.py
+++ b/Lib/test/test_cmath.py
@@ -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 @@
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 @@
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
diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py
index 548726b..f9bed06 100644
--- a/Lib/test/test_complex.py
+++ b/Lib/test/test_complex.py
@@ -435,15 +435,14 @@
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.))
+ @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.))
- @unittest.skipUnless(float.__getformat__("double").startswith("IEEE"),
- "test requires IEEE 754 doubles")
+ @support.requires_IEEE_754
def test_negated_imaginary_literal(self):
z0 = -0j
z1 = -7j
@@ -459,15 +458,13 @@
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]
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py
index 3036170..8f1f863 100644
--- a/Lib/test/test_decimal.py
+++ b/Lib/test/test_decimal.py
@@ -32,7 +32,8 @@
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 @@
)
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]
diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py
index ddf93bc..30cb4b9 100644
--- a/Lib/test/test_float.py
+++ b/Lib/test/test_float.py
@@ -16,10 +16,6 @@
"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 @@
# 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 @@
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 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 @@
('<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 @@
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 @@
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):
diff --git a/Lib/test/test_fractions.py b/Lib/test/test_fractions.py
index a63ee89..26e132f 100644
--- a/Lib/test/test_fractions.py
+++ b/Lib/test/test_fractions.py
@@ -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 @@
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"""
diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py
index 12197ee..04066ec 100644
--- a/Lib/test/test_long.py
+++ b/Lib/test/test_long.py
@@ -1,5 +1,6 @@
import unittest
from test import support
+
import sys
import random
@@ -15,11 +16,6 @@
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 @@
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 @@
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.