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
Labels
Merge Requests
4
Merge Requests
4
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
zodbtools
Commits
e838df83
Commit
e838df83
authored
Jan 29, 2019
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tidrange: different exceptions for TidRangeInvalid/TidInvalid
parent
77fa2e4b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
6 deletions
+25
-6
zodbtools/test/test_tidrange.py
zodbtools/test/test_tidrange.py
+18
-3
zodbtools/util.py
zodbtools/util.py
+7
-3
No files found.
zodbtools/test/test_tidrange.py
View file @
e838df83
...
...
@@ -26,7 +26,7 @@ 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
TidRangeInvalid
,
TidInvalid
,
ashex
,
parse_tid
,
parse_tidrange
@
pytest
.
fixture
...
...
@@ -64,8 +64,13 @@ def test_tidrange_tid():
assert
(
None
,
None
)
==
parse_tidrange
(
".."
)
with
pytest
.
raises
(
TidRangeInvalid
)
as
exc
:
parse_tidrange
(
"invalid"
)
assert
exc
.
value
.
args
==
(
"invalid"
,)
parse_tidrange
(
"inv.alid"
)
assert
exc
.
value
.
args
==
(
"inv.alid"
,
)
# range is correct, but a TID is invalid
with
pytest
.
raises
(
TidInvalid
)
as
exc
:
parse_tidrange
(
"invalid.."
)
assert
exc
.
value
.
args
==
(
"invalid"
,
)
def
test_tidrange_date
():
...
...
@@ -76,6 +81,16 @@ def test_tidrange_date():
"2018-01-01T10:30:00Z..2018-01-02T00:00:00.000000+00:00"
)
def
test_parse_tid
():
assert
b"
\
x00
\
x00
\
x00
\
x00
\
x00
\
x00
\
xbb
\
xbb
"
==
parse_tid
(
"000000000000bbbb"
)
with
pytest
.
raises
(
TidInvalid
)
as
exc
:
parse_tid
(
"invalid"
)
assert
exc
.
value
.
args
==
(
"invalid"
,
)
with
pytest
.
raises
(
TidInvalid
)
as
exc
:
parse_tid
(
''
)
assert
exc
.
value
.
args
==
(
''
,
)
test_parameters
=
[]
...
...
zodbtools/util.py
View file @
e838df83
...
...
@@ -63,7 +63,11 @@ def txnobjv(txn):
return
objv
# "tidmin..tidmax" -> (tidmin, tidmax)
class
TidRangeInvalid
(
Exception
):
class
TidInvalid
(
ValueError
):
pass
class
TidRangeInvalid
(
ValueError
):
pass
...
...
@@ -76,7 +80,7 @@ def parse_tid(tid_string, raw_only=False):
is invalid.
"""
if
not
tid_string
:
r
eturn
tid_string
r
aise
TidInvalid
(
tid_string
)
# If it "looks like a TID", don't try to parse it as time,
# because parsing is slow.
...
...
@@ -101,7 +105,7 @@ def parse_tid(tid_string, raw_only=False):
try
:
return
fromhex
(
tid_string
)
except
TypeError
:
raise
Tid
Range
Invalid
(
tid_string
)
raise
TidInvalid
(
tid_string
)
# build a ZODB.TimeStamp to convert as a TID
return
TimeStamp
(
...
...
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