Fred Drake | bc56198 | 2001-05-22 17:02:02 +0000 | [diff] [blame] | 1 | import test_support |
Barry Warsaw | b0c2232 | 1996-12-06 23:30:07 +0000 | [diff] [blame] | 2 | import time |
Fred Drake | bc56198 | 2001-05-22 17:02:02 +0000 | [diff] [blame] | 3 | import unittest |
Barry Warsaw | b0c2232 | 1996-12-06 23:30:07 +0000 | [diff] [blame] | 4 | |
Barry Warsaw | b0c2232 | 1996-12-06 23:30:07 +0000 | [diff] [blame] | 5 | |
Fred Drake | bc56198 | 2001-05-22 17:02:02 +0000 | [diff] [blame] | 6 | class TimeTestCase(unittest.TestCase): |
Barry Warsaw | b0c2232 | 1996-12-06 23:30:07 +0000 | [diff] [blame] | 7 | |
Fred Drake | bc56198 | 2001-05-22 17:02:02 +0000 | [diff] [blame] | 8 | def setUp(self): |
| 9 | self.t = time.time() |
Barry Warsaw | b0c2232 | 1996-12-06 23:30:07 +0000 | [diff] [blame] | 10 | |
Fred Drake | bc56198 | 2001-05-22 17:02:02 +0000 | [diff] [blame] | 11 | def test_data_attributes(self): |
| 12 | time.altzone |
| 13 | time.daylight |
| 14 | time.timezone |
| 15 | time.tzname |
Barry Warsaw | b0c2232 | 1996-12-06 23:30:07 +0000 | [diff] [blame] | 16 | |
Fred Drake | bc56198 | 2001-05-22 17:02:02 +0000 | [diff] [blame] | 17 | def test_clock(self): |
| 18 | time.clock() |
Barry Warsaw | b0c2232 | 1996-12-06 23:30:07 +0000 | [diff] [blame] | 19 | |
Fred Drake | bc56198 | 2001-05-22 17:02:02 +0000 | [diff] [blame] | 20 | 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 Drake | 2e2be37 | 2001-09-20 21:33:42 +0000 | [diff] [blame^] | 51 | def test_main(): |
| 52 | test_support.run_unittest(TimeTestCase) |
| 53 | |
| 54 | |
| 55 | if __name__ == "__main__": |
| 56 | test_main() |