(self)
| 3271 | |
| 3272 | @support.run_with_tz('EDT4') |
| 3273 | def test_astimezone(self): |
| 3274 | dt = self.theclass.now() |
| 3275 | f = FixedOffset(44, "0044") |
| 3276 | dt_utc = dt.replace(tzinfo=timezone(timedelta(hours=-4), 'EDT')) |
| 3277 | self.assertEqual(dt.astimezone(), dt_utc) # naive |
| 3278 | self.assertRaises(TypeError, dt.astimezone, f, f) # too many args |
| 3279 | self.assertRaises(TypeError, dt.astimezone, dt) # arg wrong type |
| 3280 | dt_f = dt.replace(tzinfo=f) + timedelta(hours=4, minutes=44) |
| 3281 | self.assertEqual(dt.astimezone(f), dt_f) # naive |
| 3282 | self.assertEqual(dt.astimezone(tz=f), dt_f) # naive |
| 3283 | |
| 3284 | class Bogus(tzinfo): |
| 3285 | def utcoffset(self, dt): return None |
| 3286 | def dst(self, dt): return timedelta(0) |
| 3287 | bog = Bogus() |
| 3288 | self.assertRaises(ValueError, dt.astimezone, bog) # naive |
| 3289 | self.assertEqual(dt.replace(tzinfo=bog).astimezone(f), dt_f) |
| 3290 | |
| 3291 | class AlsoBogus(tzinfo): |
| 3292 | def utcoffset(self, dt): return timedelta(0) |
| 3293 | def dst(self, dt): return None |
| 3294 | alsobog = AlsoBogus() |
| 3295 | self.assertRaises(ValueError, dt.astimezone, alsobog) # also naive |
| 3296 | |
| 3297 | class Broken(tzinfo): |
| 3298 | def utcoffset(self, dt): return 1 |
| 3299 | def dst(self, dt): return 1 |
| 3300 | broken = Broken() |
| 3301 | dt_broken = dt.replace(tzinfo=broken) |
| 3302 | with self.assertRaises(TypeError): |
| 3303 | dt_broken.astimezone() |
| 3304 | |
| 3305 | def test_subclass_datetime(self): |
| 3306 |
nothing calls this directly
no test coverage detected