MCPcopy Index your code
hub / github.com/python/cpython / test_one_transition

Method test_one_transition

Lib/test/test_zoneinfo/test_zoneinfo.py:592–631  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

590 module = py_zoneinfo
591
592 def test_one_transition(self):
593 LMT = ZoneOffset("LMT", -timedelta(hours=6, minutes=31, seconds=2))
594 STD = ZoneOffset("STD", -timedelta(hours=6))
595
596 transitions = [
597 ZoneTransition(datetime(1883, 6, 9, 14), LMT, STD),
598 ]
599
600 after = "STD6"
601
602 zf = self.construct_zone(transitions, after)
603 zi = self.klass.from_file(zf)
604
605 dt0 = datetime(1883, 6, 9, 1, tzinfo=zi)
606 dt1 = datetime(1883, 6, 10, 1, tzinfo=zi)
607
608 for dt, offset in [(dt0, LMT), (dt1, STD)]:
609 with self.subTest(name="local", dt=dt):
610 self.assertEqual(dt.tzname(), offset.tzname)
611 self.assertEqual(dt.utcoffset(), offset.utcoffset)
612 self.assertEqual(dt.dst(), offset.dst)
613
614 dts = [
615 (
616 datetime(1883, 6, 9, 1, tzinfo=zi),
617 datetime(1883, 6, 9, 7, 31, 2, tzinfo=timezone.utc),
618 ),
619 (
620 datetime(2010, 4, 1, 12, tzinfo=zi),
621 datetime(2010, 4, 1, 18, tzinfo=timezone.utc),
622 ),
623 ]
624
625 for dt_local, dt_utc in dts:
626 with self.subTest(name="fromutc", dt=dt_local):
627 dt_actual = dt_utc.astimezone(zi)
628 self.assertEqual(dt_actual, dt_local)
629
630 dt_utc_actual = dt_local.astimezone(timezone.utc)
631 self.assertEqual(dt_utc_actual, dt_utc)
632
633 def test_one_zone_dst(self):
634 DST = ZoneOffset("DST", ONE_H, ONE_H)

Callers

nothing calls this directly

Calls 12

construct_zoneMethod · 0.95
timedeltaClass · 0.90
datetimeClass · 0.90
ZoneOffsetClass · 0.85
ZoneTransitionClass · 0.85
astimezoneMethod · 0.80
from_fileMethod · 0.45
subTestMethod · 0.45
assertEqualMethod · 0.45
tznameMethod · 0.45
utcoffsetMethod · 0.45
dstMethod · 0.45

Tested by

no test coverage detected