summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-09-10 08:10:39 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-09-10 08:10:39 (GMT)
commit4237d3474c4792472009c6c6c5d46a7f7ab1410d (patch)
tree16d8435e1868d79970a0384ca65db4313b0c2e44
parent9c72f9b30a60d09c10b6cde23bd4b0546c6947af (diff)
downloadcpython-4237d3474c4792472009c6c6c5d46a7f7ab1410d.zip
cpython-4237d3474c4792472009c6c6c5d46a7f7ab1410d.tar.gz
cpython-4237d3474c4792472009c6c6c5d46a7f7ab1410d.tar.bz2
Fix test_time on platform with 32-bit time_t type
Filter values which would overflow when converted to a C time_t type.
-rw-r--r--Lib/test/test_time.py23
-rw-r--r--Modules/_testcapimodule.c1
2 files changed, 19 insertions, 5 deletions
diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py
index 7f1613b..891c99d 100644
--- a/Lib/test/test_time.py
+++ b/Lib/test/test_time.py
@@ -680,6 +680,15 @@ class CPyTimeTestCase:
"""
OVERFLOW_SECONDS = None
+ def setUp(self):
+ from _testcapi import SIZEOF_TIME_T
+ bits = SIZEOF_TIME_T * 8 - 1
+ self.time_t_min = -2 ** bits
+ self.time_t_max = 2 ** bits - 1
+
+ def time_t_filter(self, seconds):
+ return (self.time_t_min <= seconds <= self.time_t_max)
+
def _rounding_values(self, use_float):
"Build timestamps used to test rounding."
@@ -858,7 +867,7 @@ class TestCPyTime(CPyTimeTestCase, unittest.TestCase):
def seconds_filter(secs):
return LONG_MIN <= secs <= LONG_MAX
else:
- seconds_filter = None
+ seconds_filter = self.time_t_filter
self.check_int_rounding(PyTime_AsTimeval,
timeval_converter,
@@ -875,7 +884,8 @@ class TestCPyTime(CPyTimeTestCase, unittest.TestCase):
self.check_int_rounding(lambda ns, rnd: PyTime_AsTimespec(ns),
timespec_converter,
- NS_TO_SEC)
+ NS_TO_SEC,
+ value_filter=self.time_t_filter)
def test_AsMilliseconds(self):
from _testcapi import PyTime_AsMilliseconds
@@ -904,7 +914,8 @@ class TestOldPyTime(CPyTimeTestCase, unittest.TestCase):
from _testcapi import pytime_object_to_time_t
self.check_int_rounding(pytime_object_to_time_t,
- lambda secs: secs)
+ lambda secs: secs,
+ value_filter=self.time_t_filter)
self.check_float_rounding(pytime_object_to_time_t,
self.decimal_round)
@@ -928,7 +939,8 @@ class TestOldPyTime(CPyTimeTestCase, unittest.TestCase):
from _testcapi import pytime_object_to_timeval
self.check_int_rounding(pytime_object_to_timeval,
- lambda secs: (secs, 0))
+ lambda secs: (secs, 0),
+ value_filter=self.time_t_filter)
self.check_float_rounding(pytime_object_to_timeval,
self.create_converter(SEC_TO_US))
@@ -937,7 +949,8 @@ class TestOldPyTime(CPyTimeTestCase, unittest.TestCase):
from _testcapi import pytime_object_to_timespec
self.check_int_rounding(pytime_object_to_timespec,
- lambda secs: (secs, 0))
+ lambda secs: (secs, 0),
+ value_filter=self.time_t_filter)
self.check_float_rounding(pytime_object_to_timespec,
self.create_converter(SEC_TO_NS))
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index fed3286..1f013c2 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -4114,6 +4114,7 @@ PyInit__testcapi(void)
PyModule_AddObject(m, "PY_SSIZE_T_MAX", PyLong_FromSsize_t(PY_SSIZE_T_MAX));
PyModule_AddObject(m, "PY_SSIZE_T_MIN", PyLong_FromSsize_t(PY_SSIZE_T_MIN));
PyModule_AddObject(m, "SIZEOF_PYGC_HEAD", PyLong_FromSsize_t(sizeof(PyGC_Head)));
+ PyModule_AddObject(m, "SIZEOF_TIME_T", PyLong_FromSsize_t(sizeof(time_t)));
Py_INCREF(&PyInstanceMethod_Type);
PyModule_AddObject(m, "instancemethod", (PyObject *)&PyInstanceMethod_Type);