diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2017-09-19 14:00:44 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-09-19 14:00:44 (GMT) |
commit | f37dd11f0d4832c15d49c2ddc83d533ddaa36e74 (patch) | |
tree | 44c1ef9d26aedc095e5820113bf0dfe8100aa324 /Lib | |
parent | 99a51d4e5b154a7b8d971090fecc1e34769a3ca1 (diff) | |
download | cpython-f37dd11f0d4832c15d49c2ddc83d533ddaa36e74.zip cpython-f37dd11f0d4832c15d49c2ddc83d533ddaa36e74.tar.gz cpython-f37dd11f0d4832c15d49c2ddc83d533ddaa36e74.tar.bz2 |
[3.6] bpo-31293: Fix crashes in truediv and mul of a timedelta by a float with a bad as_integer_ratio() method. (GH-3227) (#3654)
(cherry picked from commit 865e4b4f630e2ae91e61239258abb58b488f1d65)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/datetimetester.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index b25e6c1..77df1b3 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -846,6 +846,26 @@ class TestTimeDelta(HarmlessMixedComparison, unittest.TestCase): self.assertRaises(TypeError, divmod, t, 10) + def test_issue31293(self): + # The interpreter shouldn't crash in case a timedelta is divided or + # multiplied by a float with a bad as_integer_ratio() method. + def get_bad_float(bad_ratio): + class BadFloat(float): + def as_integer_ratio(self): + return bad_ratio + return BadFloat() + + with self.assertRaises(TypeError): + timedelta() / get_bad_float(1 << 1000) + with self.assertRaises(TypeError): + timedelta() * get_bad_float(1 << 1000) + + for bad_ratio in [(), (42, ), (1, 2, 3)]: + with self.assertRaises(ValueError): + timedelta() / get_bad_float(bad_ratio) + with self.assertRaises(ValueError): + timedelta() * get_bad_float(bad_ratio) + ############################################################################# # date tests |