| 4436 | self.assertRaises(ValueError, str, t) |
| 4437 | |
| 4438 | def test_tzinfo_classes(self): |
| 4439 | cls = self.theclass |
| 4440 | class C1(tzinfo): |
| 4441 | def utcoffset(self, dt): return None |
| 4442 | def dst(self, dt): return None |
| 4443 | def tzname(self, dt): return None |
| 4444 | for t in (cls(1, 1, 1), |
| 4445 | cls(1, 1, 1, tzinfo=None), |
| 4446 | cls(1, 1, 1, tzinfo=C1())): |
| 4447 | self.assertIsNone(t.utcoffset()) |
| 4448 | self.assertIsNone(t.dst()) |
| 4449 | self.assertIsNone(t.tzname()) |
| 4450 | |
| 4451 | class C3(tzinfo): |
| 4452 | def utcoffset(self, dt): return timedelta(minutes=-1439) |
| 4453 | def dst(self, dt): return timedelta(minutes=1439) |
| 4454 | def tzname(self, dt): return "aname" |
| 4455 | t = cls(1, 1, 1, tzinfo=C3()) |
| 4456 | self.assertEqual(t.utcoffset(), timedelta(minutes=-1439)) |
| 4457 | self.assertEqual(t.dst(), timedelta(minutes=1439)) |
| 4458 | self.assertEqual(t.tzname(), "aname") |
| 4459 | |
| 4460 | # Wrong types. |
| 4461 | class C4(tzinfo): |
| 4462 | def utcoffset(self, dt): return "aname" |
| 4463 | def dst(self, dt): return 7 |
| 4464 | def tzname(self, dt): return 0 |
| 4465 | t = cls(1, 1, 1, tzinfo=C4()) |
| 4466 | self.assertRaises(TypeError, t.utcoffset) |
| 4467 | self.assertRaises(TypeError, t.dst) |
| 4468 | self.assertRaises(TypeError, t.tzname) |
| 4469 | |
| 4470 | # Offset out of range. |
| 4471 | class C6(tzinfo): |
| 4472 | def utcoffset(self, dt): return timedelta(hours=-24) |
| 4473 | def dst(self, dt): return timedelta(hours=24) |
| 4474 | t = cls(1, 1, 1, tzinfo=C6()) |
| 4475 | self.assertRaises(ValueError, t.utcoffset) |
| 4476 | self.assertRaises(ValueError, t.dst) |
| 4477 | |
| 4478 | # Not a whole number of seconds. |
| 4479 | class C7(tzinfo): |
| 4480 | def utcoffset(self, dt): return timedelta(microseconds=61) |
| 4481 | def dst(self, dt): return timedelta(microseconds=-81) |
| 4482 | t = cls(1, 1, 1, tzinfo=C7()) |
| 4483 | self.assertEqual(t.utcoffset(), timedelta(microseconds=61)) |
| 4484 | self.assertEqual(t.dst(), timedelta(microseconds=-81)) |
| 4485 | |
| 4486 | def test_aware_compare(self): |
| 4487 | cls = self.theclass |