From: Victor Stinner Date: Thu, 15 Jan 2026 10:54:30 +0000 (+0100) Subject: gh-80620: Fix test_time.test_gmtime() for 32-bit time_t (#143861) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1597d00d96057aaad82dc201d493044b609df42b;p=thirdparty%2FPython%2Fcpython.git gh-80620: Fix test_time.test_gmtime() for 32-bit time_t (#143861) --- diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py index ce13f3a22f3a..c360f4a64c26 100644 --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -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)