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

Method test_tz_before_only

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

Source from the content-addressed store, hash-verified

700 self.assertIs(t.dst(), None)
701
702 def test_tz_before_only(self):
703 # From RFC 8536 Section 3.2:
704 #
705 # If there are no transitions, local time for all timestamps is
706 # specified by the TZ string in the footer if present and nonempty;
707 # otherwise, it is specified by time type 0.
708
709 offsets = [
710 ZoneOffset("STD", ZERO, ZERO),
711 ZoneOffset("DST", ONE_H, ONE_H),
712 ]
713
714 for offset in offsets:
715 # Phantom transition to set time type 0.
716 transitions = [
717 ZoneTransition(None, offset, offset),
718 ]
719
720 after = ""
721
722 zf = self.construct_zone(transitions, after)
723 zi = self.klass.from_file(zf)
724
725 dts = [
726 datetime(1900, 1, 1),
727 datetime(1970, 1, 1),
728 datetime(2000, 1, 1),
729 ]
730
731 for dt in dts:
732 dt = dt.replace(tzinfo=zi)
733 with self.subTest(offset=offset, dt=dt):
734 self.assertEqual(dt.tzname(), offset.tzname)
735 self.assertEqual(dt.utcoffset(), offset.utcoffset)
736 self.assertEqual(dt.dst(), offset.dst)
737
738 def test_empty_zone(self):
739 zf = self.construct_zone([], "")

Callers

nothing calls this directly

Calls 11

construct_zoneMethod · 0.95
datetimeClass · 0.90
ZoneOffsetClass · 0.85
ZoneTransitionClass · 0.85
from_fileMethod · 0.45
replaceMethod · 0.45
subTestMethod · 0.45
assertEqualMethod · 0.45
tznameMethod · 0.45
utcoffsetMethod · 0.45
dstMethod · 0.45

Tested by

no test coverage detected