Skip to content

Commit b87c991

Browse files
authored
gh-149879: Fix test_math and test_statistics on Cygwin (#150432)
* Skip tests which fail on Cygwin: when Python is linked to the newlib C library. * Rename test_random() to test_fma_random(). * Move tests on large integer values from testLog2() to testLog2Exact().
1 parent f500e4e commit b87c991

3 files changed

Lines changed: 20 additions & 9 deletions

File tree

Lib/test/support/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2806,6 +2806,10 @@ def exceeds_recursion_limit():
28062806
is_s390x = hasattr(os, 'uname') and os.uname().machine == 's390x'
28072807
skip_on_s390x = unittest.skipIf(is_s390x, 'skipped on s390x')
28082808

2809+
# Cygwin uses the newlib C library
2810+
skip_on_newlib = unittest.skipIf(sys.platform == 'cygwin',
2811+
'the test fails on newlib C library')
2812+
28092813
Py_TRACE_REFS = hasattr(sys, 'getobjects')
28102814

28112815
_JIT_ENABLED = sys._jit.is_enabled()

Lib/test/test_math.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ def testHypot(self):
922922
@requires_IEEE_754
923923
@unittest.skipIf(HAVE_DOUBLE_ROUNDING,
924924
"hypot() loses accuracy on machines with double rounding")
925+
@support.skip_on_newlib
925926
def testHypotAccuracy(self):
926927
# Verify improved accuracy in cases that were known to be inaccurate.
927928
#
@@ -1253,12 +1254,6 @@ def testLog2(self):
12531254
self.assertEqual(math.log2(4), 2.0)
12541255
self.assertEqual(math.log2(MyIndexable(4)), 2.0)
12551256

1256-
# Large integer values
1257-
self.assertEqual(math.log2(2**1023), 1023.0)
1258-
self.assertEqual(math.log2(2**1024), 1024.0)
1259-
self.assertEqual(math.log2(2**2000), 2000.0)
1260-
self.assertEqual(math.log2(MyIndexable(2**2000)), 2000.0)
1261-
12621257
self.assertRaises(ValueError, math.log2, 0.0)
12631258
self.assertRaises(ValueError, math.log2, 0)
12641259
self.assertRaises(ValueError, math.log2, MyIndexable(0))
@@ -1276,12 +1271,19 @@ def testLog2(self):
12761271
@requires_IEEE_754
12771272
# log2() is not accurate enough on Mac OS X Tiger (10.4)
12781273
@support.requires_mac_ver(10, 5)
1274+
@support.skip_on_newlib
12791275
def testLog2Exact(self):
12801276
# Check that we get exact equality for log2 of powers of 2.
12811277
actual = [math.log2(math.ldexp(1.0, n)) for n in range(-1074, 1024)]
12821278
expected = [float(n) for n in range(-1074, 1024)]
12831279
self.assertEqual(actual, expected)
12841280

1281+
# Large integer values
1282+
self.assertEqual(math.log2(2**1023), 1023.0)
1283+
self.assertEqual(math.log2(2**1024), 1024.0)
1284+
self.assertEqual(math.log2(2**2000), 2000.0)
1285+
self.assertEqual(math.log2(MyIndexable(2**2000)), 2000.0)
1286+
12851287
def testLog10(self):
12861288
self.assertRaises(TypeError, math.log10)
12871289
self.ftest('log10(0.1)', math.log10(0.1), -1)
@@ -2615,6 +2617,7 @@ def test_fma_nan_results(self):
26152617
self.assertIsNaN(math.fma(a, math.nan, b))
26162618
self.assertIsNaN(math.fma(a, b, math.nan))
26172619

2620+
@support.skip_on_newlib
26182621
def test_fma_infinities(self):
26192622
# Cases involving infinite inputs or results.
26202623
positives = [1e-300, 2.3, 1e300, math.inf]
@@ -2685,7 +2688,7 @@ def test_fma_infinities(self):
26852688
# gh-73468: On some platforms, libc fma() doesn't implement IEE 754-2008
26862689
# properly: it doesn't use the right sign when the result is zero.
26872690
@unittest.skipIf(
2688-
sys.platform.startswith(("freebsd", "wasi", "netbsd", "emscripten"))
2691+
sys.platform.startswith(("freebsd", "wasi", "netbsd", "emscripten", "cygwin"))
26892692
or (sys.platform == "android" and platform.machine() == "x86_64")
26902693
or support.linked_to_musl(), # gh-131032
26912694
f"this platform doesn't implement IEE 754-2008 properly")
@@ -2743,6 +2746,7 @@ def test_fma_zero_result(self):
27432746
self.assertIsNegativeZero(math.fma(y-x, -(x+y), -z))
27442747
self.assertIsPositiveZero(math.fma(x-y, -(x+y), z))
27452748

2749+
@support.skip_on_newlib
27462750
def test_fma_overflow(self):
27472751
a = b = float.fromhex('0x1p512')
27482752
c = float.fromhex('0x1p1023')
@@ -2776,11 +2780,13 @@ def test_fma_overflow(self):
27762780
c = float.fromhex('0x1.fffffffffffffp+1023')
27772781
self.assertEqual(math.fma(a, b, -c), c)
27782782

2783+
@support.skip_on_newlib
27792784
def test_fma_single_round(self):
27802785
a = float.fromhex('0x1p-50')
27812786
self.assertEqual(math.fma(a - 1.0, a + 1.0, 1.0), a*a)
27822787

2783-
def test_random(self):
2788+
@support.skip_on_newlib
2789+
def test_fma_random(self):
27842790
# A collection of randomly generated inputs for which the naive FMA
27852791
# (with two rounds) gives a different result from a singly-rounded FMA.
27862792

Lib/test/test_statistics.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import sys
1717
import unittest
1818
from test import support
19-
from test.support import import_helper, requires_IEEE_754
19+
from test.support import import_helper, requires_IEEE_754, skip_on_newlib
2020

2121
from decimal import Decimal
2222
from fractions import Fraction
@@ -2799,6 +2799,7 @@ def test_sqrtprod_helper_function_fundamentals(self):
27992799
@unittest.skipIf(HAVE_DOUBLE_ROUNDING,
28002800
"accuracy not guaranteed on machines with double rounding")
28012801
@support.cpython_only # Allow for a weaker sumprod() implementation
2802+
@skip_on_newlib
28022803
def test_sqrtprod_helper_function_improved_accuracy(self):
28032804
# Test a known example where accuracy is improved
28042805
x, y, target = 0.8035720646477457, 0.7957468097636939, 0.7996498651651661

0 commit comments

Comments
 (0)