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

Method test_tricky

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

Source from the content-addressed store, hash-verified

5940 # self.convert_between_tz_and_utc(Central, Eastern) # can't work
5941
5942 def test_tricky(self):
5943 # 22:00 on day before daylight starts.
5944 fourback = self.dston - timedelta(hours=4)
5945 ninewest = FixedOffset(-9*60, "-0900", 0)
5946 fourback = fourback.replace(tzinfo=ninewest)
5947 # 22:00-0900 is 7:00 UTC == 2:00 EST == 3:00 DST. Since it's "after
5948 # 2", we should get the 3 spelling.
5949 # If we plug 22:00 the day before into Eastern, it "looks like std
5950 # time", so its offset is returned as -5, and -5 - -9 = 4. Adding 4
5951 # to 22:00 lands on 2:00, which makes no sense in local time (the
5952 # local clock jumps from 1 to 3). The point here is to make sure we
5953 # get the 3 spelling.
5954 expected = self.dston.replace(hour=3)
5955 got = fourback.astimezone(Eastern).replace(tzinfo=None)
5956 self.assertEqual(expected, got)
5957
5958 # Similar, but map to 6:00 UTC == 1:00 EST == 2:00 DST. In that
5959 # case we want the 1:00 spelling.
5960 sixutc = self.dston.replace(hour=6, tzinfo=utc_real)
5961 # Now 6:00 "looks like daylight", so the offset wrt Eastern is -4,
5962 # and adding -4-0 == -4 gives the 2:00 spelling. We want the 1:00 EST
5963 # spelling.
5964 expected = self.dston.replace(hour=1)
5965 got = sixutc.astimezone(Eastern).replace(tzinfo=None)
5966 self.assertEqual(expected, got)
5967
5968 # Now on the day DST ends, we want "repeat an hour" behavior.
5969 # UTC 4:MM 5:MM 6:MM 7:MM checking these
5970 # EST 23:MM 0:MM 1:MM 2:MM
5971 # EDT 0:MM 1:MM 2:MM 3:MM
5972 # wall 0:MM 1:MM 1:MM 2:MM against these
5973 for utc in utc_real, utc_fake:
5974 for tz in Eastern, Pacific:
5975 first_std_hour = self.dstoff - timedelta(hours=2) # 23:MM
5976 # Convert that to UTC.
5977 first_std_hour -= tz.utcoffset(None)
5978 # Adjust for possibly fake UTC.
5979 asutc = first_std_hour + utc.utcoffset(None)
5980 # First UTC hour to convert; this is 4:00 when utc=utc_real &
5981 # tz=Eastern.
5982 asutcbase = asutc.replace(tzinfo=utc)
5983 for tzhour in (0, 1, 1, 2):
5984 expectedbase = self.dstoff.replace(hour=tzhour)
5985 for minute in 0, 30, 59:
5986 expected = expectedbase.replace(minute=minute)
5987 asutc = asutcbase.replace(minute=minute)
5988 astz = asutc.astimezone(tz)
5989 self.assertEqual(astz.replace(tzinfo=None), expected)
5990 asutcbase += HOUR
5991
5992
5993 def test_bogus_dst(self):

Callers

nothing calls this directly

Calls 6

timedeltaClass · 0.90
FixedOffsetClass · 0.85
astimezoneMethod · 0.80
replaceMethod · 0.45
assertEqualMethod · 0.45
utcoffsetMethod · 0.45

Tested by

no test coverage detected