Changeset View
Changeset View
Standalone View
Standalone View
swh/model/hypothesis_strategies.py
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | from .model import ( | ||||
Snapshot, | Snapshot, | ||||
SnapshotBranch, | SnapshotBranch, | ||||
TargetType, | TargetType, | ||||
Timestamp, | Timestamp, | ||||
TimestampWithTimezone, | TimestampWithTimezone, | ||||
) | ) | ||||
from .swhids import ExtendedObjectType, ExtendedSWHID | from .swhids import ExtendedObjectType, ExtendedSWHID | ||||
pgsql_alphabet = characters( | |||||
def pgsql_alphabet(blacklist_chars=[]): | blacklist_categories=("Cs",), blacklist_characters=["\u0000"] | ||||
pgsql_blacklist_chars = ["\u0000"] # postgresql does not like these | ) # postgresql does not like these | ||||
return characters( | |||||
blacklist_categories=("Cs",), | |||||
blacklist_characters=pgsql_blacklist_chars + blacklist_chars, | |||||
) | |||||
def optional(strategy): | def optional(strategy): | ||||
return one_of(none(), strategy) | return one_of(none(), strategy) | ||||
def pgsql_text(blacklist_chars=[]): | def pgsql_text(): | ||||
return text(alphabet=pgsql_alphabet(blacklist_chars)) | return text(alphabet=pgsql_alphabet) | ||||
def sha1_git(): | def sha1_git(): | ||||
return binary(min_size=20, max_size=20) | return binary(min_size=20, max_size=20) | ||||
def sha1(): | def sha1(): | ||||
return binary(min_size=20, max_size=20) | return binary(min_size=20, max_size=20) | ||||
▲ Show 20 Lines • Show All 193 Lines • ▼ Show 20 Lines | |||||
def revisions(): | def revisions(): | ||||
return revisions_d().map(Revision.from_dict) | return revisions_d().map(Revision.from_dict) | ||||
def directory_entries_d(): | def directory_entries_d(): | ||||
return builds( | return builds( | ||||
dict, | dict, | ||||
name=pgsql_text(blacklist_chars=["/"]).map(str.encode), | name=binary(), | ||||
target=sha1_git(), | target=sha1_git(), | ||||
type=sampled_from(["file", "dir", "rev"]), | type=sampled_from(["file", "dir", "rev"]), | ||||
perms=sampled_from([perm.value for perm in DentryPerms]), | perms=sampled_from([perm.value for perm in DentryPerms]), | ||||
) | ) | ||||
def directory_entries(): | def directory_entries(): | ||||
return directory_entries_d().map(DirectoryEntry) | return directory_entries_d().map(DirectoryEntry) | ||||
▲ Show 20 Lines • Show All 230 Lines • Show Last 20 Lines |