diff options
author | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2010-07-05 15:05:33 (GMT) |
---|---|---|
committer | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2010-07-05 15:05:33 (GMT) |
commit | f34e82ef49728f73254b1eff12bfe643c2cd2124 (patch) | |
tree | 198e0ea19ed49499672cf0bd15545be5ca0105dc /Lib/test/test_datetime.py | |
parent | a7465e2fdf7f7effe19fbbe2c9a79a40df6c5d9f (diff) | |
download | cpython-f34e82ef49728f73254b1eff12bfe643c2cd2124.zip cpython-f34e82ef49728f73254b1eff12bfe643c2cd2124.tar.gz cpython-f34e82ef49728f73254b1eff12bfe643c2cd2124.tar.bz2 |
Added more tests for utctimetuple()
Diffstat (limited to 'Lib/test/test_datetime.py')
-rw-r--r-- | Lib/test/test_datetime.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/Lib/test/test_datetime.py b/Lib/test/test_datetime.py index fb1ce4c..4423d9b 100644 --- a/Lib/test/test_datetime.py +++ b/Lib/test/test_datetime.py @@ -3008,7 +3008,7 @@ class TestDateTimeTZ(TestDateTime, TZInfoBase, unittest.TestCase): def test_utctimetuple(self): class DST(tzinfo): - def __init__(self, dstvalue): + def __init__(self, dstvalue=0): if isinstance(dstvalue, int): dstvalue = timedelta(minutes=dstvalue) self.dstvalue = dstvalue @@ -3043,6 +3043,26 @@ class TestDateTimeTZ(TestDateTime, TZInfoBase, unittest.TestCase): # is never in effect for a UTC time. self.assertEqual(0, t.tm_isdst) + # For naive datetime, utctimetuple == timetuple except for isdst + d = cls(1, 2, 3, 10, 20, 30, 40) + t = d.utctimetuple() + self.assertEqual(t[:-1], d.timetuple()[:-1]) + self.assertEqual(0, t.tm_isdst) + # Same if utcoffset is None + class NOFS(DST): + def utcoffset(self, dt): + return None + d = cls(1, 2, 3, 10, 20, 30, 40, tzinfo=NOFS()) + t = d.utctimetuple() + self.assertEqual(t[:-1], d.timetuple()[:-1]) + self.assertEqual(0, t.tm_isdst) + # Check that bad tzinfo is detected + class BOFS(DST): + def utcoffset(self, dt): + return "EST" + d = cls(1, 2, 3, 10, 20, 30, 40, tzinfo=BOFS()) + self.assertRaises(TypeError, d.utctimetuple) + # Check that utctimetuple() is the same as # astimezone(utc).timetuple() d = cls(2010, 11, 13, 14, 15, 16, 171819) |