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

Method test_utcfromtimestamp_limits

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

Source from the content-addressed store, hash-verified

2922
2923 @unittest.skipIf(sys.platform == "win32", "Windows doesn't support min timestamp")
2924 def test_utcfromtimestamp_limits(self):
2925 with self.assertWarns(DeprecationWarning):
2926 try:
2927 self.theclass.utcfromtimestamp(-2**32 - 1)
2928 except (OSError, OverflowError):
2929 self.skipTest("Test not valid on this platform")
2930
2931 min_dt = self.theclass.min.replace(tzinfo=timezone.utc)
2932 min_ts = min_dt.timestamp()
2933
2934 max_dt = self.theclass.max.replace(microsecond=0, tzinfo=timezone.utc)
2935 max_ts = max_dt.timestamp()
2936
2937 for (test_name, ts, expected) in [
2938 ("minimum", min_ts, min_dt.replace(tzinfo=None)),
2939 ("maximum", max_ts, max_dt.replace(tzinfo=None)),
2940 ]:
2941 with self.subTest(test_name, ts=ts, expected=expected):
2942 with self.assertWarns(DeprecationWarning):
2943 try:
2944 actual = self.theclass.utcfromtimestamp(ts)
2945 except (OSError, OverflowError) as exc:
2946 self.skipTest(str(exc))
2947
2948 self.assertEqual(actual, expected)
2949
2950 # Test error conditions
2951 test_cases = [
2952 ("Too small by a little", min_ts - 1),
2953 ("Too small by a lot", min_ts - timedelta(days=400).total_seconds()),
2954 ("Too big by a little", max_ts + 1),
2955 ("Too big by a lot", max_ts + timedelta(days=400).total_seconds()),
2956 ]
2957
2958 for test_name, ts in test_cases:
2959 with self.subTest(test_name, ts=ts):
2960 with self.assertRaises((ValueError, OverflowError)):
2961 with self.assertWarns(DeprecationWarning):
2962 # converting a Python int to C time_t can raise a
2963 # OverflowError, especially on 32-bit platforms.
2964 self.theclass.utcfromtimestamp(ts)
2965
2966 def test_insane_fromtimestamp(self):
2967 # 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
total_secondsMethod · 0.80
utcfromtimestampMethod · 0.45
replaceMethod · 0.45
subTestMethod · 0.45
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected