Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/strategies.py
Show First 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | |||||
def content_image_type(): | def content_image_type(): | ||||
""" | """ | ||||
Hypothesis strategy returning random image contents ingested | Hypothesis strategy returning random image contents ingested | ||||
into the test archive. | into the test archive. | ||||
""" | """ | ||||
return content().filter(lambda c: c['mimetype'].startswith('image/')) | return content().filter(lambda c: c['mimetype'].startswith('image/')) | ||||
def content_utf8_detected_as_binary(): | |||||
""" | |||||
Hypothesis strategy returning random textual contents detected as binary | |||||
by libmagic while they are valid UTF-8 encoded files. | |||||
""" | |||||
def utf8_binary_detected(content): | |||||
if content['encoding'] != 'binary': | |||||
return False | |||||
try: | |||||
content['data'].decode('utf-8') | |||||
except Exception: | |||||
return False | |||||
else: | |||||
return True | |||||
return content().filter(utf8_binary_detected) | |||||
@composite | @composite | ||||
def new_content(draw): | def new_content(draw): | ||||
blake2s256_hex = draw(sha256()) | blake2s256_hex = draw(sha256()) | ||||
sha1_hex = draw(sha1()) | sha1_hex = draw(sha1()) | ||||
sha1_git_hex = draw(sha1()) | sha1_git_hex = draw(sha1()) | ||||
sha256_hex = draw(sha256()) | sha256_hex = draw(sha256()) | ||||
assume(sha1_hex != sha1_git_hex) | assume(sha1_hex != sha1_git_hex) | ||||
▲ Show 20 Lines • Show All 382 Lines • Show Last 20 Lines |