Changeset View
Changeset View
Standalone View
Standalone View
swh/model/tests/test_hypothesis_strategies.py
# Copyright (C) 2019 The Software Heritage developers | # Copyright (C) 2019 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 datetime | import datetime | ||||
import attr | import attr | ||||
import iso8601 | |||||
from hypothesis import given, settings | from hypothesis import given, settings | ||||
from swh.model.hashutil import DEFAULT_ALGORITHMS | from swh.model.hashutil import DEFAULT_ALGORITHMS | ||||
from swh.model.hypothesis_strategies import ( | from swh.model.hypothesis_strategies import ( | ||||
aware_datetimes, | |||||
objects, | objects, | ||||
object_dicts, | object_dicts, | ||||
contents, | contents, | ||||
skipped_contents, | skipped_contents, | ||||
snapshots, | snapshots, | ||||
origin_visits, | origin_visits, | ||||
) | ) | ||||
from swh.model.model import TargetType | from swh.model.model import TargetType | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | if obj_type == "content": | ||||
assert False, object_ | assert False, object_ | ||||
elif obj_type == "release": | elif obj_type == "release": | ||||
assert object_["target_type"] in target_types | assert object_["target_type"] in target_types | ||||
elif obj_type == "snapshot": | elif obj_type == "snapshot": | ||||
for branch in object_["branches"].values(): | for branch in object_["branches"].values(): | ||||
assert branch is None or branch["target_type"] in target_types | assert branch is None or branch["target_type"] in target_types | ||||
@given(aware_datetimes()) | |||||
def test_datetimes(dt): | |||||
# Checks this doesn't raise an error, eg. about seconds in the TZ offset | |||||
iso8601.parse_date(dt.isoformat()) | |||||
assert dt.tzinfo is not None | |||||
@given(object_dicts(split_content=False)) | @given(object_dicts(split_content=False)) | ||||
def test_dicts_generation_merged_content(obj_type_and_obj): | def test_dicts_generation_merged_content(obj_type_and_obj): | ||||
# we should never generate a "skipped_content" here | # we should never generate a "skipped_content" here | ||||
assert obj_type_and_obj[0] != "skipped_content" | assert obj_type_and_obj[0] != "skipped_content" | ||||
@given(object_dicts(split_content=True, blacklist_types=all_but_skipped_content)) | @given(object_dicts(split_content=True, blacklist_types=all_but_skipped_content)) | ||||
def test_dicts_generation_split_content(obj_type_and_obj): | def test_dicts_generation_split_content(obj_type_and_obj): | ||||
▲ Show 20 Lines • Show All 85 Lines • Show Last 20 Lines |