diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2017-09-09 04:53:04 (GMT) |
---|---|---|
committer | Mariatta <Mariatta@users.noreply.github.com> | 2017-09-09 04:53:04 (GMT) |
commit | a4baf1c543bca261c27e98ba296e42665f3cb872 (patch) | |
tree | 954fbc81fb080d4234f2fcee258803346a43d180 /Lib/test | |
parent | 3892799668dbf2b123a52780fd1d78f8880fdeb7 (diff) | |
download | cpython-a4baf1c543bca261c27e98ba296e42665f3cb872.zip cpython-a4baf1c543bca261c27e98ba296e42665f3cb872.tar.gz cpython-a4baf1c543bca261c27e98ba296e42665f3cb872.tar.bz2 |
[3.6] bpo-26669: Fix nan arg value error in pytime.c (GH-3085) (GH-3467)
* Modify NaN check function and error message
* Fix pytime.c when arg is nan
* fix whitespace
(cherry picked from commit 829dacce4fca60fc3c3367980e75e21dfcdbe6be)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_time.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py index 810ec37..7093fc6 100644 --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -489,6 +489,10 @@ class TimeTestCase(unittest.TestCase): self.assertRaises(OSError, time.localtime, invalid_time_t) self.assertRaises(OSError, time.ctime, invalid_time_t) + # Issue #26669: check for localtime() failure + self.assertRaises(ValueError, time.localtime, float("nan")) + self.assertRaises(ValueError, time.ctime, float("nan")) + def test_get_clock_info(self): clocks = ['clock', 'perf_counter', 'process_time', 'time'] if hasattr(time, 'monotonic'): @@ -823,6 +827,11 @@ class TestCPyTime(CPyTimeTestCase, unittest.TestCase): lambda secs: secs * SEC_TO_NS, value_filter=c_int_filter) + # test nan + for time_rnd, _ in ROUNDING_MODES: + with self.assertRaises(TypeError): + PyTime_FromSeconds(float('nan')) + def test_FromSecondsObject(self): from _testcapi import PyTime_FromSecondsObject @@ -834,6 +843,11 @@ class TestCPyTime(CPyTimeTestCase, unittest.TestCase): PyTime_FromSecondsObject, lambda ns: self.decimal_round(ns * SEC_TO_NS)) + # test nan + for time_rnd, _ in ROUNDING_MODES: + with self.assertRaises(ValueError): + PyTime_FromSecondsObject(float('nan'), time_rnd) + def test_AsSecondsDouble(self): from _testcapi import PyTime_AsSecondsDouble @@ -847,6 +861,11 @@ class TestCPyTime(CPyTimeTestCase, unittest.TestCase): float_converter, NS_TO_SEC) + # test nan + for time_rnd, _ in ROUNDING_MODES: + with self.assertRaises(TypeError): + PyTime_AsSecondsDouble(float('nan')) + def create_decimal_converter(self, denominator): denom = decimal.Decimal(denominator) @@ -952,6 +971,11 @@ class TestOldPyTime(CPyTimeTestCase, unittest.TestCase): self.create_converter(SEC_TO_US), value_filter=self.time_t_filter) + # test nan + for time_rnd, _ in ROUNDING_MODES: + with self.assertRaises(ValueError): + pytime_object_to_timeval(float('nan'), time_rnd) + def test_object_to_timespec(self): from _testcapi import pytime_object_to_timespec @@ -963,6 +987,11 @@ class TestOldPyTime(CPyTimeTestCase, unittest.TestCase): self.create_converter(SEC_TO_NS), value_filter=self.time_t_filter) + # test nan + for time_rnd, _ in ROUNDING_MODES: + with self.assertRaises(ValueError): + pytime_object_to_timespec(float('nan'), time_rnd) + if __name__ == "__main__": unittest.main() |