MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_astimezone

Method test_astimezone

Lib/test/datetimetester.py:3108–3138  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 11

timezoneClass · 0.90
timedeltaClass · 0.90
AlsoBogusClass · 0.85
nowMethod · 0.80
astimezoneMethod · 0.80
FixedOffsetClass · 0.70
BogusClass · 0.70
BrokenClass · 0.70
replaceMethod · 0.45
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected