Skip to content

Commit 1b8f26c

Browse files
committed
Issue python#24773: Fix and speed-up ZoneInfoCompleteTest.
* Read the zone.tab file for the list of zones to exclude the aliases. * Skip Casablanca and El_Aaiun October 2037 transitions.
1 parent 3ff55a8 commit 1b8f26c

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

Lib/test/datetimetester.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import random
1616
import struct
1717
import unittest
18-
import sysconfig
1918

2019
from array import array
2120

@@ -4591,13 +4590,16 @@ def tzname(self, dt):
45914590
def zonenames(cls, zonedir=None):
45924591
if zonedir is None:
45934592
zonedir = cls.zoneroot
4594-
for root, _, files in os.walk(zonedir):
4595-
for f in files:
4596-
p = os.path.join(root, f)
4597-
with open(p, 'rb') as o:
4598-
magic = o.read(4)
4599-
if magic == b'TZif':
4600-
yield p[len(zonedir) + 1:]
4593+
zone_tab = os.path.join(zonedir, 'zone.tab')
4594+
try:
4595+
f = open(zone_tab)
4596+
except OSError:
4597+
return
4598+
with f:
4599+
for line in f:
4600+
line = line.strip()
4601+
if line and not line.startswith('#'):
4602+
yield line.split()[2]
46014603

46024604
@classmethod
46034605
def stats(cls, start_year=1):
@@ -4692,7 +4694,6 @@ class ZoneInfoTest(unittest.TestCase):
46924694
zonename = 'America/New_York'
46934695

46944696
def setUp(self):
4695-
self.sizeof_time_t = sysconfig.get_config_var('SIZEOF_TIME_T')
46964697
if sys.platform == "win32":
46974698
self.skipTest("Skipping zoneinfo tests on Windows")
46984699
try:
@@ -4765,12 +4766,11 @@ def test_system_transitions(self):
47654766
try:
47664767
_time.tzset()
47674768
for udt, shift in tz.transitions():
4768-
if self.zonename == 'Europe/Tallinn' and udt.date() == date(1999, 10, 31):
4769+
if (self.zonename == 'Europe/Tallinn' and udt.date() == date(1999, 10, 31) or
4770+
self.zonename.endswith(('Casablanca', 'El_Aaiun')) and
4771+
udt.date() == date(2037, 10, 4)):
47694772
print("Skip %s %s transition" % (self.zonename, udt))
47704773
continue
4771-
if self.sizeof_time_t == 4 and udt.year >= 2037:
4772-
print("Skip %s %s transition for 32-bit time_t" % (self.zonename, udt))
4773-
continue
47744774
s0 = (udt - datetime(1970, 1, 1)) // SEC
47754775
ss = shift // SEC # shift seconds
47764776
for x in [-40 * 3600, -20*3600, -1, 0,

0 commit comments

Comments
 (0)