(self)
| 3106 | |
| 3107 | @support.run_with_tz('EDT4') |
| 3108 | def test_astimezone(self): |
| 3109 | dt = self.theclass.now() |
| 3110 | f = FixedOffset(44, "0044") |
| 3111 | dt_utc = dt.replace(tzinfo=timezone(timedelta(hours=-4), 'EDT')) |
| 3112 | self.assertEqual(dt.astimezone(), dt_utc) # naive |
| 3113 | self.assertRaises(TypeError, dt.astimezone, f, f) # too many args |
| 3114 | self.assertRaises(TypeError, dt.astimezone, dt) # arg wrong type |
| 3115 | dt_f = dt.replace(tzinfo=f) + timedelta(hours=4, minutes=44) |
| 3116 | self.assertEqual(dt.astimezone(f), dt_f) # naive |
| 3117 | self.assertEqual(dt.astimezone(tz=f), dt_f) # naive |
| 3118 | |
| 3119 | class Bogus(tzinfo): |
| 3120 | def utcoffset(self, dt): return None |
| 3121 | def dst(self, dt): return timedelta(0) |
| 3122 | bog = Bogus() |
| 3123 | self.assertRaises(ValueError, dt.astimezone, bog) # naive |
| 3124 | self.assertEqual(dt.replace(tzinfo=bog).astimezone(f), dt_f) |
| 3125 | |
| 3126 | class AlsoBogus(tzinfo): |
| 3127 | def utcoffset(self, dt): return timedelta(0) |
| 3128 | def dst(self, dt): return None |
| 3129 | alsobog = AlsoBogus() |
| 3130 | self.assertRaises(ValueError, dt.astimezone, alsobog) # also naive |
| 3131 | |
| 3132 | class Broken(tzinfo): |
| 3133 | def utcoffset(self, dt): return 1 |
| 3134 | def dst(self, dt): return 1 |
| 3135 | broken = Broken() |
| 3136 | dt_broken = dt.replace(tzinfo=broken) |
| 3137 | with self.assertRaises(TypeError): |
| 3138 | dt_broken.astimezone() |
| 3139 | |
| 3140 | def test_subclass_datetime(self): |
| 3141 |
nothing calls this directly
no test coverage detected