(self)
| 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): |
nothing calls this directly
no test coverage detected