Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 75a40fc

Browse files
committed
test_formatdate(), test_formatdate_zoneoffsets(): Two changes. First,
use the correct way to test for epoch, by looking at the year component of gmtime(0). Add clause for Unix epoch and Mac epoch (Tim, what is Windows epoch?). Also, get rid of the strptime() test, it was way too problematic given that strptime() is missing on many platforms and issues with locales. Instead, simply test that formatdate() gets the numeric timezone calculation correct for the altzone and timezone.
1 parent cd45a36 commit 75a40fc

1 file changed

Lines changed: 16 additions & 17 deletions

File tree

Lib/test/test_email.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -921,33 +921,32 @@ def test__all__(self):
921921

922922
def test_formatdate(self):
923923
now = 1005327232.109884
924-
time0 = time.ctime(0)
924+
epoch = time.gmtime(0)[0]
925925
# When does the epoch start?
926-
if time0 == 'Wed Dec 31 19:00:00 1969':
926+
if epoch == 1970:
927927
# traditional Unix epoch
928928
matchdate = 'Fri, 09 Nov 2001 17:33:52 -0000'
929-
elif time0 == 'Fri Jan 1 00:00:00 1904':
929+
elif epoch == 1904:
930930
# Mac epoch
931931
matchdate = 'Sat, 09 Nov 1935 16:33:52 -0000'
932932
else:
933933
matchdate = "I don't understand your epoch"
934934
gdate = Utils.formatdate(now)
935935
ldate = Utils.formatdate(now, localtime=1)
936936
self.assertEqual(gdate, matchdate)
937-
# It's a little tougher to test for localtime, but we'll try. Skip if
938-
# we don't have strptime().
939-
if hasattr(time, 'strptime'):
940-
gtime = time.strptime(gdate.split()[4], '%H:%M:%S')
941-
ltime = time.strptime(ldate.split()[4], '%H:%M:%S')
942-
zone = ldate.split()[5]
943-
offset = int(zone[:3]) * -3600 + int(zone[-2:])
944-
if time.daylight and time.localtime(now)[-1]:
945-
toff = time.altzone
946-
else:
947-
toff = time.timezone
948-
self.assertEqual(offset, toff)
949-
950-
def test_parsedate(self):
937+
938+
def test_formatdate_zoneoffsets(self):
939+
now = 1005327232.109884
940+
ldate = Utils.formatdate(now, localtime=1)
941+
zone = ldate.split()[5]
942+
offset = int(zone[:3]) * -3600 + int(zone[-2:]) * -60
943+
if time.daylight and time.localtime(now)[-1]:
944+
toff = time.altzone
945+
else:
946+
toff = time.timezone
947+
self.assertEqual(offset, toff)
948+
949+
def test_parsedate_none(self):
951950
self.assertEqual(Utils.parsedate(''), None)
952951

953952

0 commit comments

Comments
 (0)