Changeset View
Changeset View
Standalone View
Standalone View
swh/model/hypothesis_strategies.py
# Copyright (C) 2019-2020 The Software Heritage developers | # Copyright (C) 2019-2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import attr | import attr | ||||
import datetime | import datetime | ||||
from hypothesis import assume | |||||
from hypothesis.strategies import ( | from hypothesis.strategies import ( | ||||
binary, builds, characters, composite, dictionaries, | binary, booleans, builds, characters, composite, dictionaries, | ||||
from_regex, integers, just, lists, none, one_of, | from_regex, integers, just, lists, none, one_of, | ||||
sampled_from, sets, text, tuples, | sampled_from, sets, 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, | ||||
OriginVisitUpdate, Snapshot, SnapshotBranch, TargetType, Release, | OriginVisitUpdate, Snapshot, SnapshotBranch, TargetType, Release, | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | def timestamps(): | ||||
min_seconds = datetime.datetime.min.replace( | min_seconds = datetime.datetime.min.replace( | ||||
tzinfo=datetime.timezone.utc).timestamp() | tzinfo=datetime.timezone.utc).timestamp() | ||||
return builds( | return builds( | ||||
Timestamp, | Timestamp, | ||||
seconds=integers(min_seconds, max_seconds), | seconds=integers(min_seconds, max_seconds), | ||||
microseconds=integers(0, 1000000)) | microseconds=integers(0, 1000000)) | ||||
def timestamps_with_timezone(): | @composite | ||||
return builds( | def timestamps_with_timezone( | ||||
TimestampWithTimezone, | draw, | ||||
timestamp=timestamps(), | timestamp=timestamps(), | ||||
offset=integers(min_value=-14*60, max_value=14*60)) | offset=integers(min_value=-14*60, max_value=14*60), | ||||
negative_utc=booleans()): | |||||
timestamp = draw(timestamp) | |||||
offset = draw(offset) | |||||
negative_utc = draw(negative_utc) | |||||
assume(not (negative_utc and offset)) | |||||
return TimestampWithTimezone( | |||||
timestamp=timestamp, | |||||
offset=offset, | |||||
negative_utc=negative_utc) | |||||
def origins(): | def origins(): | ||||
return builds( | return builds( | ||||
Origin, | Origin, | ||||
url=urls()) | url=urls()) | ||||
▲ Show 20 Lines • Show All 185 Lines • Show Last 20 Lines |