Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-web
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Platform
Development
swh-web
Commits
be853cf3
Commit
be853cf3
authored
6 years ago
by
Antoine Lambert
Browse files
Options
Downloads
Patches
Plain Diff
tests.strategies: Ensure to always generate different checksums
parent
612eb319
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
swh/web/tests/strategies.py
+13
-6
13 additions, 6 deletions
swh/web/tests/strategies.py
with
13 additions
and
6 deletions
swh/web/tests/strategies.py
+
13
−
6
View file @
be853cf3
...
...
@@ -39,6 +39,16 @@ storage = tests_data['storage']
# The following strategies exploit the hypothesis capabilities
_generated_checksums
=
set
()
def
_filter_checksum
(
cs
):
if
not
int
.
from_bytes
(
cs
,
byteorder
=
'
little
'
)
or
\
cs
in
_generated_checksums
:
return
False
_generated_checksums
.
add
(
cs
)
return
True
def
_known_swh_object
(
object_type
):
return
sampled_from
(
tests_data
[
object_type
])
...
...
@@ -49,8 +59,7 @@ def sha1():
Hypothesis strategy returning a valid hexadecimal sha1 value.
"""
return
binary
(
min_size
=
20
,
max_size
=
20
).
filter
(
lambda
s
:
int
.
from_bytes
(
s
,
byteorder
=
'
little
'
)).
map
(
hash_to_hex
)
min_size
=
20
,
max_size
=
20
).
filter
(
_filter_checksum
).
map
(
hash_to_hex
)
def
invalid_sha1
():
...
...
@@ -58,8 +67,7 @@ def invalid_sha1():
Hypothesis strategy returning an invalid sha1 representation.
"""
return
binary
(
min_size
=
50
,
max_size
=
50
).
filter
(
lambda
s
:
int
.
from_bytes
(
s
,
byteorder
=
'
little
'
)).
map
(
hash_to_hex
)
min_size
=
50
,
max_size
=
50
).
filter
(
_filter_checksum
).
map
(
hash_to_hex
)
def
sha256
():
...
...
@@ -67,8 +75,7 @@ def sha256():
Hypothesis strategy returning a valid hexadecimal sha256 value.
"""
return
binary
(
min_size
=
32
,
max_size
=
32
).
filter
(
lambda
s
:
int
.
from_bytes
(
s
,
byteorder
=
'
little
'
)).
map
(
hash_to_hex
)
min_size
=
32
,
max_size
=
32
).
filter
(
_filter_checksum
).
map
(
hash_to_hex
)
def
content
():
...
...
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