diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-02-10 10:34:37 +0100 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2017-02-10 10:34:37 +0100 |
commit | 0b87bc9a510db8933ec52eee2cbe71b2388ad5c3 (patch) | |
tree | 048714e43df0bdcb800f5c42520946ea5cc7d078 /Lib/test/datetimetester.py | |
parent | 8972587fab93cd27ac78b4eab3805f5e11164cb9 (diff) | |
parent | efb9e6050c840ddb095b372abd5a6d04c73aff2b (diff) | |
download | cpython-0b87bc9a510db8933ec52eee2cbe71b2388ad5c3.tar.gz |
Merge 3.6
Diffstat (limited to 'Lib/test/datetimetester.py')
-rw-r--r-- | Lib/test/datetimetester.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index d65186db0c..7feabced94 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -1989,6 +1989,42 @@ class TestDateTime(TestDate): self.assertEqual(t.second, 0) self.assertEqual(t.microsecond, 7812) + def test_timestamp_limits(self): + # minimum timestamp + min_dt = self.theclass.min.replace(tzinfo=timezone.utc) + min_ts = min_dt.timestamp() + # date 0001-01-01 00:00:00+00:00: timestamp=-62135596800 + self.assertEqual(self.theclass.fromtimestamp(min_ts, tz=timezone.utc), + min_dt) + + # maximum timestamp: set seconds to zero to avoid rounding issues + max_dt = self.theclass.max.replace(tzinfo=timezone.utc, + second=0, microsecond=0) + max_ts = max_dt.timestamp() + # date 9999-12-31 23:59:00+00:00: timestamp 253402300740 + self.assertEqual(self.theclass.fromtimestamp(max_ts, tz=timezone.utc), + max_dt) + + # number of seconds greater than 1 year: make sure that the new date + # is not valid in datetime.datetime limits + delta = 3600 * 24 * 400 + + # too small + ts = min_ts - delta + # converting a Python int to C time_t can raise a OverflowError, + # especially on 32-bit platforms. + with self.assertRaises((ValueError, OverflowError)): + self.theclass.fromtimestamp(ts) + with self.assertRaises((ValueError, OverflowError)): + self.theclass.utcfromtimestamp(ts) + + # too big + ts = max_dt.timestamp() + delta + with self.assertRaises((ValueError, OverflowError)): + self.theclass.fromtimestamp(ts) + with self.assertRaises((ValueError, OverflowError)): + self.theclass.utcfromtimestamp(ts) + def test_insane_fromtimestamp(self): # It's possible that some platform maps time_t to double, # and that this test will fail there. This test should |