astimezone() internals: if utcoffset() returns a duration, complain if

dst() returns None (instead of treating that as 0).
This commit is contained in:
Tim Peters 2003-01-02 19:35:54 +00:00
parent 0123139d66
commit 710fb1548a
4 changed files with 45 additions and 14 deletions

View file

@ -2591,6 +2591,8 @@ class TestTimezoneConversions(unittest.TestCase):
dston = datetimetz(2002, 4, 7, 2)
dstoff = datetimetz(2002, 10, 27, 2)
theclass = datetimetz
# Check a time that's inside DST.
def checkinside(self, dt, tz, utc, dston, dstoff):
self.assertEqual(dt.dst(), HOUR)
@ -2729,6 +2731,21 @@ class TestTimezoneConversions(unittest.TestCase):
got = sixutc.astimezone(Eastern).astimezone(None)
self.assertEqual(expected, got)
def test_bogus_dst(self):
class ok(tzinfo):
def utcoffset(self, dt): return HOUR
def dst(self, dt): return HOUR
now = self.theclass.now().replace(tzinfo=utc_real)
# Doesn't blow up.
now.astimezone(ok())
# Does blow up.
class notok(ok):
def dst(self, dt): return None
self.assertRaises(ValueError, now.astimezone, notok())
def test_suite():
allsuites = [unittest.makeSuite(klass, 'test')
for klass in (TestModule,