Changeset View
Changeset View
Standalone View
Standalone View
swh/model/hypothesis_strategies.py
Show All 10 Lines | from hypothesis.strategies import ( | ||||
integers, just, lists, none, one_of, sampled_from, text, tuples, | integers, just, lists, none, one_of, sampled_from, text, tuples, | ||||
) | ) | ||||
from .from_disk import DentryPerms | from .from_disk import DentryPerms | ||||
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, SkippedContent | ||||
) | ) | ||||
from .identifiers import snapshot_identifier, identifier_to_bytes | from .identifiers import snapshot_identifier, identifier_to_bytes | ||||
pgsql_alphabet = characters( | pgsql_alphabet = characters( | ||||
blacklist_categories=('Cs', ), | blacklist_categories=('Cs', ), | ||||
blacklist_characters=['\u0000']) # postgresql does not like these | blacklist_characters=['\u0000']) # postgresql does not like these | ||||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | |||||
def directories(): | def directories(): | ||||
return builds( | return builds( | ||||
Directory, | Directory, | ||||
entries=lists(directory_entries())) | entries=lists(directory_entries())) | ||||
@composite | def contents(): | ||||
def contents(draw): | return one_of(present_contents(), skipped_contents()) | ||||
(status, data, reason) = draw(one_of( | |||||
tuples(just('visible'), binary(), none()), | |||||
tuples(just('absent'), none(), pgsql_text()), | |||||
tuples(just('hidden'), binary(), none()), | |||||
)) | |||||
@composite | |||||
ardumont: as zack said `present` is better
----
also i like `existing` but it can be ambiguous.
if it's… | |||||
def present_contents(draw): | |||||
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(), | ||||
sha256=binary(min_size=32, max_size=32), | sha256=binary(min_size=32, max_size=32), | ||||
blake2s256=binary(min_size=32, max_size=32), | blake2s256=binary(min_size=32, max_size=32), | ||||
status=just(status), | status=one_of(just('visible'), just('hidden')), | ||||
data=just(data), | data=binary(), | ||||
reason=just(reason), | )) | ||||
@composite | |||||
def skipped_contents(draw): | |||||
def optional(strategy): | |||||
return one_of(none(), strategy) | |||||
return draw(builds( | |||||
SkippedContent, | |||||
length=optional(integers(min_value=0, max_value=2**63-1)), | |||||
sha1=optional(sha1()), | |||||
sha1_git=optional(sha1_git()), | |||||
sha256=optional(binary(min_size=32, max_size=32)), | |||||
blake2s256=optional(binary(min_size=32, max_size=32)), | |||||
status=just('absent'), | |||||
reason=pgsql_text(), | |||||
)) | )) | ||||
def branch_names(): | def branch_names(): | ||||
return binary(min_size=1) | return binary(min_size=1) | ||||
def branch_targets_object(): | def branch_targets_object(): | ||||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |
as zack said present is better
also i like existing but it can be ambiguous.
if it's missing, it does not exist within the archive...
it exists for real though... like i said ambiguous.
go for present ;)