MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_system_transitions

Method test_system_transitions

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

Source from the content-addressed store, hash-verified

6720 hasattr(_time, "tzset"), "time module has no attribute tzset"
6721 )
6722 def test_system_transitions(self):
6723 if ('Riyadh8' in self.zonename or
6724 # From tzdata NEWS file:
6725 # The files solar87, solar88, and solar89 are no longer distributed.
6726 # They were a negative experiment - that is, a demonstration that
6727 # tz data can represent solar time only with some difficulty and error.
6728 # Their presence in the distribution caused confusion, as Riyadh
6729 # civil time was generally not solar time in those years.
6730 self.zonename.startswith('right/')):
6731 self.skipTest("Skipping %s" % self.zonename)
6732 tz = self.tz
6733 with self._change_tz(self.zonename):
6734 for udt, shift in tz.transitions():
6735 if udt.year >= 2037:
6736 # System support for times around the end of 32-bit time_t
6737 # and later is flaky on many systems.
6738 break
6739 s0 = (udt - datetime(1970, 1, 1)) // SEC
6740 ss = shift // SEC # shift seconds
6741 for x in [-40 * 3600, -20 * 3600, -1, 0,
6742 ss - 1, ss + 20 * 3600, ss + 40 * 3600]:
6743 s = s0 + x
6744 sdt = datetime.fromtimestamp(s)
6745 tzdt = datetime.fromtimestamp(s, tz).replace(tzinfo=None)
6746 self.assertEquivDatetimes(sdt, tzdt)
6747 s1 = sdt.timestamp()
6748 self.assertEqual(s, s1)
6749 if ss > 0: # gap
6750 # Create local time inside the gap
6751 dt = datetime.fromtimestamp(s0) - shift / 2
6752 ts0 = dt.timestamp()
6753 ts1 = dt.replace(fold=1).timestamp()
6754 self.assertEqual(ts0, s0 + ss / 2)
6755 self.assertEqual(ts1, s0 - ss / 2)
6756 # gh-83861
6757 utc0 = dt.astimezone(timezone.utc)
6758 utc1 = dt.replace(fold=1).astimezone(timezone.utc)
6759 self.assertEqual(utc0, utc1 + timedelta(0, ss))
6760
6761
6762class ZoneInfoCompleteTest(unittest.TestSuite):

Callers

nothing calls this directly

Calls 12

_change_tzMethod · 0.95
assertEquivDatetimesMethod · 0.95
datetimeClass · 0.90
timedeltaClass · 0.90
skipTestMethod · 0.80
timestampMethod · 0.80
astimezoneMethod · 0.80
startswithMethod · 0.45
transitionsMethod · 0.45
fromtimestampMethod · 0.45
replaceMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected