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 | ||||
from hypothesis import given | from hypothesis import given | ||||
from swh.model.hashutil import DEFAULT_ALGORITHMS | from swh.model.hashutil import DEFAULT_ALGORITHMS | ||||
from swh.model.hypothesis_strategies import objects, object_dicts | from swh.model.hypothesis_strategies import objects, object_dicts, snapshots | ||||
from swh.model.model import TargetType | |||||
target_types = ( | target_types = ( | ||||
'content', 'directory', 'revision', 'release', 'snapshot', 'alias') | 'content', 'directory', 'revision', 'release', 'snapshot', 'alias') | ||||
@given(objects()) | @given(objects()) | ||||
def test_generation(obj_type_and_obj): | def test_generation(obj_type_and_obj): | ||||
Show All 34 Lines | if obj_type == 'content': | ||||
set(DEFAULT_ALGORITHMS) | {'length', 'status', 'data'} | set(DEFAULT_ALGORITHMS) | {'length', 'status', 'data'} | ||||
else: | else: | ||||
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(snapshots(min_size=4)) | |||||
def test_generated_snapshot_branch_alias(snapshot): | |||||
for name, branch in snapshot.branches.items(): | |||||
if branch and branch.target_type == TargetType.ALIAS: | |||||
assert branch.target in snapshot.branches | |||||
alias_target = snapshot.branches[branch.target] | |||||
assert not alias_target or alias_target.target != name |