summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_time.py
diff options
context:
space:
mode:
authorHan Lee <hanlee.dev@gmail.com>2017-09-08 23:05:05 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2017-09-08 23:05:05 (GMT)
commit829dacce4fca60fc3c3367980e75e21dfcdbe6be (patch)
tree749ad4b2cb18866dce40da6cfb4b53b0424b8041 /Lib/test/test_time.py
parente6eb48c10dc389d1d70657593de6a6cb3087d3d1 (diff)
downloadcpython-829dacce4fca60fc3c3367980e75e21dfcdbe6be.zip
cpython-829dacce4fca60fc3c3367980e75e21dfcdbe6be.tar.gz
cpython-829dacce4fca60fc3c3367980e75e21dfcdbe6be.tar.bz2
bpo-26669: Fix nan arg value error in pytime.c (#3085)
* Fix #26669 * Modify NaN check function and error message * Fix pytime.c when arg is nan * fix whitespace
Diffstat (limited to 'Lib/test/test_time.py')
-rw-r--r--Lib/test/test_time.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py
index 42323b9..b2aedc3 100644
--- a/Lib/test/test_time.py
+++ b/Lib/test/test_time.py
@@ -485,6 +485,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'):
@@ -819,6 +823,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
@@ -830,6 +839,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
@@ -843,6 +857,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)
@@ -948,6 +967,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
@@ -959,6 +983,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()