Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(253291)

Side by Side Diff: Lib/test/test_time.py

Issue 16510: Using appropriate checks in tests
Patch Set: Created 5 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_tempfile.py ('k') | Lib/test/test_traceback.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 from test import support 1 from test import support
2 import time 2 import time
3 import unittest 3 import unittest
4 import locale 4 import locale
5 import sysconfig 5 import sysconfig
6 import sys 6 import sys
7 import platform 7 import platform
8 try: 8 try:
9 import threading 9 import threading
10 except ImportError: 10 except ImportError:
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 environ['TZ'] = victoria 287 environ['TZ'] = victoria
288 time.tzset() 288 time.tzset()
289 self.assertNotEqual(time.gmtime(xmas2002), time.localtime(xmas2002)) 289 self.assertNotEqual(time.gmtime(xmas2002), time.localtime(xmas2002))
290 290
291 # Issue #11886: Australian Eastern Standard Time (UTC+10) is called 291 # Issue #11886: Australian Eastern Standard Time (UTC+10) is called
292 # "EST" (as Eastern Standard Time, UTC-5) instead of "AEST" 292 # "EST" (as Eastern Standard Time, UTC-5) instead of "AEST"
293 # (non-DST timezone), and "EDT" instead of "AEDT" (DST timezone), 293 # (non-DST timezone), and "EDT" instead of "AEDT" (DST timezone),
294 # on some operating systems (e.g. FreeBSD), which is wrong. See for 294 # on some operating systems (e.g. FreeBSD), which is wrong. See for
295 # example this bug: 295 # example this bug:
296 # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=93810 296 # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=93810
297 self.assertIn(time.tzname[0], ('AEST' 'EST'), time.tzname[0]) 297 self.assertIn(time.tzname[0], ('AEST' 'EST'))
298 self.assertTrue(time.tzname[1] in ('AEDT', 'EDT'), str(time.tzname[1 ])) 298 self.assertIn(time.tzname[1], ('AEDT', 'EDT'))
299 self.assertEqual(len(time.tzname), 2) 299 self.assertEqual(len(time.tzname), 2)
300 self.assertEqual(time.daylight, 1) 300 self.assertEqual(time.daylight, 1)
301 self.assertEqual(time.timezone, -36000) 301 self.assertEqual(time.timezone, -36000)
302 self.assertEqual(time.altzone, -39600) 302 self.assertEqual(time.altzone, -39600)
303 self.assertEqual(time.localtime(xmas2002).tm_isdst, 1) 303 self.assertEqual(time.localtime(xmas2002).tm_isdst, 1)
304 304
305 finally: 305 finally:
306 # Repair TZ environment variable in case any other tests 306 # Repair TZ environment variable in case any other tests
307 # rely on it. 307 # rely on it.
308 if org_TZ is not None: 308 if org_TZ is not None:
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 def test_localtime_timezone(self): 642 def test_localtime_timezone(self):
643 643
644 # Get the localtime and examine it for the offset and zone. 644 # Get the localtime and examine it for the offset and zone.
645 lt = time.localtime() 645 lt = time.localtime()
646 self.assertTrue(hasattr(lt, "tm_gmtoff")) 646 self.assertTrue(hasattr(lt, "tm_gmtoff"))
647 self.assertTrue(hasattr(lt, "tm_zone")) 647 self.assertTrue(hasattr(lt, "tm_zone"))
648 648
649 # See if the offset and zone are similar to the module 649 # See if the offset and zone are similar to the module
650 # attributes. 650 # attributes.
651 if lt.tm_gmtoff is None: 651 if lt.tm_gmtoff is None:
652 self.assertTrue(not hasattr(time, "timezone")) 652 self.assertFalse(hasattr(time, "timezone"))
653 else: 653 else:
654 self.assertEqual(lt.tm_gmtoff, -[time.timezone, time.altzone][lt.tm_ isdst]) 654 self.assertEqual(lt.tm_gmtoff, -[time.timezone, time.altzone][lt.tm_ isdst])
655 if lt.tm_zone is None: 655 if lt.tm_zone is None:
656 self.assertTrue(not hasattr(time, "tzname")) 656 self.assertFalse(hasattr(time, "tzname"))
657 else: 657 else:
658 self.assertEqual(lt.tm_zone, time.tzname[lt.tm_isdst]) 658 self.assertEqual(lt.tm_zone, time.tzname[lt.tm_isdst])
659 659
660 # Try and make UNIX times from the localtime and a 9-tuple 660 # Try and make UNIX times from the localtime and a 9-tuple
661 # created from the localtime. Test to see that the times are 661 # created from the localtime. Test to see that the times are
662 # the same. 662 # the same.
663 t = time.mktime(lt); t9 = time.mktime(lt[:9]) 663 t = time.mktime(lt); t9 = time.mktime(lt[:9])
664 self.assertEqual(t, t9) 664 self.assertEqual(t, t9)
665 665
666 # Make localtimes from the UNIX times and compare them to 666 # Make localtimes from the UNIX times and compare them to
(...skipping 14 matching lines...) Expand all
681 self.assertEqual(t.tm_gmtoff, 5 * 3600) 681 self.assertEqual(t.tm_gmtoff, 5 * 3600)
682 682
683 @unittest.skipUnless(time._STRUCT_TM_ITEMS == 11, "needs tm_zone support") 683 @unittest.skipUnless(time._STRUCT_TM_ITEMS == 11, "needs tm_zone support")
684 def test_short_times(self): 684 def test_short_times(self):
685 685
686 import pickle 686 import pickle
687 687
688 # Load a short time structure using pickle. 688 # Load a short time structure using pickle.
689 st = b"ctime\nstruct_time\np0\n((I2007\nI8\nI11\nI1\nI24\nI49\nI5\nI223\ nI1\ntp1\n(dp2\ntp3\nRp4\n." 689 st = b"ctime\nstruct_time\np0\n((I2007\nI8\nI11\nI1\nI24\nI49\nI5\nI223\ nI1\ntp1\n(dp2\ntp3\nRp4\n."
690 lt = pickle.loads(st) 690 lt = pickle.loads(st)
691 self.assertIs(lt.tm_gmtoff, None) 691 self.assertIsNone(lt.tm_gmtoff)
692 self.assertIs(lt.tm_zone, None) 692 self.assertIsNone(lt.tm_zone)
693 693
694 694
695 if __name__ == "__main__": 695 if __name__ == "__main__":
696 unittest.main() 696 unittest.main()
OLDNEW
« no previous file with comments | « Lib/test/test_tempfile.py ('k') | Lib/test/test_traceback.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+