Changeset View
Changeset View
Standalone View
Standalone View
swh/model/hypothesis_strategies.py
Show All 28 Lines | |||||
from .from_disk import DentryPerms | from .from_disk import DentryPerms | ||||
from .identifiers import identifier_to_bytes, snapshot_identifier | from .identifiers import identifier_to_bytes, snapshot_identifier | ||||
from .model import ( | from .model import ( | ||||
BaseContent, | BaseContent, | ||||
Content, | Content, | ||||
Directory, | Directory, | ||||
DirectoryEntry, | DirectoryEntry, | ||||
ExtID, | |||||
ObjectType, | ObjectType, | ||||
Origin, | Origin, | ||||
OriginVisit, | OriginVisit, | ||||
OriginVisitStatus, | OriginVisitStatus, | ||||
Person, | Person, | ||||
Release, | Release, | ||||
Revision, | Revision, | ||||
RevisionType, | RevisionType, | ||||
▲ Show 20 Lines • Show All 237 Lines • ▼ Show 20 Lines | |||||
def contents_d(): | def contents_d(): | ||||
return one_of(present_contents_d(), skipped_contents_d()) | return one_of(present_contents_d(), skipped_contents_d()) | ||||
def contents(): | def contents(): | ||||
return one_of(present_contents(), skipped_contents()) | return one_of(present_contents(), skipped_contents()) | ||||
def extids_d(): | |||||
return builds( | |||||
dict, | |||||
target_type=sampled_from([x.value for x in ObjectType]), | |||||
target=sha1_git(), | |||||
extid_type=sampled_from(["hg", "git", "bzr"]), | |||||
extid=sha1(), | |||||
) | |||||
def extids(): | |||||
return extids_d().map(ExtID.from_dict) | |||||
def present_contents_d(): | def present_contents_d(): | ||||
return builds( | return builds( | ||||
dict, | dict, | ||||
data=binary(max_size=4096), | data=binary(max_size=4096), | ||||
ctime=optional(aware_datetimes()), | ctime=optional(aware_datetimes()), | ||||
status=one_of(just("visible"), just("hidden")), | status=one_of(just("visible"), just("hidden")), | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | def objects(blacklist_types=("origin_visit_status",), split_content=False): | ||||
strategies = [ | strategies = [ | ||||
("origin", origins), | ("origin", origins), | ||||
("origin_visit", origin_visits), | ("origin_visit", origin_visits), | ||||
("origin_visit_status", origin_visit_statuses), | ("origin_visit_status", origin_visit_statuses), | ||||
("snapshot", snapshots), | ("snapshot", snapshots), | ||||
("release", releases), | ("release", releases), | ||||
("revision", revisions), | ("revision", revisions), | ||||
("directory", directories), | ("directory", directories), | ||||
("extid", extids), | |||||
] | ] | ||||
if split_content: | if split_content: | ||||
strategies.append(("content", present_contents)) | strategies.append(("content", present_contents)) | ||||
strategies.append(("skipped_content", skipped_contents)) | strategies.append(("skipped_content", skipped_contents)) | ||||
else: | else: | ||||
strategies.append(("content", contents)) | strategies.append(("content", contents)) | ||||
args = [ | args = [ | ||||
obj_gen().map(lambda x, obj_type=obj_type: (obj_type, x)) | obj_gen().map(lambda x, obj_type=obj_type: (obj_type, x)) | ||||
Show All 17 Lines | def object_dicts(blacklist_types=("origin_visit_status",), split_content=False): | ||||
strategies = [ | strategies = [ | ||||
("origin", origins_d), | ("origin", origins_d), | ||||
("origin_visit", origin_visits_d), | ("origin_visit", origin_visits_d), | ||||
("origin_visit_status", origin_visit_statuses_d), | ("origin_visit_status", origin_visit_statuses_d), | ||||
("snapshot", snapshots_d), | ("snapshot", snapshots_d), | ||||
("release", releases_d), | ("release", releases_d), | ||||
("revision", revisions_d), | ("revision", revisions_d), | ||||
("directory", directories_d), | ("directory", directories_d), | ||||
("extid", extids_d), | |||||
] | ] | ||||
if split_content: | if split_content: | ||||
strategies.append(("content", present_contents_d)) | strategies.append(("content", present_contents_d)) | ||||
strategies.append(("skipped_content", skipped_contents_d)) | strategies.append(("skipped_content", skipped_contents_d)) | ||||
else: | else: | ||||
strategies.append(("content", contents_d)) | strategies.append(("content", contents_d)) | ||||
args = [ | args = [ | ||||
obj_gen().map(lambda x, obj_type=obj_type: (obj_type, x)) | obj_gen().map(lambda x, obj_type=obj_type: (obj_type, x)) | ||||
for (obj_type, obj_gen) in strategies | for (obj_type, obj_gen) in strategies | ||||
if obj_type not in blacklist_types | if obj_type not in blacklist_types | ||||
] | ] | ||||
return one_of(*args) | return one_of(*args) |