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'):
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
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
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)
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
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()
if (PyFloat_Check(obj)) {
double d = PyFloat_AsDouble(obj);
+ if (Py_IS_NAN(d)) {
+ *numerator = 0;
+ PyErr_SetString(PyExc_ValueError, "Invalid value NaN (not a number)");
+ return -1;
+ }
return _PyTime_DoubleToDenominator(d, sec, numerator,
denominator, round);
}
volatile double d;
d = PyFloat_AsDouble(obj);
+ if (Py_IS_NAN(d)) {
+ PyErr_SetString(PyExc_ValueError, "Invalid value NaN (not a number)");
+ return -1;
+ }
+
d = _PyTime_Round(d, round);
(void)modf(d, &intpart);
if (PyFloat_Check(obj)) {
double d;
d = PyFloat_AsDouble(obj);
+ if (Py_IS_NAN(d)) {
+ PyErr_SetString(PyExc_ValueError, "Invalid value NaN (not a number)");
+ return -1;
+ }
return _PyTime_FromFloatObject(t, d, round, unit_to_ns);
}
else {