Commit 9be7226f authored by Jérome Perrin's avatar Jérome Perrin

test cleanup

parent 26b77fdd
......@@ -17,39 +17,37 @@
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
import datetime
import os
import time
import datetime
import pytest
import pytz
from freezegun import freeze_time
from ZODB.TimeStamp import TimeStamp
from zodbtools.util import TidRangeInvalid, ashex, parse_tid, parse_tidrange
from zodbtools.util import parse_tidrange, parse_tid, ashex, TidRangeInvalid
@pytest.fixture
def europe_paris_timezone():
"""Pytest's fixture to run this test with Europe/Paris as default timezone.
def fake_time():
"""Pytest's fixture to run this test as if now() was 2009-08-30T19:20:00Z
and if the machine timezone was Europe/Paris
"""
initial_tz = os.environ.get("TZ")
os.environ["TZ"] = "Europe/Paris"
time.tzset()
yield
reference_time = datetime.datetime(2009, 8, 30, 19, 20, 0, 0, pytz.utc).astimezone(
pytz.timezone("Europe/Paris")
)
with freeze_time(reference_time):
yield
del os.environ["TZ"]
if initial_tz:
os.environ["TZ"] = initial_tz
time.tzset()
# TODO: merge these fixtures in one
@pytest.fixture
def fake_time():
"""Pytest's fixture to run this test as if now() was 2009-08-30T19:20:00Z
"""
reference_time = datetime.datetime(2009, 8, 30, 19, 20, 0, 0, pytz.utc)\
.astimezone(pytz.timezone("Europe/Paris"))
with freeze_time(reference_time):
yield
def test_tidrange_tid():
assert (
......@@ -72,28 +70,23 @@ def test_tidrange_tid():
assert exc.value.args == ("invalid",)
# XXX do we need this
def test_tidrange_date(europe_paris_timezone, fake_time):
# dates in UTC
def test_tidrange_date():
assert (
b"\x03\xc4\x85v\x00\x00\x00\x00",
b"\x03\xc4\x88\xa0\x00\x00\x00\x00",
) == parse_tidrange("2018-01-01 10:30:00 UTC..2018-01-02 UTC")
# these TIDs are ZODB.TimeStamp.TimeStamp
assert (TimeStamp(2018, 1, 1, 10, 30, 0).raw(), None) == parse_tidrange(
"2018-01-01 10:30:00 UTC.."
)
import os
test_parameters = []
with open(os.path.join(os.path.dirname(__file__), "testdata", "tidrange-formats.txt")) as f:
with open(
os.path.join(os.path.dirname(__file__), "testdata", "tidrange-formats.txt")
) as f:
for line in f:
line = line.strip()
if line and not line.startswith('#'):
if line and not line.startswith("#"):
test_parameters.append(line.split(" ", 2))
@pytest.mark.parametrize("reference_time,reference_tid,input_time", test_parameters)
def test_parse_tid(europe_paris_timezone, fake_time, reference_time, reference_tid, input_time):
def test_parse_tid(fake_time, reference_time, reference_tid, input_time):
assert reference_tid == ashex(parse_tid(input_time))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment