test_time.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. __author__ = 'Jacco Kulman'
  2. import unittest
  3. import time
  4. class TimeTestCase(unittest.TestCase):
  5. def setUp(self):
  6. self.t = time.time()
  7. def test_data_attributes(self):
  8. time.altzone
  9. time.daylight
  10. time.timezone
  11. time.tzname
  12. def test_clock(self):
  13. time.clock()
  14. def test_conversions(self):
  15. self.assertTrue(time.ctime(self.t)
  16. == time.asctime(time.localtime(self.t)))
  17. self.assertTrue(long(time.mktime(time.localtime(self.t)))
  18. == long(self.t))
  19. def test_sleep(self):
  20. time.sleep(0.01)
  21. def test_strftime(self):
  22. self.assertEqual(time.strftime("%b %d %Y %H:%M:%S", time.localtime(3661 + time.timezone)), "Jan 01 1970 01:01:01");
  23. def _test_dir(self):
  24. # this test fails because the compare
  25. self.assertEqual(dir(time), [
  26. '__file__'
  27. '__name__',
  28. '__package__',
  29. 'accept2dyear',
  30. 'altzone',
  31. 'asctime',
  32. 'clock',
  33. 'ctime',
  34. 'daylight',
  35. 'gmtime',
  36. 'localtime',
  37. 'mktime',
  38. 'sleep',
  39. 'strftime',
  40. 'strptime',
  41. 'struct_time',
  42. 'time',
  43. 'timezone',
  44. 'tzname',
  45. 'tzset']);
  46. if __name__ == '__main__':
  47. unittest.main()