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

Method test_fromtimestamp_limits

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

Source from the content-addressed store, hash-verified

2742 self.assertEqual(max_ts, 253402300799.0)
2743
2744 def test_fromtimestamp_limits(self):
2745 try:
2746 self.theclass.fromtimestamp(-2**32 - 1)
2747 except (OSError, OverflowError):
2748 self.skipTest("Test not valid on this platform")
2749
2750 # XXX: Replace these with datetime.{min,max}.timestamp() when we solve
2751 # the issue with gh-91012
2752 min_dt = self.theclass.min + timedelta(days=1)
2753 min_ts = min_dt.timestamp()
2754
2755 max_dt = self.theclass.max.replace(microsecond=0)
2756 max_ts = ((self.theclass.max - timedelta(hours=23)).timestamp() +
2757 timedelta(hours=22, minutes=59, seconds=59).total_seconds())
2758
2759 for (test_name, ts, expected) in [
2760 ("minimum", min_ts, min_dt),
2761 ("maximum", max_ts, max_dt),
2762 ]:
2763 with self.subTest(test_name, ts=ts, expected=expected):
2764 actual = self.theclass.fromtimestamp(ts)
2765
2766 self.assertEqual(actual, expected)
2767
2768 # Test error conditions
2769 test_cases = [
2770 ("Too small by a little", min_ts - timedelta(days=1, hours=12).total_seconds()),
2771 ("Too small by a lot", min_ts - timedelta(days=400).total_seconds()),
2772 ("Too big by a little", max_ts + timedelta(days=1).total_seconds()),
2773 ("Too big by a lot", max_ts + timedelta(days=400).total_seconds()),
2774 ]
2775
2776 for test_name, ts in test_cases:
2777 with self.subTest(test_name, ts=ts):
2778 with self.assertRaises((ValueError, OverflowError)):
2779 # converting a Python int to C time_t can raise a
2780 # OverflowError, especially on 32-bit platforms.
2781 self.theclass.fromtimestamp(ts)
2782
2783 def test_utcfromtimestamp_limits(self):
2784 with self.assertWarns(DeprecationWarning):

Callers

nothing calls this directly

Calls 9

timedeltaClass · 0.90
skipTestMethod · 0.80
timestampMethod · 0.80
total_secondsMethod · 0.80
subTestMethod · 0.80
fromtimestampMethod · 0.45
replaceMethod · 0.45
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected