Commit 574037c8 authored by Jérome Perrin's avatar Jérome Perrin

XXX WIP fixed time

parent 2b6551cd
...@@ -23,7 +23,7 @@ setup( ...@@ -23,7 +23,7 @@ setup(
install_requires = ['ZODB', 'zodburi', 'zope.interface', 'pygolang >= 0.0.0.dev6', 'six', 'dateparser'], install_requires = ['ZODB', 'zodburi', 'zope.interface', 'pygolang >= 0.0.0.dev6', 'six', 'dateparser'],
extras_require = { extras_require = {
'test': ['pytest'], 'test': ['pytest', 'freezegun', 'pytz'],
}, },
entry_points= {'console_scripts': ['zodb = zodbtools.zodb:main']}, entry_points= {'console_scripts': ['zodb = zodbtools.zodb:main']},
......
...@@ -19,10 +19,13 @@ ...@@ -19,10 +19,13 @@
import os import os
import time import time
import datetime
from pytest import raises, fixture from pytest import raises, fixture
from zodbtools.util import parse_tidrange, TidRangeInvalid, ashex import pytz
from freezegun import freeze_time
from ZODB.TimeStamp import TimeStamp from ZODB.TimeStamp import TimeStamp
from zodbtools.util import parse_tidrange, TidRangeInvalid
@fixture @fixture
def europe_paris_timezone(): def europe_paris_timezone():
...@@ -38,6 +41,15 @@ def europe_paris_timezone(): ...@@ -38,6 +41,15 @@ def europe_paris_timezone():
time.tzset() time.tzset()
@fixture
def fake_time_2001_01_01():
"""Pytest's fixture to run this test as if now() was 2001/01/01 at midnight UTC.
"""
reference_time = datetime.datetime(2001, 1, 1, 0, 0, 0, 0, pytz.utc)
with freeze_time(reference_time):
yield
def test_tidrange_tid(): def test_tidrange_tid():
assert ( assert (
b"\x00\x00\x00\x00\x00\x00\xaa\xaa", b"\x00\x00\x00\x00\x00\x00\xaa\xaa",
...@@ -59,7 +71,7 @@ def test_tidrange_tid(): ...@@ -59,7 +71,7 @@ def test_tidrange_tid():
assert exc.value.args == ("invalid",) assert exc.value.args == ("invalid",)
def test_tidrange_date(europe_paris_timezone): def test_tidrange_date(europe_paris_timezone, fake_time_2001_01_01):
# dates in UTC # dates in UTC
assert ( assert (
b"\x03\xc4\x85v\x00\x00\x00\x00", b"\x03\xc4\x85v\x00\x00\x00\x00",
...@@ -84,4 +96,6 @@ def test_tidrange_date(europe_paris_timezone): ...@@ -84,4 +96,6 @@ def test_tidrange_date(europe_paris_timezone):
) == parse_tidrange("le 1er janvier 2018 à 10h30..2018年1月2日") ) == parse_tidrange("le 1er janvier 2018 à 10h30..2018年1月2日")
# or relative dates # or relative dates
assert (b"\x039\x8e\x7f\x00\x00\x00\x00", None) == parse_tidrange("1 minute ago..")
assert (None, None) != parse_tidrange("1 month ago..yesterday") assert (None, None) != parse_tidrange("1 month ago..yesterday")
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