forked from garrickp/tzinfo_py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_zoneinfo.py
executable file
·62 lines (46 loc) · 2.03 KB
/
test_zoneinfo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#! /usr/bin/env python
"""
Tests the generated zoneinfo module.
"""
from datetime import datetime, timedelta, time
import unittest
import zoneinfo
class TestZoneinfo(unittest.TestCase):
def test_general_functionality(self):
"""
Make sure the basic functions (through datetime) don't throw exceptions
for all of the timzeones.
"""
for _, tz in zoneinfo.timezones.items():
now = datetime.now(tz)
now.utcoffset()
now.dst()
now.strftime("%H:%M:%S %Z")
def test_mst_mdt(self):
mst = zoneinfo.timezones['US/Mountain']
pst = zoneinfo.timezones['US/Pacific']
dt = datetime(2011, 7, 4, 0, 0, tzinfo=mst)
self.assertEqual(dt.utcoffset(), timedelta(hours=-8))
self.assert_("MDT" in dt.strftime("%Y %M %D %h:%m %Z"), "'MDT' not in %r" % (dt.strftime("%Y %M %D %h:%m %Z"),))
dtp = dt.astimezone(pst)
adjusted_mt = dt - timedelta(hours=1)
self.assertEqual(adjusted_mt.timetuple(), dtp.timetuple())
dt = datetime(2011, 1, 4, 0, 0, tzinfo=mst)
self.assertEqual(dt.utcoffset(), timedelta(hours=-7))
self.assert_("MST" in dt.strftime("%Y %M %D %h:%m %Z"), "'MST' not in %r" % (dt.strftime("%Y %M %D %h:%m %Z"),))
def test_time(self):
mst = zoneinfo.timezones['US/Mountain']
t = time(20, 35, tzinfo=mst)
self.assert_('-07:00' in t.isoformat() or '-08:00' in t.isoformat())
def test_historical_sample(self):
ab = zoneinfo.timezones['Asia/Baku']
dt = datetime(1991, 8, 30, 12, 0, tzinfo=ab)
self.assertEqual(dt.utcoffset(), timedelta(hours=2))
vi = zoneinfo.timezones['America/Indiana/Vincennes']
dt = datetime(1955, 6, 1, 12, 0, tzinfo=vi)
self.assertEqual(dt.utcoffset(), timedelta(hours=-7))
ad = zoneinfo.timezones['Australia/Darwin']
dt = datetime(1872, 1, 1, 12, 0, tzinfo=ad)
self.assertEqual(dt.utcoffset(), timedelta(hours=8, minutes=43))
if __name__ == "__main__":
unittest.main()