MCPcopy Create free account
hub / github.com/dateutil/dateutil / test_matches_zoneinfo

Function test_matches_zoneinfo

tests/test_tzpath_data.py:119–159  ·  view source on GitHub ↗

utcoffset, tzname and fromutc agree with the stdlib zoneinfo.

(tz_source)

Source from the content-addressed store, hash-verified

117
118
119def test_matches_zoneinfo(tz_source):
120 """utcoffset, tzname and fromutc agree with the stdlib zoneinfo."""
121 # dateutil and zoneinfo share TZPATH, and the tz_source
122 # fixture blocks (or allows) tzdata for both of them.
123 #
124 # This doesn't compare dst(), which zoneinfo infers differently, and gets
125 # wrong for some zones (e.g. gh-85102); test_dst_matches_tzdata_zi checks
126 # dst() against the source data instead.
127 for key in _keys():
128 zone = tz.gettz(key)
129 reference = zoneinfo.ZoneInfo.no_cache(key)
130
131 for dt_utc in _probe_instants(zone):
132 dt = dt_utc.astimezone(zone)
133 dt_ref = dt_utc.astimezone(reference)
134 if (dt.replace(tzinfo=None), dt.fold) != (
135 dt_ref.replace(tzinfo=None),
136 dt_ref.fold,
137 ):
138 # zoneinfo gets some TZ strings wrong near the new year (e.g.
139 # "0/0,J365/23" rules); only accept a difference where its
140 # answer doesn't round trip and ours does.
141 assert dt_ref.astimezone(UTC) != dt_utc, (key, dt_utc)
142 assert dt.astimezone(UTC) == dt_utc, (key, dt_utc)
143
144 wall = dt_utc.replace(tzinfo=None)
145 for fold in (0, 1):
146 dt = tz.enfold(wall.replace(tzinfo=zone), fold=fold)
147 dt_ref = wall.replace(tzinfo=reference, fold=fold)
148 if (dt.utcoffset(), dt.tzname()) != (
149 dt_ref.utcoffset(),
150 dt_ref.tzname(),
151 ):
152 # As above: zoneinfo's offset has to be one that its own
153 # fromutc contradicts, and ours has to be one ours agrees
154 # with, so a difference in a real gap still fails.
155 case = (key, wall, fold)
156 ref_rt = dt_ref.astimezone(UTC).astimezone(reference)
157 our_rt = dt.astimezone(UTC).astimezone(zone)
158 assert ref_rt.replace(tzinfo=None) != wall, case
159 assert our_rt.replace(tzinfo=None) == wall, case
160
161
162####

Callers

nothing calls this directly

Calls 6

_keysFunction · 0.85
_probe_instantsFunction · 0.85
replaceMethod · 0.80
gettzMethod · 0.45
utcoffsetMethod · 0.45
tznameMethod · 0.45

Tested by

no test coverage detected