blob: b2a3a2878804f074cd17794adc682f0e3c5486bd [file] [log] [blame]
Fred Drakebc561982001-05-22 17:02:02 +00001import test_support
Barry Warsawb0c22321996-12-06 23:30:07 +00002import time
Fred Drakebc561982001-05-22 17:02:02 +00003import unittest
Barry Warsawb0c22321996-12-06 23:30:07 +00004
Barry Warsawb0c22321996-12-06 23:30:07 +00005
Fred Drakebc561982001-05-22 17:02:02 +00006class TimeTestCase(unittest.TestCase):
Barry Warsawb0c22321996-12-06 23:30:07 +00007
Fred Drakebc561982001-05-22 17:02:02 +00008 def setUp(self):
9 self.t = time.time()
Barry Warsawb0c22321996-12-06 23:30:07 +000010
Fred Drakebc561982001-05-22 17:02:02 +000011 def test_data_attributes(self):
12 time.altzone
13 time.daylight
14 time.timezone
15 time.tzname
Barry Warsawb0c22321996-12-06 23:30:07 +000016
Fred Drakebc561982001-05-22 17:02:02 +000017 def test_clock(self):
18 time.clock()
Barry Warsawb0c22321996-12-06 23:30:07 +000019
Fred Drakebc561982001-05-22 17:02:02 +000020 def test_conversions(self):
21 self.assert_(time.ctime(self.t)
22 == time.asctime(time.localtime(self.t)))
23 self.assert_(long(time.mktime(time.localtime(self.t)))
24 == long(self.t))
25
26 def test_sleep(self):
27 time.sleep(1.2)
28
29 def test_strftime(self):
30 tt = time.gmtime(self.t)
31 for directive in ('a', 'A', 'b', 'B', 'c', 'd', 'H', 'I',
32 'j', 'm', 'M', 'p', 'S',
33 'U', 'w', 'W', 'x', 'X', 'y', 'Y', 'Z', '%'):
34 format = ' %' + directive
35 try:
36 time.strftime(format, tt)
37 except ValueError:
38 self.fail('conversion specifier: %r failed.' % format)
39
40 def test_asctime(self):
41 time.asctime(time.gmtime(self.t))
42 self.assertRaises(TypeError, time.asctime, 0)
43
44 def test_mktime(self):
45 self.assertRaises(OverflowError,
46 time.mktime, (999999, 999999, 999999, 999999,
47 999999, 999999, 999999, 999999,
48 999999))
49
50
Fred Drake2e2be372001-09-20 21:33:42 +000051def test_main():
52 test_support.run_unittest(TimeTestCase)
53
54
55if __name__ == "__main__":
56 test_main()