(original) (raw)
import time import unittest class PatchTest(unittest.TestCase): # Check for problems with tm_gmtoff field in struct time. These # can bite us on BSD-derived libc's. The primary (only?) symptom # is to break the strftime %z format. def test_tm_gtmoff1(self): # The %z format is not guaranteed to be supported by the libc # strftime(), but strftime(fmt) is documented to work the same # as strftime(fmt, localtime()) in all cases. self.failUnlessEqual(time.strftime('%z'), time.strftime('%z', time.localtime())) def test_tm_gmtoff2(self): # The %z format is not guarranteed to be supported by the libc # strftime(), but if it is US Eastern timezone should never # return +0. if not hasattr(time, "tzset"): return # Can't test this; don't want the test suite to fail from os import environ eastern = 'EST+05EDT,M4.1.0,M10.5.0' org_TZ = environ.get('TZ',None) try: environ['TZ'] = eastern time.tzset() self.failIfEqual(time.strftime('%z', time.localtime()), '+0000') finally: # Repair TZ environment variable in case any other tests # rely on it. if org_TZ is not None: environ['TZ'] = org_TZ elif environ.has_key('TZ'): del environ['TZ'] time.tzset() if __name__ == "__main__": unittest.main()