Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-model
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Renaud Boyer
swh-model
Commits
54957d2f
Commit
54957d2f
authored
5 years ago
by
vlorentz
Browse files
Options
Downloads
Patches
Plain Diff
Make OriginVisit use datetime for its date.
But keep support for deserializing from str, like swh-storage does.
parent
01a5d4ce
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
swh/model/model.py
+6
-3
6 additions, 3 deletions
swh/model/model.py
swh/model/tests/test_hypothesis_strategies.py
+4
-1
4 additions, 1 deletion
swh/model/tests/test_hypothesis_strategies.py
with
10 additions
and
4 deletions
swh/model/model.py
+
6
−
3
View file @
54957d2f
...
...
@@ -112,7 +112,6 @@ class OriginVisit(BaseModel):
"""
Serializes the date as a string and omits the visit id if it is
`None`.
"""
ov
=
super
().
to_dict
()
ov
[
'
date
'
]
=
str
(
self
.
date
)
if
ov
[
'
visit
'
]
is
None
:
del
ov
[
'
visit
'
]
return
ov
...
...
@@ -120,9 +119,13 @@ class OriginVisit(BaseModel):
@classmethod
def
from_dict
(
cls
,
d
):
"""
Parses the date from a string, and accepts missing visit ids.
"""
d
=
d
.
copy
()
date
=
d
.
pop
(
'
date
'
)
return
cls
(
origin
=
Origin
.
from_dict
(
d
[
'
origin
'
]),
date
=
dateutil
.
parser
.
parse
(
d
[
'
date
'
]),
origin
=
Origin
.
from_dict
(
d
.
pop
(
'
origin
'
)),
date
=
(
date
if
isinstance
(
date
,
datetime
.
datetime
)
else
dateutil
.
parser
.
parse
(
date
)),
visit
=
d
.
get
(
'
visit
'
))
...
...
This diff is collapsed.
Click to expand it.
swh/model/tests/test_hypothesis_strategies.py
+
4
−
1
View file @
54957d2f
...
...
@@ -3,6 +3,8 @@
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
import
datetime
import
attr
from
hypothesis
import
given
...
...
@@ -30,7 +32,8 @@ def assert_nested_dict(obj):
elif
isinstance
(
obj
,
list
):
for
value
in
obj
:
assert_nested_dict
(
value
)
elif
isinstance
(
obj
,
(
int
,
float
,
str
,
bytes
,
bool
,
type
(
None
))):
elif
isinstance
(
obj
,
(
int
,
float
,
str
,
bytes
,
bool
,
type
(
None
),
datetime
.
datetime
)):
pass
else
:
assert
False
,
obj
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment