]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-80620: Fix test_time.test_gmtime() for 32-bit time_t (#143861)
authorVictor Stinner <vstinner@python.org>
Thu, 15 Jan 2026 10:54:30 +0000 (11:54 +0100)
committerGitHub <noreply@github.com>
Thu, 15 Jan 2026 10:54:30 +0000 (11:54 +0100)
Lib/test/test_time.py

index ce13f3a22f3ae5bd21c7f1af97164c100615d411..c360f4a64c266b28ae1c8e3127377591d2ba2b07 100644 (file)
@@ -192,18 +192,29 @@ class TimeTestCase(unittest.TestCase):
         # (tm_year, tm_mon, tm_mday,
         #  tm_hour, tm_min, tm_sec,
         #  tm_wday, tm_yday)
-        for t, expected in (
+        tests = [
             (-13262400, (1969, 7, 31, 12, 0, 0, 3, 212)),
             (-6177600, (1969, 10, 21, 12, 0, 0, 1, 294)),
-            # non-leap years (pre epoch)
-            (-2203891200, (1900, 3, 1, 0, 0, 0, 3, 60)),
-            (-2203977600, (1900, 2, 28, 0, 0, 0, 2, 59)),
-            (-5359564800, (1800, 3, 1, 0, 0, 0, 5, 60)),
-            (-5359651200, (1800, 2, 28, 0, 0, 0, 4, 59)),
             # leap years (pre epoch)
             (-2077660800, (1904, 3, 1, 0, 0, 0, 1, 61)),
             (-2077833600, (1904, 2, 28, 0, 0, 0, 6, 59)),
-        ):
+        ]
+
+        try:
+            from _testinternalcapi import SIZEOF_TIME_T
+        except ImportError:
+            pass
+        else:
+            if SIZEOF_TIME_T >= 8:
+                tests.extend((
+                    # non-leap years (pre epoch)
+                    (-2203891200, (1900, 3, 1, 0, 0, 0, 3, 60)),
+                    (-2203977600, (1900, 2, 28, 0, 0, 0, 2, 59)),
+                    (-5359564800, (1800, 3, 1, 0, 0, 0, 5, 60)),
+                    (-5359651200, (1800, 2, 28, 0, 0, 0, 4, 59)),
+                ))
+
+        for t, expected in tests:
             with self.subTest(t=t, expected=expected):
                 res = time.gmtime(t)
                 self.assertEqual(tuple(res)[:8], expected, res)