Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Lib/test/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ def test_localtime_failure(self):
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"))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok for "functional" tests", but I also would like to see unit tests on the following _testcapi functions:

  • pytime_object_to_time_t
  • pytime_object_to_timeval
  • pytime_object_to_timespec
  • PyTime_FromSeconds
  • PyTime_FromSecondsObject
  • PyTime_AsSecondsDouble

See CPyTimeTestCase in test_time.py.


def test_get_clock_info(self):
clocks = ['clock', 'perf_counter', 'process_time', 'time']
if hasattr(time, 'monotonic'):
Expand Down
5 changes: 5 additions & 0 deletions Python/pytime.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ _PyTime_ObjectToTime_t(PyObject *obj, time_t *sec, _PyTime_round_t 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);

Expand Down