[Python-checkins] CVS: python/nondist/sandbox/datetime test_datetime.py,1.10,1.11
Tim Peters
tim_one@users.sourceforge.net
Sat, 02 Mar 2002 18:15:36 -0800
Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory usw-pr-cvs1:/tmp/cvs-serv25139
Modified Files:
test_datetime.py
Log Message:
Added test_roundtrip(), to verify datetime->string->datetime identity,
and to verify that a datetime object can be reconstructed exactly from
its pieces.
Index: test_datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/test_datetime.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** test_datetime.py 3 Mar 2002 02:10:24 -0000 1.10
--- test_datetime.py 3 Mar 2002 02:15:34 -0000 1.11
***************
*** 20,23 ****
--- 20,37 ----
self.assertEqual(dt.second, 0)
+ def test_roundtrip(self):
+ for dt in (datetime.new(1, 2, 3, 4, 5, 6, 7, 8),
+ datetime.now()):
+ # Verify dt -> string -> datetime identity.
+ s = repr(dt)
+ dt2 = eval(s)
+ self.assertEqual(dt, dt2)
+
+ # Verify identity via reconstructing from pieces.
+ dt2 = datetime.new(dt.year, dt.month, dt.day,
+ dt.hour, dt.minute, dt.second,
+ dt.microsecond, dt.tzoffset)
+ self.assertEqual(dt, dt2)
+
def test_tz_independent_comparing(self):
dt1 = datetime.new(2002, 3, 1, 9, 0, 0, tzoffset=-60)