Fix minimum and maximum for datetime tests
Depending on the local timezone one could get ValueError: year 0 is out of range
This commit is contained in:
parent
f6f607ef68
commit
8cdc0b42dd
|
@ -40,21 +40,8 @@ MIN_DAYS = pdt.timedelta.min // pdt.timedelta(days=1)
|
||||||
MAX_MICROSECONDS = int(pdt.timedelta.max.total_seconds() * 1e6)
|
MAX_MICROSECONDS = int(pdt.timedelta.max.total_seconds() * 1e6)
|
||||||
MIN_MICROSECONDS = int(pdt.timedelta.min.total_seconds() * 1e6)
|
MIN_MICROSECONDS = int(pdt.timedelta.min.total_seconds() * 1e6)
|
||||||
|
|
||||||
IS_X86 = platform.architecture()[0] == "32bit"
|
MIN_DATETIME = pdt.datetime.min
|
||||||
IS_WINDOWS = sys.platform == "win32"
|
MAX_DATETIME = pdt.datetime.max
|
||||||
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)
|
|
||||||
|
|
||||||
PYPY = platform.python_implementation() == "PyPy"
|
PYPY = platform.python_implementation() == "PyPy"
|
||||||
HAS_FOLD = getattr(pdt.datetime, "fold", False)
|
HAS_FOLD = getattr(pdt.datetime, "fold", False)
|
||||||
|
@ -85,9 +72,7 @@ def test_invalid_date_fails():
|
||||||
rdt.make_date(2017, 2, 30)
|
rdt.make_date(2017, 2, 30)
|
||||||
|
|
||||||
|
|
||||||
@given(
|
@given(d=st.dates(MIN_DATETIME.date(), MAX_DATETIME.date()))
|
||||||
d=st.dates(MIN_DATETIME_FROM_TIMESTAMP.date(), MAX_DATETIME_FROM_TIMESTAMP.date())
|
|
||||||
)
|
|
||||||
def test_date_from_timestamp(d):
|
def test_date_from_timestamp(d):
|
||||||
if PYPY and d < pdt.date(1900, 1, 1):
|
if PYPY and d < pdt.date(1900, 1, 1):
|
||||||
pytest.xfail("pdt.datetime.timestamp will raise on PyPy with dates before 1900")
|
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)
|
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))
|
@example(dt=pdt.datetime(1970, 1, 2, 0, 0))
|
||||||
def test_datetime_from_timestamp(dt):
|
def test_datetime_from_timestamp(dt):
|
||||||
if PYPY and dt < pdt.datetime(1900, 1, 1):
|
if PYPY and dt < pdt.datetime(1900, 1, 1):
|
||||||
|
|
Loading…
Reference in New Issue