datetime tests: Remove Python 2 compatibility

This commit is contained in:
Alexander Niederbühl 2019-07-15 08:13:03 +02:00
parent ad0a068a38
commit f22708f140
1 changed files with 6 additions and 19 deletions

View File

@ -34,13 +34,8 @@ UTC = _get_utc()
MAX_SECONDS = int(pdt.timedelta.max.total_seconds())
MIN_SECONDS = int(pdt.timedelta.min.total_seconds())
try:
MAX_DAYS = pdt.timedelta.max // pdt.timedelta(days=1)
MIN_DAYS = pdt.timedelta.min // pdt.timedelta(days=1)
except Exception:
# Python 2 compatibility
MAX_DAYS = MAX_SECONDS // pdt.timedelta(days=1).total_seconds()
MIN_DAYS = MIN_SECONDS // pdt.timedelta(days=1).total_seconds()
MAX_DAYS = pdt.timedelta.max // pdt.timedelta(days=1)
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)
@ -64,14 +59,6 @@ else:
PYPY = platform.python_implementation() == "PyPy"
HAS_FOLD = getattr(pdt.datetime, "fold", False)
# Helper functions
get_timestamp = getattr(pdt.datetime, "timestamp", None)
if get_timestamp is None:
def get_timestamp(dt):
# Python 2 compatibility
return (dt - pdt.datetime(1970, 1, 1)).total_seconds()
xfail_date_bounds = pytest.mark.xfail(
sys.version_info < (3, 6),
@ -102,9 +89,9 @@ def test_invalid_date_fails():
MAX_DATETIME_FROM_TIMESTAMP.date()))
def test_date_from_timestamp(d):
if PYPY and d < pdt.date(1900, 1, 1):
pytest.xfail("get_timestamp will raise on PyPy with dates before 1900")
pytest.xfail("pdt.datetime.timestamp will raise on PyPy with dates before 1900")
ts = get_timestamp(pdt.datetime.combine(d, pdt.time(0)))
ts = pdt.datetime.timestamp(pdt.datetime.combine(d, pdt.time(0)))
assert rdt.date_from_timestamp(int(ts)) == pdt.date.fromtimestamp(ts)
@ -243,9 +230,9 @@ def test_datetime_typeerror():
@example(dt=pdt.datetime(1970, 1, 2, 0, 0))
def test_datetime_from_timestamp(dt):
if PYPY and dt < pdt.datetime(1900, 1, 1):
pytest.xfail("get_timestamp will raise on PyPy with dates before 1900")
pytest.xfail("pdt.datetime.timestamp will raise on PyPy with dates before 1900")
ts = get_timestamp(dt)
ts = pdt.datetime.timestamp(dt)
assert rdt.datetime_from_timestamp(ts) == pdt.datetime.fromtimestamp(ts)