summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_time.py
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2001-05-22 17:02:02 (GMT)
committerFred Drake <fdrake@acm.org>2001-05-22 17:02:02 (GMT)
commitbc5619826e6c84d68f73df02d712302b9f25a924 (patch)
tree79d438e82cb5e4f54ccf41974558f79c868ccb87 /Lib/test/test_time.py
parent5b021848ac728b9815d6c5c5b9622d3956665bbb (diff)
downloadcpython-bc5619826e6c84d68f73df02d712302b9f25a924.zip
cpython-bc5619826e6c84d68f73df02d712302b9f25a924.tar.gz
cpython-bc5619826e6c84d68f73df02d712302b9f25a924.tar.bz2
Convert time module tests to PyUnit.
Diffstat (limited to 'Lib/test/test_time.py')
-rw-r--r--Lib/test/test_time.py86
1 files changed, 49 insertions, 37 deletions
diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py
index ebe8fa7..160ce4d 100644
--- a/Lib/test/test_time.py
+++ b/Lib/test/test_time.py
@@ -1,39 +1,51 @@
+import test_support
import time
+import unittest
-time.altzone
-time.clock()
-t = time.time()
-time.asctime(time.gmtime(t))
-if time.ctime(t) != time.asctime(time.localtime(t)):
- print 'time.ctime(t) != time.asctime(time.localtime(t))'
-
-time.daylight
-if long(time.mktime(time.localtime(t))) != long(t):
- print 'time.mktime(time.localtime(t)) != t'
-
-time.sleep(1.2)
-tt = time.gmtime(t)
-for directive in ('a', 'A', 'b', 'B', 'c', 'd', 'H', 'I',
- 'j', 'm', 'M', 'p', 'S',
- 'U', 'w', 'W', 'x', 'X', 'y', 'Y', 'Z', '%'):
- format = ' %' + directive
- try:
- time.strftime(format, tt)
- except ValueError:
- print 'conversion specifier:', format, ' failed.'
-
-time.timezone
-time.tzname
-
-# expected errors
-try:
- time.asctime(0)
-except TypeError:
- pass
-
-try:
- time.mktime((999999, 999999, 999999, 999999,
- 999999, 999999, 999999, 999999,
- 999999))
-except OverflowError:
- pass
+
+class TimeTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.t = time.time()
+
+ def test_data_attributes(self):
+ time.altzone
+ time.daylight
+ time.timezone
+ time.tzname
+
+ def test_clock(self):
+ time.clock()
+
+ def test_conversions(self):
+ self.assert_(time.ctime(self.t)
+ == time.asctime(time.localtime(self.t)))
+ self.assert_(long(time.mktime(time.localtime(self.t)))
+ == long(self.t))
+
+ def test_sleep(self):
+ time.sleep(1.2)
+
+ def test_strftime(self):
+ tt = time.gmtime(self.t)
+ for directive in ('a', 'A', 'b', 'B', 'c', 'd', 'H', 'I',
+ 'j', 'm', 'M', 'p', 'S',
+ 'U', 'w', 'W', 'x', 'X', 'y', 'Y', 'Z', '%'):
+ format = ' %' + directive
+ try:
+ time.strftime(format, tt)
+ except ValueError:
+ self.fail('conversion specifier: %r failed.' % format)
+
+ def test_asctime(self):
+ time.asctime(time.gmtime(self.t))
+ self.assertRaises(TypeError, time.asctime, 0)
+
+ def test_mktime(self):
+ self.assertRaises(OverflowError,
+ time.mktime, (999999, 999999, 999999, 999999,
+ 999999, 999999, 999999, 999999,
+ 999999))
+
+
+test_support.run_unittest(TimeTestCase)