]> granicus.if.org Git - python/commitdiff
test_formatdate(): A test for email.Utils.formatdate().
authorBarry Warsaw <barry@python.org>
Fri, 9 Nov 2001 17:46:17 +0000 (17:46 +0000)
committerBarry Warsaw <barry@python.org>
Fri, 9 Nov 2001 17:46:17 +0000 (17:46 +0000)
Lib/test/test_email.py

index d397c091ac564998ab9937102d89e0bf58bd397e..1e065e4ef4809765387f59278319fa3e4591dec6 100644 (file)
@@ -919,6 +919,22 @@ class TestMiscellaneous(unittest.TestCase):
                                'Utils',
                                'message_from_file', 'message_from_string'])
 
+    def test_formatdate(self):
+        now = 1005327232.109884
+        gdate = Utils.formatdate(now)
+        ldate = Utils.formatdate(now, localtime=1)
+        self.assertEqual(gdate, 'Fri, 09 Nov 2001 17:33:52 -0000')
+        # It's a little tougher to test for localtime, but we'll try
+        gtime = time.strptime(gdate.split()[4], '%H:%M:%S')
+        ltime = time.strptime(ldate.split()[4], '%H:%M:%S')
+        zone = ldate.split()[5]
+        offset = int(zone[:3]) * -3600 + int(zone[-2:])
+        if time.daylight and time.localtime(now)[-1]:
+            toff = time.altzone
+        else:
+            toff = time.timezone
+        self.assertEqual(offset, toff)
+
 
 \f
 # Test the iterator/generators