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

Method test_gaps

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

Source from the content-addressed store, hash-verified

6870 self.assertEqual(ldt.fold, 0)
6871
6872 def test_gaps(self):
6873 tz = self.tz
6874 for dt, shift in tz.gaps():
6875 for x in [0 * shift, 0.5 * shift, shift - timedelta.resolution]:
6876 udt = dt + x
6877 udt = udt.replace(tzinfo=tz)
6878 ldt = tz.fromutc(udt)
6879 self.assertEqual(ldt.fold, 0)
6880 adt = udt.replace(tzinfo=timezone.utc).astimezone(tz)
6881 self.assertEquivDatetimes(adt, ldt)
6882 utcoffset = ldt.utcoffset()
6883 self.assertEqual(ldt.replace(tzinfo=None), udt.replace(tzinfo=None) + utcoffset)
6884 # Create a local time inside the gap
6885 ldt = tz.fromutc(dt.replace(tzinfo=tz)) - shift + x
6886 self.assertLess(ldt.replace(fold=1).utcoffset(),
6887 ldt.replace(fold=0).utcoffset(),
6888 "At %s." % ldt)
6889
6890 for x in [-timedelta.resolution, shift]:
6891 udt = dt + x
6892 ldt = tz.fromutc(udt.replace(tzinfo=tz))
6893 self.assertEqual(ldt.fold, 0)
6894
6895 @classmethod
6896 @contextlib.contextmanager

Callers

nothing calls this directly

Calls 8

assertEquivDatetimesMethod · 0.95
gapsMethod · 0.80
astimezoneMethod · 0.80
replaceMethod · 0.45
fromutcMethod · 0.45
assertEqualMethod · 0.45
utcoffsetMethod · 0.45
assertLessMethod · 0.45

Tested by

no test coverage detected