]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-149879: Fix test_math and test_statistics on Cygwin (#150432)
authorVictor Stinner <vstinner@python.org>
Tue, 26 May 2026 02:39:22 +0000 (04:39 +0200)
committerGitHub <noreply@github.com>
Tue, 26 May 2026 02:39:22 +0000 (02:39 +0000)
* 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().

Lib/test/support/__init__.py
Lib/test/test_math.py
Lib/test/test_statistics.py

index 87082ff37d1e58df53e89ce98b1d5b09119a228c..62804e2fa2d68e905d043703dabe982400af3157 100644 (file)
@@ -2806,6 +2806,10 @@ def exceeds_recursion_limit():
 is_s390x = hasattr(os, 'uname') and os.uname().machine == 's390x'
 skip_on_s390x = unittest.skipIf(is_s390x, 'skipped on s390x')
 
+# Cygwin uses the newlib C library
+skip_on_newlib = unittest.skipIf(sys.platform == 'cygwin',
+                                 'the test fails on newlib C library')
+
 Py_TRACE_REFS = hasattr(sys, 'getobjects')
 
 _JIT_ENABLED = sys._jit.is_enabled()
index 8f9a239bead13096de7a0196e9bc7b833d152862..7c40f9f94c37ad9df1af7cba722978d4eaa3610c 100644 (file)
@@ -922,6 +922,7 @@ class MathTests(unittest.TestCase):
     @requires_IEEE_754
     @unittest.skipIf(HAVE_DOUBLE_ROUNDING,
                      "hypot() loses accuracy on machines with double rounding")
+    @support.skip_on_newlib
     def testHypotAccuracy(self):
         # Verify improved accuracy in cases that were known to be inaccurate.
         #
@@ -1253,12 +1254,6 @@ class MathTests(unittest.TestCase):
         self.assertEqual(math.log2(4), 2.0)
         self.assertEqual(math.log2(MyIndexable(4)), 2.0)
 
-        # Large integer values
-        self.assertEqual(math.log2(2**1023), 1023.0)
-        self.assertEqual(math.log2(2**1024), 1024.0)
-        self.assertEqual(math.log2(2**2000), 2000.0)
-        self.assertEqual(math.log2(MyIndexable(2**2000)), 2000.0)
-
         self.assertRaises(ValueError, math.log2, 0.0)
         self.assertRaises(ValueError, math.log2, 0)
         self.assertRaises(ValueError, math.log2, MyIndexable(0))
@@ -1276,12 +1271,19 @@ class MathTests(unittest.TestCase):
     @requires_IEEE_754
     # log2() is not accurate enough on Mac OS X Tiger (10.4)
     @support.requires_mac_ver(10, 5)
+    @support.skip_on_newlib
     def testLog2Exact(self):
         # Check that we get exact equality for log2 of powers of 2.
         actual = [math.log2(math.ldexp(1.0, n)) for n in range(-1074, 1024)]
         expected = [float(n) for n in range(-1074, 1024)]
         self.assertEqual(actual, expected)
 
+        # Large integer values
+        self.assertEqual(math.log2(2**1023), 1023.0)
+        self.assertEqual(math.log2(2**1024), 1024.0)
+        self.assertEqual(math.log2(2**2000), 2000.0)
+        self.assertEqual(math.log2(MyIndexable(2**2000)), 2000.0)
+
     def testLog10(self):
         self.assertRaises(TypeError, math.log10)
         self.ftest('log10(0.1)', math.log10(0.1), -1)
@@ -2615,6 +2617,7 @@ class FMATests(unittest.TestCase):
                 self.assertIsNaN(math.fma(a, math.nan, b))
                 self.assertIsNaN(math.fma(a, b, math.nan))
 
+    @support.skip_on_newlib
     def test_fma_infinities(self):
         # Cases involving infinite inputs or results.
         positives = [1e-300, 2.3, 1e300, math.inf]
@@ -2685,7 +2688,7 @@ class FMATests(unittest.TestCase):
     # gh-73468: On some platforms, libc fma() doesn't implement IEE 754-2008
     # properly: it doesn't use the right sign when the result is zero.
     @unittest.skipIf(
-        sys.platform.startswith(("freebsd", "wasi", "netbsd", "emscripten"))
+        sys.platform.startswith(("freebsd", "wasi", "netbsd", "emscripten", "cygwin"))
         or (sys.platform == "android" and platform.machine() == "x86_64")
         or support.linked_to_musl(),  # gh-131032
         f"this platform doesn't implement IEE 754-2008 properly")
@@ -2743,6 +2746,7 @@ class FMATests(unittest.TestCase):
         self.assertIsNegativeZero(math.fma(y-x, -(x+y), -z))
         self.assertIsPositiveZero(math.fma(x-y, -(x+y), z))
 
+    @support.skip_on_newlib
     def test_fma_overflow(self):
         a = b = float.fromhex('0x1p512')
         c = float.fromhex('0x1p1023')
@@ -2776,11 +2780,13 @@ class FMATests(unittest.TestCase):
         c = float.fromhex('0x1.fffffffffffffp+1023')
         self.assertEqual(math.fma(a, b, -c), c)
 
+    @support.skip_on_newlib
     def test_fma_single_round(self):
         a = float.fromhex('0x1p-50')
         self.assertEqual(math.fma(a - 1.0, a + 1.0, 1.0), a*a)
 
-    def test_random(self):
+    @support.skip_on_newlib
+    def test_fma_random(self):
         # A collection of randomly generated inputs for which the naive FMA
         # (with two rounds) gives a different result from a singly-rounded FMA.
 
index 677a87b51b919257ac26acee5a01935b44a9eda2..de7d13651cfea62604109b6683bef9e4ada4eafe 100644 (file)
@@ -16,7 +16,7 @@ import random
 import sys
 import unittest
 from test import support
-from test.support import import_helper, requires_IEEE_754
+from test.support import import_helper, requires_IEEE_754, skip_on_newlib
 
 from decimal import Decimal
 from fractions import Fraction
@@ -2799,6 +2799,7 @@ class TestCorrelationAndCovariance(unittest.TestCase):
     @unittest.skipIf(HAVE_DOUBLE_ROUNDING,
                      "accuracy not guaranteed on machines with double rounding")
     @support.cpython_only    # Allow for a weaker sumprod() implementation
+    @skip_on_newlib
     def test_sqrtprod_helper_function_improved_accuracy(self):
         # Test a known example where accuracy is improved
         x, y, target = 0.8035720646477457, 0.7957468097636939, 0.7996498651651661