Skip to content
Snippets Groups Projects
Commit be853cf3 authored by Antoine Lambert's avatar Antoine Lambert
Browse files

tests.strategies: Ensure to always generate different checksums

parent 612eb319
No related branches found
No related tags found
No related merge requests found
......@@ -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():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment