From 8cdc0b42dda8412bacae8f921c538a932f17a059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Niederb=C3=BChl?= Date: Sat, 19 Oct 2019 17:56:39 +0200 Subject: [PATCH] Fix minimum and maximum for datetime tests Depending on the local timezone one could get ValueError: year 0 is out of range --- .../rustapi_module/tests/test_datetime.py | 23 ++++--------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/examples/rustapi_module/tests/test_datetime.py b/examples/rustapi_module/tests/test_datetime.py index 017f45e3..ce2e07b7 100644 --- a/examples/rustapi_module/tests/test_datetime.py +++ b/examples/rustapi_module/tests/test_datetime.py @@ -40,21 +40,8 @@ MIN_DAYS = pdt.timedelta.min // pdt.timedelta(days=1) MAX_MICROSECONDS = int(pdt.timedelta.max.total_seconds() * 1e6) MIN_MICROSECONDS = int(pdt.timedelta.min.total_seconds() * 1e6) -IS_X86 = platform.architecture()[0] == "32bit" -IS_WINDOWS = sys.platform == "win32" -if IS_WINDOWS: - MIN_DATETIME_FROM_TIMESTAMP = pdt.datetime.fromtimestamp(86400) - if IS_X86: - MAX_DATETIME_FROM_TIMESTAMP = pdt.datetime.fromtimestamp(32536789199) - else: - MAX_DATETIME_FROM_TIMESTAMP = pdt.datetime.fromtimestamp(32536799999) -else: - if IS_X86: - MIN_DATETIME_FROM_TIMESTAMP = pdt.datetime.fromtimestamp(-2147483648) - MAX_DATETIME_FROM_TIMESTAMP = pdt.datetime.fromtimestamp(2147483647) - else: - MIN_DATETIME_FROM_TIMESTAMP = pdt.datetime.fromtimestamp(-62135510400) - MAX_DATETIME_FROM_TIMESTAMP = pdt.datetime.fromtimestamp(253402300799) +MIN_DATETIME = pdt.datetime.min +MAX_DATETIME = pdt.datetime.max PYPY = platform.python_implementation() == "PyPy" HAS_FOLD = getattr(pdt.datetime, "fold", False) @@ -85,9 +72,7 @@ def test_invalid_date_fails(): rdt.make_date(2017, 2, 30) -@given( - d=st.dates(MIN_DATETIME_FROM_TIMESTAMP.date(), MAX_DATETIME_FROM_TIMESTAMP.date()) -) +@given(d=st.dates(MIN_DATETIME.date(), MAX_DATETIME.date())) def test_date_from_timestamp(d): if PYPY and d < pdt.date(1900, 1, 1): pytest.xfail("pdt.datetime.timestamp will raise on PyPy with dates before 1900") @@ -226,7 +211,7 @@ def test_datetime_typeerror(): rdt.make_datetime("2011", 1, 1, 0, 0, 0, 0) -@given(dt=st.datetimes(MIN_DATETIME_FROM_TIMESTAMP, MAX_DATETIME_FROM_TIMESTAMP)) +@given(dt=st.datetimes(MIN_DATETIME, MAX_DATETIME)) @example(dt=pdt.datetime(1970, 1, 2, 0, 0)) def test_datetime_from_timestamp(dt): if PYPY and dt < pdt.datetime(1900, 1, 1):