Changeset View
Changeset View
Standalone View
Standalone View
swh/model/hypothesis_strategies.py
Show All 14 Lines | |||||
from .model import ( | from .model import ( | ||||
Person, Timestamp, TimestampWithTimezone, Origin, OriginVisit, | Person, Timestamp, TimestampWithTimezone, Origin, OriginVisit, | ||||
Snapshot, SnapshotBranch, TargetType, Release, Revision, | Snapshot, SnapshotBranch, TargetType, Release, Revision, | ||||
Directory, DirectoryEntry, Content | Directory, DirectoryEntry, Content | ||||
) | ) | ||||
from .identifiers import snapshot_identifier, identifier_to_bytes | from .identifiers import snapshot_identifier, identifier_to_bytes | ||||
pgsql_alphabet = characters( | |||||
blacklist_categories=('Cs', ), | |||||
blacklist_characters=['\u0000']) # postgresql does not like these | |||||
def pgsql_text(): | |||||
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 53 Lines • ▼ Show 20 Lines | rel = draw(builds( | ||||
date=none(), | date=none(), | ||||
target=sha1_git())) | target=sha1_git())) | ||||
rel.date = date | rel.date = date | ||||
rel.author = author | rel.author = author | ||||
return rel | return rel | ||||
def revision_metadata(): | def revision_metadata(): | ||||
alphabet = characters( | return dictionaries(pgsql_text(), pgsql_text()) | ||||
blacklist_categories=('Cs', ), | |||||
blacklist_characters=['\u0000']) # postgresql does not like these | |||||
return dictionaries(text(alphabet=alphabet), text(alphabet=alphabet)) | |||||
def revisions(): | def revisions(): | ||||
return builds( | return builds( | ||||
Revision, | Revision, | ||||
id=sha1_git(), | id=sha1_git(), | ||||
date=timestamps_with_timezone(), | date=timestamps_with_timezone(), | ||||
committer_date=timestamps_with_timezone(), | committer_date=timestamps_with_timezone(), | ||||
Show All 16 Lines | return builds( | ||||
id=sha1_git(), | id=sha1_git(), | ||||
entries=lists(directory_entries())) | entries=lists(directory_entries())) | ||||
@composite | @composite | ||||
def contents(draw): | def contents(draw): | ||||
(status, data, reason) = draw(one_of( | (status, data, reason) = draw(one_of( | ||||
tuples(just('visible'), binary(), none()), | tuples(just('visible'), binary(), none()), | ||||
tuples(just('absent'), none(), text()), | tuples(just('absent'), none(), pgsql_text()), | ||||
tuples(just('hidden'), none(), none()), | tuples(just('hidden'), none(), none()), | ||||
)) | )) | ||||
return draw(builds( | return draw(builds( | ||||
Content, | Content, | ||||
length=integers(min_value=0, max_value=2**63-1), | length=integers(min_value=0, max_value=2**63-1), | ||||
sha1=sha1(), | sha1=sha1(), | ||||
sha1_git=sha1_git(), | sha1_git=sha1_git(), | ||||
▲ Show 20 Lines • Show All 86 Lines • Show Last 20 Lines |