Skip to content

Commit 6ca94a6

Browse files
committed
add instead the skip_if_have_double_rounding decorator
1 parent dfdb76b commit 6ca94a6

4 files changed

Lines changed: 18 additions & 19 deletions

File tree

Lib/test/support/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"run_no_yield_async_fn", "run_yielding_async_fn", "async_yield",
7474
"reset_code", "on_github_actions",
7575
"requires_root_user", "requires_non_root_user",
76-
"HAVE_DOUBLE_ROUNDING",
76+
"skip_if_have_double_rounding",
7777
]
7878

7979

@@ -525,10 +525,13 @@ def dec(*args, **kwargs):
525525
float.__getformat__("double").startswith("IEEE"),
526526
"test requires IEEE 754 doubles")
527527

528-
# detect evidence of double-rounding: fsum is not always correctly
529-
# rounded on machines that suffer from double rounding.
528+
# detect evidence of double-rounding:
530529
x, y = 1e16, 2.9999 # use temporary values to defeat peephole optimizer
531-
HAVE_DOUBLE_ROUNDING = (x + y == 1e16 + 4)
530+
skip_if_have_double_rounding = unittest.skipIf(x + y == 1e16 + 4,
531+
("accuracy not guaranteed on "
532+
"machines with double "
533+
"rounding"))
534+
532535

533536
def requires_zlib(reason='requires zlib'):
534537
try:

Lib/test/test_builtin.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from test.support.script_helper import assert_python_ok
4040
from test.support.testcase import ComplexesAreIdenticalMixin
4141
from test.support.warnings_helper import check_warnings
42-
from test.support import HAVE_DOUBLE_ROUNDING, requires_IEEE_754
42+
from test.support import requires_IEEE_754, skip_if_have_double_rounding
4343
from unittest.mock import MagicMock, patch
4444
try:
4545
import pty, signal
@@ -2230,8 +2230,7 @@ def __getitem__(self, index):
22302230
complex(2, -0.0))
22312231

22322232
@requires_IEEE_754
2233-
@unittest.skipIf(HAVE_DOUBLE_ROUNDING,
2234-
"sum accuracy not guaranteed on machines with double rounding")
2233+
@skip_if_have_double_rounding
22352234
@support.cpython_only # Other implementations may choose a different algorithm
22362235
def test_sum_accuracy(self):
22372236
self.assertEqual(sum([0.1] * 10), 1.0)

Lib/test/test_math.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Python test set -- math module
22
# XXXX Should not do tests around zero only
33

4-
from test.support import HAVE_DOUBLE_ROUNDING, verbose, requires_IEEE_754
4+
from test.support import (verbose, requires_IEEE_754,
5+
skip_if_have_double_rounding)
56
from test import support
67
import unittest
78
import fractions
@@ -678,8 +679,7 @@ def testfrexp(name, result, expected):
678679
self.assertTrue(math.isnan(math.frexp(NAN)[0]))
679680

680681
@requires_IEEE_754
681-
@unittest.skipIf(HAVE_DOUBLE_ROUNDING,
682-
"fsum is not exact on machines with double rounding")
682+
@skip_if_have_double_rounding
683683
def testFsum(self):
684684
# math.fsum relies on exact rounding for correct operation.
685685
# There's a known problem with IA32 floating-point that causes
@@ -915,8 +915,7 @@ def testHypot(self):
915915
self.assertRaises(TypeError, math.hypot, *([1.0]*18), 'spam')
916916

917917
@requires_IEEE_754
918-
@unittest.skipIf(HAVE_DOUBLE_ROUNDING,
919-
"hypot() loses accuracy on machines with double rounding")
918+
@skip_if_have_double_rounding
920919
def testHypotAccuracy(self):
921920
# Verify improved accuracy in cases that were known to be inaccurate.
922921
#
@@ -1405,8 +1404,7 @@ def __rmul__(self, other):
14051404
self.assertEqual(sumprod(*args), 0.0)
14061405

14071406
@requires_IEEE_754
1408-
@unittest.skipIf(HAVE_DOUBLE_ROUNDING,
1409-
"sumprod() accuracy not guaranteed on machines with double rounding")
1407+
@skip_if_have_double_rounding
14101408
@support.cpython_only # Other implementations may choose a different algorithm
14111409
def test_sumprod_accuracy(self):
14121410
sumprod = math.sumprod
@@ -1491,8 +1489,7 @@ def run(func, *args):
14911489
)
14921490

14931491
@requires_IEEE_754
1494-
@unittest.skipIf(HAVE_DOUBLE_ROUNDING,
1495-
"sumprod() accuracy not guaranteed on machines with double rounding")
1492+
@skip_if_have_double_rounding
14961493
@support.cpython_only # Other implementations may choose a different algorithm
14971494
@support.requires_resource('cpu')
14981495
def test_sumprod_extended_precision_accuracy(self):

Lib/test/test_statistics.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
import sys
1717
import unittest
1818
from test import support
19-
from test.support import HAVE_DOUBLE_ROUNDING, import_helper, requires_IEEE_754
19+
from test.support import (import_helper, requires_IEEE_754,
20+
skip_if_have_double_rounding)
2021

2122
from decimal import Decimal
2223
from fractions import Fraction
@@ -2790,8 +2791,7 @@ def test_sqrtprod_helper_function_fundamentals(self):
27902791
self.assertEqual(sign(actual), sign(expected))
27912792

27922793
@requires_IEEE_754
2793-
@unittest.skipIf(HAVE_DOUBLE_ROUNDING,
2794-
"accuracy not guaranteed on machines with double rounding")
2794+
@skip_if_have_double_rounding
27952795
@support.cpython_only # Allow for a weaker sumprod() implementation
27962796
def test_sqrtprod_helper_function_improved_accuracy(self):
27972797
# Test a known example where accuracy is improved

0 commit comments

Comments
 (0)