Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/algos/test_snapshot.py
# Copyright (C) 2018-2020 The Software Heritage developers | # Copyright (C) 2018-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 | ||||
from hypothesis import given | from hypothesis import HealthCheck, given, settings | ||||
import pytest | import pytest | ||||
from swh.model.hypothesis_strategies import branch_names, branch_targets, snapshots | from swh.model.hypothesis_strategies import branch_names, branch_targets, snapshots | ||||
from swh.model.model import ( | from swh.model.model import ( | ||||
OriginVisit, | OriginVisit, | ||||
OriginVisitStatus, | OriginVisitStatus, | ||||
Snapshot, | Snapshot, | ||||
SnapshotBranch, | SnapshotBranch, | ||||
Show All 12 Lines | |||||
@pytest.fixture | @pytest.fixture | ||||
def swh_storage_backend_config(): | def swh_storage_backend_config(): | ||||
yield { | yield { | ||||
"cls": "memory", | "cls": "memory", | ||||
"journal_writer": None, | "journal_writer": None, | ||||
} | } | ||||
@settings(suppress_health_check=[HealthCheck.function_scoped_fixture]) | |||||
@given(snapshot=snapshots(min_size=0, max_size=10, only_objects=False)) | @given(snapshot=snapshots(min_size=0, max_size=10, only_objects=False)) | ||||
def test_snapshot_small(swh_storage, snapshot): # noqa | def test_snapshot_small(swh_storage, snapshot): # noqa | ||||
swh_storage.snapshot_add([snapshot]) | swh_storage.snapshot_add([snapshot]) | ||||
returned_snapshot = snapshot_get_all_branches(swh_storage, snapshot.id) | returned_snapshot = snapshot_get_all_branches(swh_storage, snapshot.id) | ||||
assert snapshot == returned_snapshot | assert snapshot == returned_snapshot | ||||
@settings(suppress_health_check=[HealthCheck.function_scoped_fixture]) | |||||
@given(branch_name=branch_names(), branch_target=branch_targets(only_objects=True)) | @given(branch_name=branch_names(), branch_target=branch_targets(only_objects=True)) | ||||
def test_snapshot_large(swh_storage, branch_name, branch_target): # noqa | def test_snapshot_large(swh_storage, branch_name, branch_target): # noqa | ||||
snapshot = Snapshot( | snapshot = Snapshot( | ||||
branches={b"%s%05d" % (branch_name, i): branch_target for i in range(10000)}, | branches={b"%s%05d" % (branch_name, i): branch_target for i in range(10000)}, | ||||
) | ) | ||||
swh_storage.snapshot_add([snapshot]) | swh_storage.snapshot_add([snapshot]) | ||||
▲ Show 20 Lines • Show All 345 Lines • Show Last 20 Lines |