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
9be7226f
Commit
9be7226f
authored
Jan 12, 2019
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test cleanup
parent
26b77fdd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
27 deletions
+20
-27
zodbtools/test/test_tidrange.py
zodbtools/test/test_tidrange.py
+20
-27
No files found.
zodbtools/test/test_tidrange.py
View file @
9be7226f
...
...
@@ -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
\
x85
v
\
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
))
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