Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/strategies.py
Show First 20 Lines • Show All 217 Lines • ▼ Show 20 Lines | |||||
def directory(): | def directory(): | ||||
""" | """ | ||||
Hypothesis strategy returning a random directory ingested | Hypothesis strategy returning a random directory ingested | ||||
into the test archive. | into the test archive. | ||||
""" | """ | ||||
return _known_swh_object("directories") | return _known_swh_object("directories") | ||||
def directory_with_subdirs(): | def _directory_with_entry_type(type_): | ||||
""" | |||||
Hypothesis strategy returning a random directory containing | |||||
sub directories ingested into the test archive. | |||||
""" | |||||
return directory().filter( | return directory().filter( | ||||
lambda d: any( | lambda d: any( | ||||
[ | [ | ||||
e["type"] == "dir" | e["type"] == type_ | ||||
for e in list( | for e in list( | ||||
get_tests_data()["storage"].directory_ls(hash_to_bytes(d)) | get_tests_data()["storage"].directory_ls(hash_to_bytes(d)) | ||||
) | ) | ||||
] | ] | ||||
) | ) | ||||
) | ) | ||||
def directory_with_subdirs(): | |||||
""" | |||||
Hypothesis strategy returning a random directory containing | |||||
sub directories ingested into the test archive. | |||||
""" | |||||
return _directory_with_entry_type("dir") | |||||
def directory_with_files(): | |||||
""" | |||||
Hypothesis strategy returning a random directory containing | |||||
at least one regular file | |||||
""" | |||||
return _directory_with_entry_type("file") | |||||
def empty_directory(): | def empty_directory(): | ||||
""" | """ | ||||
Hypothesis strategy returning the empty directory ingested | Hypothesis strategy returning the empty directory ingested | ||||
into the test archive. | into the test archive. | ||||
""" | """ | ||||
return just(Directory(entries=()).id.hex()) | return just(Directory(entries=()).id.hex()) | ||||
▲ Show 20 Lines • Show All 383 Lines • Show Last 20 Lines |