| 4253 | self.assertRaises(ValueError, str, t) |
| 4254 | |
| 4255 | def test_tzinfo_classes(self): |
| 4256 | cls = self.theclass |
| 4257 | class C1(tzinfo): |
| 4258 | def utcoffset(self, dt): return None |
| 4259 | def dst(self, dt): return None |
| 4260 | def tzname(self, dt): return None |
| 4261 | for t in (cls(1, 1, 1), |
| 4262 | cls(1, 1, 1, tzinfo=None), |
| 4263 | cls(1, 1, 1, tzinfo=C1())): |
| 4264 | self.assertIsNone(t.utcoffset()) |
| 4265 | self.assertIsNone(t.dst()) |
| 4266 | self.assertIsNone(t.tzname()) |
| 4267 | |
| 4268 | class C3(tzinfo): |
| 4269 | def utcoffset(self, dt): return timedelta(minutes=-1439) |
| 4270 | def dst(self, dt): return timedelta(minutes=1439) |
| 4271 | def tzname(self, dt): return "aname" |
| 4272 | t = cls(1, 1, 1, tzinfo=C3()) |
| 4273 | self.assertEqual(t.utcoffset(), timedelta(minutes=-1439)) |
| 4274 | self.assertEqual(t.dst(), timedelta(minutes=1439)) |
| 4275 | self.assertEqual(t.tzname(), "aname") |
| 4276 | |
| 4277 | # Wrong types. |
| 4278 | class C4(tzinfo): |
| 4279 | def utcoffset(self, dt): return "aname" |
| 4280 | def dst(self, dt): return 7 |
| 4281 | def tzname(self, dt): return 0 |
| 4282 | t = cls(1, 1, 1, tzinfo=C4()) |
| 4283 | self.assertRaises(TypeError, t.utcoffset) |
| 4284 | self.assertRaises(TypeError, t.dst) |
| 4285 | self.assertRaises(TypeError, t.tzname) |
| 4286 | |
| 4287 | # Offset out of range. |
| 4288 | class C6(tzinfo): |
| 4289 | def utcoffset(self, dt): return timedelta(hours=-24) |
| 4290 | def dst(self, dt): return timedelta(hours=24) |
| 4291 | t = cls(1, 1, 1, tzinfo=C6()) |
| 4292 | self.assertRaises(ValueError, t.utcoffset) |
| 4293 | self.assertRaises(ValueError, t.dst) |
| 4294 | |
| 4295 | # Not a whole number of seconds. |
| 4296 | class C7(tzinfo): |
| 4297 | def utcoffset(self, dt): return timedelta(microseconds=61) |
| 4298 | def dst(self, dt): return timedelta(microseconds=-81) |
| 4299 | t = cls(1, 1, 1, tzinfo=C7()) |
| 4300 | self.assertEqual(t.utcoffset(), timedelta(microseconds=61)) |
| 4301 | self.assertEqual(t.dst(), timedelta(microseconds=-81)) |
| 4302 | |
| 4303 | def test_aware_compare(self): |
| 4304 | cls = self.theclass |