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

Method test_tzstr_from_utc

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

Source from the content-addressed store, hash-verified

1037 self.assertEqual(dt.dst(), offset.dst)
1038
1039 def test_tzstr_from_utc(self):
1040 for tzstr, cases in self.test_cases.items():
1041 with self.subTest(tzstr=tzstr):
1042 zi = self.zone_from_tzstr(tzstr)
1043
1044 for dt_naive, offset, dt_type in cases:
1045 if dt_type == self.GAP:
1046 continue # Cannot create a gap from UTC
1047
1048 dt_utc = (dt_naive - offset.utcoffset).replace(
1049 tzinfo=timezone.utc
1050 )
1051
1052 # Check that we can go UTC -> Our zone
1053 dt_act = dt_utc.astimezone(zi)
1054 dt_exp = dt_naive.replace(tzinfo=zi)
1055
1056 self.assertEqual(dt_act, dt_exp)
1057
1058 if dt_type == self.FOLD:
1059 self.assertEqual(dt_act.fold, dt_naive.fold, dt_naive)
1060 else:
1061 self.assertEqual(dt_act.fold, 0)
1062
1063 # Now check that we can go our zone -> UTC
1064 dt_act = dt_exp.astimezone(timezone.utc)
1065
1066 self.assertEqual(dt_act, dt_utc)
1067
1068 def test_extreme_tzstr(self):
1069 tzstrs = [

Callers

nothing calls this directly

Calls 6

zone_from_tzstrMethod · 0.95
astimezoneMethod · 0.80
itemsMethod · 0.45
subTestMethod · 0.45
replaceMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected