Changeset View
Changeset View
Standalone View
Standalone View
swh/model/tests/test_model.py
# Copyright (C) 2019 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 copy | import copy | ||||
import datetime | import datetime | ||||
from hypothesis import given | from hypothesis import given | ||||
from hypothesis.strategies import binary | from hypothesis.strategies import binary | ||||
import pytest | import pytest | ||||
from swh.model.model import ( | from swh.model.model import ( | ||||
Content, SkippedContent, Directory, Revision, Release, Snapshot, | Content, SkippedContent, Directory, Revision, Release, Snapshot, | ||||
Timestamp, TimestampWithTimezone, | Timestamp, TimestampWithTimezone, | ||||
MissingData, Person | MissingData, Person | ||||
) | ) | ||||
from swh.model.hashutil import hash_to_bytes, MultiHash | from swh.model.hashutil import hash_to_bytes, MultiHash | ||||
from swh.model.hypothesis_strategies import objects, origins, origin_visits | from swh.model.hypothesis_strategies import ( | ||||
objects, origins, origin_visits, origin_visit_updates | |||||
) | |||||
from swh.model.identifiers import ( | from swh.model.identifiers import ( | ||||
directory_identifier, revision_identifier, release_identifier, | directory_identifier, revision_identifier, release_identifier, | ||||
snapshot_identifier | snapshot_identifier | ||||
) | ) | ||||
from swh.model.tests.test_identifiers import ( | from swh.model.tests.test_identifiers import ( | ||||
directory_example, revision_example, release_example, snapshot_example | directory_example, revision_example, release_example, snapshot_example | ||||
) | ) | ||||
Show All 28 Lines | |||||
@given(origin_visits()) | @given(origin_visits()) | ||||
def test_todict_origin_visits(origin_visit): | def test_todict_origin_visits(origin_visit): | ||||
obj = origin_visit.to_dict() | obj = origin_visit.to_dict() | ||||
assert origin_visit == type(origin_visit).from_dict(obj) | assert origin_visit == type(origin_visit).from_dict(obj) | ||||
@given(origin_visit_updates()) | |||||
def test_todict_origin_visit_updates(origin_visit_update): | |||||
obj = origin_visit_update.to_dict() | |||||
assert origin_visit_update == type(origin_visit_update).from_dict(obj) | |||||
def test_timestampwithtimezone_from_datetime(): | def test_timestampwithtimezone_from_datetime(): | ||||
tz = datetime.timezone(datetime.timedelta(minutes=+60)) | tz = datetime.timezone(datetime.timedelta(minutes=+60)) | ||||
date = datetime.datetime( | date = datetime.datetime( | ||||
2020, 2, 27, 14, 39, 19, tzinfo=tz) | 2020, 2, 27, 14, 39, 19, tzinfo=tz) | ||||
tstz = TimestampWithTimezone.from_datetime(date) | tstz = TimestampWithTimezone.from_datetime(date) | ||||
assert tstz == TimestampWithTimezone( | assert tstz == TimestampWithTimezone( | ||||
▲ Show 20 Lines • Show All 240 Lines • Show Last 20 Lines |