(self)
| 2882 | |
| 2883 | @unittest.skipIf(sys.platform == "win32", "Windows doesn't support min timestamp") |
| 2884 | def test_fromtimestamp_limits(self): |
| 2885 | try: |
| 2886 | self.theclass.fromtimestamp(-2**32 - 1) |
| 2887 | except (OSError, OverflowError): |
| 2888 | self.skipTest("Test not valid on this platform") |
| 2889 | |
| 2890 | # XXX: Replace these with datetime.{min,max}.timestamp() when we solve |
| 2891 | # the issue with gh-91012 |
| 2892 | min_dt = self.theclass.min + timedelta(days=1) |
| 2893 | min_ts = min_dt.timestamp() |
| 2894 | |
| 2895 | max_dt = self.theclass.max.replace(microsecond=0) |
| 2896 | max_ts = ((self.theclass.max - timedelta(hours=23)).timestamp() + |
| 2897 | timedelta(hours=22, minutes=59, seconds=59).total_seconds()) |
| 2898 | |
| 2899 | for (test_name, ts, expected) in [ |
| 2900 | ("minimum", min_ts, min_dt), |
| 2901 | ("maximum", max_ts, max_dt), |
| 2902 | ]: |
| 2903 | with self.subTest(test_name, ts=ts, expected=expected): |
| 2904 | actual = self.theclass.fromtimestamp(ts) |
| 2905 | |
| 2906 | self.assertEqual(actual, expected) |
| 2907 | |
| 2908 | # Test error conditions |
| 2909 | test_cases = [ |
| 2910 | ("Too small by a little", min_ts - timedelta(days=1, hours=12).total_seconds()), |
| 2911 | ("Too small by a lot", min_ts - timedelta(days=400).total_seconds()), |
| 2912 | ("Too big by a little", max_ts + timedelta(days=1).total_seconds()), |
| 2913 | ("Too big by a lot", max_ts + timedelta(days=400).total_seconds()), |
| 2914 | ] |
| 2915 | |
| 2916 | for test_name, ts in test_cases: |
| 2917 | with self.subTest(test_name, ts=ts): |
| 2918 | with self.assertRaises((ValueError, OverflowError)): |
| 2919 | # converting a Python int to C time_t can raise a |
| 2920 | # OverflowError, especially on 32-bit platforms. |
| 2921 | self.theclass.fromtimestamp(ts) |
| 2922 | |
| 2923 | @unittest.skipIf(sys.platform == "win32", "Windows doesn't support min timestamp") |
| 2924 | def test_utcfromtimestamp_limits(self): |
nothing calls this directly
no test coverage detected