bpo-26669: Fix nan arg value error in pytime.c (#3085) · python/cpython@829dacc

@@ -485,6 +485,10 @@ def test_localtime_failure(self):

485485

self.assertRaises(OSError, time.localtime, invalid_time_t)

486486

self.assertRaises(OSError, time.ctime, invalid_time_t)

487487488+

# Issue #26669: check for localtime() failure

489+

self.assertRaises(ValueError, time.localtime, float("nan"))

490+

self.assertRaises(ValueError, time.ctime, float("nan"))

491+488492

def test_get_clock_info(self):

489493

clocks = ['clock', 'perf_counter', 'process_time', 'time']

490494

if hasattr(time, 'monotonic'):

@@ -819,6 +823,11 @@ def c_int_filter(secs):

819823

lambda secs: secs * SEC_TO_NS,

820824

value_filter=c_int_filter)

821825826+

# test nan

827+

for time_rnd, _ in ROUNDING_MODES:

828+

with self.assertRaises(TypeError):

829+

PyTime_FromSeconds(float('nan'))

830+822831

def test_FromSecondsObject(self):

823832

from _testcapi import PyTime_FromSecondsObject

824833

@@ -830,6 +839,11 @@ def test_FromSecondsObject(self):

830839

PyTime_FromSecondsObject,

831840

lambda ns: self.decimal_round(ns * SEC_TO_NS))

832841842+

# test nan

843+

for time_rnd, _ in ROUNDING_MODES:

844+

with self.assertRaises(ValueError):

845+

PyTime_FromSecondsObject(float('nan'), time_rnd)

846+833847

def test_AsSecondsDouble(self):

834848

from _testcapi import PyTime_AsSecondsDouble

835849

@@ -843,6 +857,11 @@ def float_converter(ns):

843857

float_converter,

844858

NS_TO_SEC)

845859860+

# test nan

861+

for time_rnd, _ in ROUNDING_MODES:

862+

with self.assertRaises(TypeError):

863+

PyTime_AsSecondsDouble(float('nan'))

864+846865

def create_decimal_converter(self, denominator):

847866

denom = decimal.Decimal(denominator)

848867

@@ -948,6 +967,11 @@ def test_object_to_timeval(self):

948967

self.create_converter(SEC_TO_US),

949968

value_filter=self.time_t_filter)

950969970+

# test nan

971+

for time_rnd, _ in ROUNDING_MODES:

972+

with self.assertRaises(ValueError):

973+

pytime_object_to_timeval(float('nan'), time_rnd)

974+951975

def test_object_to_timespec(self):

952976

from _testcapi import pytime_object_to_timespec

953977

@@ -959,6 +983,11 @@ def test_object_to_timespec(self):

959983

self.create_converter(SEC_TO_NS),

960984

value_filter=self.time_t_filter)

961985986+

# test nan

987+

for time_rnd, _ in ROUNDING_MODES:

988+

with self.assertRaises(ValueError):

989+

pytime_object_to_timespec(float('nan'), time_rnd)

990+962991963992

if __name__ == "__main__":

964993

unittest.main()