Convert time module tests to PyUnit.

This commit is contained in:
Fred Drake 2001-05-22 17:02:02 +00:00
parent 5b021848ac
commit bc5619826e

View file

@ -1,18 +1,33 @@
import test_support
import time import time
import unittest
class TimeTestCase(unittest.TestCase):
def setUp(self):
self.t = time.time()
def test_data_attributes(self):
time.altzone 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 time.daylight
if long(time.mktime(time.localtime(t))) != long(t): time.timezone
print 'time.mktime(time.localtime(t)) != t' 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) time.sleep(1.2)
tt = time.gmtime(t)
def test_strftime(self):
tt = time.gmtime(self.t)
for directive in ('a', 'A', 'b', 'B', 'c', 'd', 'H', 'I', for directive in ('a', 'A', 'b', 'B', 'c', 'd', 'H', 'I',
'j', 'm', 'M', 'p', 'S', 'j', 'm', 'M', 'p', 'S',
'U', 'w', 'W', 'x', 'X', 'y', 'Y', 'Z', '%'): 'U', 'w', 'W', 'x', 'X', 'y', 'Y', 'Z', '%'):
@ -20,20 +35,17 @@ for directive in ('a', 'A', 'b', 'B', 'c', 'd', 'H', 'I',
try: try:
time.strftime(format, tt) time.strftime(format, tt)
except ValueError: except ValueError:
print 'conversion specifier:', format, ' failed.' self.fail('conversion specifier: %r failed.' % format)
time.timezone def test_asctime(self):
time.tzname time.asctime(time.gmtime(self.t))
self.assertRaises(TypeError, time.asctime, 0)
# expected errors def test_mktime(self):
try: self.assertRaises(OverflowError,
time.asctime(0) time.mktime, (999999, 999999, 999999, 999999,
except TypeError:
pass
try:
time.mktime((999999, 999999, 999999, 999999,
999999, 999999, 999999, 999999, 999999, 999999, 999999, 999999,
999999)) 999999))
except OverflowError:
pass
test_support.run_unittest(TimeTestCase)