[Python-checkins] python/nondist/sandbox/datetime test_both.py,1.26,1.27

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Tue, 03 Dec 2002 13:17:09 -0800


Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv16932

Modified Files:
	test_both.py 
Log Message:
The timedelta type lacked a roundtrip test; added one.


Index: test_both.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/test_both.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** test_both.py	3 Dec 2002 20:43:45 -0000	1.26
--- test_both.py	3 Dec 2002 21:17:04 -0000	1.27
***************
*** 240,243 ****
--- 240,258 ----
             "999999999 days, 23:59:59.999999")
  
+     def test_roundtrip(self):
+         for td in (timedelta(days=999999999, hours=23, minutes=59,
+                              seconds=59, microseconds=999999),
+                    timedelta(days=-999999999),
+                    timedelta(days=1, seconds=2, microseconds=3)):
+ 
+             # Verify td -> string -> td identity.
+             s = repr(td)
+             td2 = eval(s)
+             self.assertEqual(td, td2)
+ 
+             # Verify identity via reconstructing from pieces.
+             td2 = timedelta(td.days, td.seconds, td.microseconds)
+             self.assertEqual(td, td2)
+ 
  #############################################################################
  # date tests