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
08fd228f
Commit
08fd228f
authored
4 years ago
by
vlorentz
Browse files
Options
Downloads
Patches
Plain Diff
hypothesis_strategies: Generate aware datetimes instead of naive ones.
Production should only use aware datetimes.
parent
0fad8862
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
swh/model/hypothesis_strategies.py
+9
-4
9 additions, 4 deletions
swh/model/hypothesis_strategies.py
swh/model/tests/test_hypothesis_strategies.py
+23
-1
23 additions, 1 deletion
swh/model/tests/test_hypothesis_strategies.py
with
32 additions
and
5 deletions
swh/model/hypothesis_strategies.py
+
9
−
4
View file @
08fd228f
...
...
@@ -6,6 +6,7 @@
import
datetime
from
hypothesis
import
assume
from
hypothesis.extra.dateutil
import
timezones
from
hypothesis.strategies
import
(
binary
,
booleans
,
...
...
@@ -70,6 +71,10 @@ def sha1():
return
binary
(
min_size
=
20
,
max_size
=
20
)
def
aware_datetimes
():
return
datetimes
(
timezones
=
timezones
())
@composite
def
urls
(
draw
):
protocol
=
draw
(
sampled_from
([
"
git
"
,
"
http
"
,
"
https
"
,
"
deb
"
]))
...
...
@@ -138,7 +143,7 @@ def origin_visits_d():
dict
,
visit
=
integers
(
0
,
1000
),
origin
=
urls
(),
date
=
datetimes
(),
date
=
aware_
datetimes
(),
status
=
sampled_from
([
"
ongoing
"
,
"
full
"
,
"
partial
"
]),
type
=
pgsql_text
(),
snapshot
=
optional
(
sha1_git
()),
...
...
@@ -159,7 +164,7 @@ def origin_visit_statuses_d():
visit
=
integers
(
0
,
1000
),
origin
=
urls
(),
status
=
sampled_from
([
"
ongoing
"
,
"
full
"
,
"
partial
"
]),
date
=
datetimes
(),
date
=
aware_
datetimes
(),
snapshot
=
optional
(
sha1_git
()),
metadata
=
one_of
(
none
(),
metadata_dicts
()),
)
...
...
@@ -268,7 +273,7 @@ def present_contents_d():
return
builds
(
dict
,
data
=
binary
(
max_size
=
4096
),
ctime
=
optional
(
datetimes
()),
ctime
=
optional
(
aware_
datetimes
()),
status
=
one_of
(
just
(
"
visible
"
),
just
(
"
hidden
"
)),
)
...
...
@@ -288,7 +293,7 @@ def skipped_contents_d(draw):
result
[
k
]
=
None
result
[
"
reason
"
]
=
draw
(
pgsql_text
())
result
[
"
status
"
]
=
"
absent
"
result
[
"
ctime
"
]
=
draw
(
optional
(
datetimes
()))
result
[
"
ctime
"
]
=
draw
(
optional
(
aware_
datetimes
()))
return
result
...
...
This diff is collapsed.
Click to expand it.
swh/model/tests/test_hypothesis_strategies.py
+
23
−
1
View file @
08fd228f
...
...
@@ -9,7 +9,14 @@ import attr
from
hypothesis
import
given
,
settings
from
swh.model.hashutil
import
DEFAULT_ALGORITHMS
from
swh.model.hypothesis_strategies
import
objects
,
object_dicts
,
snapshots
from
swh.model.hypothesis_strategies
import
(
objects
,
object_dicts
,
contents
,
skipped_contents
,
snapshots
,
origin_visits
,
)
from
swh.model.model
import
TargetType
...
...
@@ -125,6 +132,16 @@ def test_model_to_dicts(obj_type_and_obj):
assert
branch
is
None
or
branch
[
"
target_type
"
]
in
target_types
@given
(
contents
())
def
test_content_aware_datetime
(
cont
):
assert
cont
.
ctime
is
None
or
cont
.
ctime
.
tzinfo
is
not
None
@given
(
skipped_contents
())
def
test_skipped_content_aware_datetime
(
cont
):
assert
cont
.
ctime
is
None
or
cont
.
ctime
.
tzinfo
is
not
None
_min_snp_size
=
10
_max_snp_size
=
100
...
...
@@ -164,3 +181,8 @@ def test_snapshots_strategy(snapshot):
@settings
(
max_examples
=
1
)
def
test_snapshots_strategy_fixed_size
(
snapshot
):
assert
len
(
snapshot
.
branches
)
==
_min_snp_size
@given
(
origin_visits
())
def
test_origin_visit_aware_datetime
(
visit
):
assert
visit
.
date
.
tzinfo
is
not
None
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