[Python-checkins] python/nondist/sandbox/datetime test_both.py,1.33,1.34

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
2002年12月04日 14:49:19 -0800


Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv11846
Modified Files:
	test_both.py 
Log Message:
Added a test for fromtimestamp().
Index: test_both.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/test_both.py,v
retrieving revision 1.33
retrieving revision 1.34
diff -C2 -d -r1.33 -r1.34
*** test_both.py	4 Dec 2002 22:07:16 -0000	1.33
--- test_both.py	4 Dec 2002 22:49:04 -0000	1.34
***************
*** 468,471 ****
--- 468,495 ----
 self.assertRaises(OverflowError, dt.__sub__, -tiny)
 
+ def test_fromtimestamp(self):
+ import time
+ 
+ # Try an arbitrary fixed value.
+ year, month, day = 1999, 9, 19
+ ts = time.mktime((year, month, day, 0, 0, 0, 0, 0, -1))
+ d = self.theclass.fromtimestamp(ts)
+ self.assertEqual(d.year, year)
+ self.assertEqual(d.month, month)
+ self.assertEqual(d.day, day)
+ 
+ # Try today.
+ today = self.theclass.today()
+ ts = time.time()
+ todayagain = self.theclass.fromtimestamp(ts)
+ if today != todayagain:
+ # It's possible that equality fails if we're running at a
+ # midnight boundary, so wait a little and try again.
+ time.sleep(5)
+ today = self.theclass.today()
+ ts = time.time()
+ todayagain = self.theclass.fromtimestamp(ts)
+ self.assertEqual(today, todayagain)
+ 
 def test_weekday(self):
 for i in range(7):

AltStyle によって変換されたページ (->オリジナル) /