Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
zodbtools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
zodbtools
Commits
f941f5fc
Commit
f941f5fc
authored
Jan 12, 2019
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test_tidrange
parent
cbbc1adb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
25 deletions
+24
-25
zodbtools/test/test_tidrange.py
zodbtools/test/test_tidrange.py
+24
-25
No files found.
zodbtools/test/test_tidrange.py
View file @
f941f5fc
...
@@ -20,14 +20,14 @@
...
@@ -20,14 +20,14 @@
import
os
import
os
import
time
import
time
import
datetime
import
datetime
from
pytest
import
raises
,
fixture
import
pytest
import
pytz
import
pytz
from
freezegun
import
freeze_time
from
freezegun
import
freeze_time
from
ZODB.TimeStamp
import
TimeStamp
from
ZODB.TimeStamp
import
TimeStamp
from
zodbtools.util
import
parse_tidrange
,
TidRangeInvalid
from
zodbtools.util
import
parse_tidrange
,
parse_tid
,
ashex
,
TidRangeInvalid
@
fixture
@
pytest
.
fixture
def
europe_paris_timezone
():
def
europe_paris_timezone
():
"""Pytest's fixture to run this test with Europe/Paris as default timezone.
"""Pytest's fixture to run this test with Europe/Paris as default timezone.
"""
"""
...
@@ -40,12 +40,13 @@ def europe_paris_timezone():
...
@@ -40,12 +40,13 @@ def europe_paris_timezone():
os
.
environ
[
"TZ"
]
=
initial_tz
os
.
environ
[
"TZ"
]
=
initial_tz
time
.
tzset
()
time
.
tzset
()
# TODO: merge these fixtures in one
@
fixture
@
pytest
.
fixture
def
fake_time
_2001_01_01
():
def
fake_time
():
"""Pytest's fixture to run this test as if now() was 200
1/01/01 at midnight UTC.
"""Pytest's fixture to run this test as if now() was 200
9-08-30T19:20:00Z
"""
"""
reference_time
=
datetime
.
datetime
(
2001
,
1
,
1
,
0
,
0
,
0
,
0
,
pytz
.
utc
)
reference_time
=
datetime
.
datetime
(
2009
,
8
,
30
,
19
,
20
,
0
,
0
,
pytz
.
utc
)
\
.
astimezone
(
pytz
.
timezone
(
"Europe/Paris"
))
with
freeze_time
(
reference_time
):
with
freeze_time
(
reference_time
):
yield
yield
...
@@ -66,12 +67,13 @@ def test_tidrange_tid():
...
@@ -66,12 +67,13 @@ def test_tidrange_tid():
assert
(
None
,
None
)
==
parse_tidrange
(
".."
)
assert
(
None
,
None
)
==
parse_tidrange
(
".."
)
with
raises
(
TidRangeInvalid
)
as
exc
:
with
pytest
.
raises
(
TidRangeInvalid
)
as
exc
:
parse_tidrange
(
"invalid"
)
parse_tidrange
(
"invalid"
)
assert
exc
.
value
.
args
==
(
"invalid"
,)
assert
exc
.
value
.
args
==
(
"invalid"
,)
def
test_tidrange_date
(
europe_paris_timezone
,
fake_time_2001_01_01
):
# XXX do we need this
def
test_tidrange_date
(
europe_paris_timezone
,
fake_time
):
# dates in UTC
# dates in UTC
assert
(
assert
(
b"
\
x03
\
xc4
\
x85
v
\
x00
\
x00
\
x00
\
x00
"
,
b"
\
x03
\
xc4
\
x85
v
\
x00
\
x00
\
x00
\
x00
"
,
...
@@ -83,19 +85,16 @@ def test_tidrange_date(europe_paris_timezone, fake_time_2001_01_01):
...
@@ -83,19 +85,16 @@ def test_tidrange_date(europe_paris_timezone, fake_time_2001_01_01):
"2018-01-01 10:30:00 UTC.."
"2018-01-01 10:30:00 UTC.."
)
)
# dates in local timezone
assert
(
b"
\
x03
\
xc4
\
x85
:
\
x00
\
x00
\
x00
\
x00
"
,
b"
\
x03
\
xc4
\
x88
d
\
x00
\
x00
\
x00
\
x00
"
,
)
==
parse_tidrange
(
"2018-01-01 10:30:00..2018-01-02"
)
# dates in natural language (also in local timezone)
assert
(
b"
\
x03
\
xc4
\
x85
:
\
x00
\
x00
\
x00
\
x00
"
,
b"
\
x03
\
xc4
\
x88
d
\
x00
\
x00
\
x00
\
x00
"
,
)
==
parse_tidrange
(
"le 1er janvier 2018 à 10h30..2018年1月2日"
)
# or relative dates
assert
(
b"
\
x03
9
\
x8e
\
x7f
\
x00
\
x00
\
x00
\
x00
"
,
None
)
==
parse_tidrange
(
"1 minute ago.."
)
assert
(
None
,
None
)
!=
parse_tidrange
(
"1 month ago..yesterday"
)
import
os
test_parameters
=
[]
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
(
'#'
):
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
):
print
(
"parsing"
,
input_time
,
"expecting"
,
reference_time
)
assert
reference_tid
==
ashex
(
parse_tid
(
input_time
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment