Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/strategies.py
Show All 10 Lines | |||||
from hypothesis import settings, assume | from hypothesis import settings, assume | ||||
from hypothesis.strategies import ( | from hypothesis.strategies import ( | ||||
just, sampled_from, lists, composite, datetimes, | just, sampled_from, lists, composite, datetimes, | ||||
binary, text, characters | binary, text, characters | ||||
) | ) | ||||
from swh.model.hashutil import hash_to_hex, hash_to_bytes | from swh.model.hashutil import hash_to_hex, hash_to_bytes | ||||
from swh.model.identifiers import directory_identifier | from swh.model.identifiers import directory_identifier | ||||
from swh.model.model import Person, Revision, TimestampWithTimezone | from swh.model.model import ( | ||||
Person, Revision, RevisionType, TimestampWithTimezone | |||||
) | |||||
from swh.storage.algos.revisions_walker import get_revisions_walker | from swh.storage.algos.revisions_walker import get_revisions_walker | ||||
from swh.model.hypothesis_strategies import ( | from swh.model.hypothesis_strategies import ( | ||||
origins as new_origin_strategy, snapshots as new_snapshot | origins as new_origin_strategy, snapshots as new_snapshot | ||||
) | ) | ||||
from swh.web.tests.data import get_tests_data | from swh.web.tests.data import get_tests_data | ||||
# Module dedicated to the generation of input data for tests through | # Module dedicated to the generation of input data for tests through | ||||
# the use of hypothesis. | # the use of hypothesis. | ||||
▲ Show 20 Lines • Show All 333 Lines • ▼ Show 20 Lines | return Revision( | ||||
author=draw(new_person()), | author=draw(new_person()), | ||||
committer=draw(new_person()), | committer=draw(new_person()), | ||||
message=draw( | message=draw( | ||||
text(min_size=20, max_size=100).map(lambda t: t.encode())), | text(min_size=20, max_size=100).map(lambda t: t.encode())), | ||||
date=TimestampWithTimezone.from_datetime(draw(new_swh_date())), | date=TimestampWithTimezone.from_datetime(draw(new_swh_date())), | ||||
committer_date=TimestampWithTimezone.from_datetime( | committer_date=TimestampWithTimezone.from_datetime( | ||||
draw(new_swh_date())), | draw(new_swh_date())), | ||||
synthetic=False, | synthetic=False, | ||||
type='git', | type=RevisionType.GIT, | ||||
) | ) | ||||
def revisions(min_size=2, max_size=8): | def revisions(min_size=2, max_size=8): | ||||
""" | """ | ||||
Hypothesis strategy returning random revisions ingested | Hypothesis strategy returning random revisions ingested | ||||
into the test archive. | into the test archive. | ||||
""" | """ | ||||
▲ Show 20 Lines • Show All 154 Lines • Show Last 20 Lines |