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

Method test_utcfromtimestamp_limits

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

Source from the content-addressed store, hash-verified

2781 self.theclass.fromtimestamp(ts)
2782
2783 def test_utcfromtimestamp_limits(self):
2784 with self.assertWarns(DeprecationWarning):
2785 try:
2786 self.theclass.utcfromtimestamp(-2**32 - 1)
2787 except (OSError, OverflowError):
2788 self.skipTest("Test not valid on this platform")
2789
2790 min_dt = self.theclass.min.replace(tzinfo=timezone.utc)
2791 min_ts = min_dt.timestamp()
2792
2793 max_dt = self.theclass.max.replace(microsecond=0, tzinfo=timezone.utc)
2794 max_ts = max_dt.timestamp()
2795
2796 for (test_name, ts, expected) in [
2797 ("minimum", min_ts, min_dt.replace(tzinfo=None)),
2798 ("maximum", max_ts, max_dt.replace(tzinfo=None)),
2799 ]:
2800 with self.subTest(test_name, ts=ts, expected=expected):
2801 with self.assertWarns(DeprecationWarning):
2802 try:
2803 actual = self.theclass.utcfromtimestamp(ts)
2804 except (OSError, OverflowError) as exc:
2805 self.skipTest(str(exc))
2806
2807 self.assertEqual(actual, expected)
2808
2809 # Test error conditions
2810 test_cases = [
2811 ("Too small by a little", min_ts - 1),
2812 ("Too small by a lot", min_ts - timedelta(days=400).total_seconds()),
2813 ("Too big by a little", max_ts + 1),
2814 ("Too big by a lot", max_ts + timedelta(days=400).total_seconds()),
2815 ]
2816
2817 for test_name, ts in test_cases:
2818 with self.subTest(test_name, ts=ts):
2819 with self.assertRaises((ValueError, OverflowError)):
2820 with self.assertWarns(DeprecationWarning):
2821 # converting a Python int to C time_t can raise a
2822 # OverflowError, especially on 32-bit platforms.
2823 self.theclass.utcfromtimestamp(ts)
2824
2825 def test_insane_fromtimestamp(self):
2826 # It's possible that some platform maps time_t to double,

Callers

nothing calls this directly

Calls 11

timedeltaClass · 0.90
strFunction · 0.85
assertWarnsMethod · 0.80
skipTestMethod · 0.80
timestampMethod · 0.80
subTestMethod · 0.80
total_secondsMethod · 0.80
utcfromtimestampMethod · 0.45
replaceMethod · 0.45
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected