Changeset View
Changeset View
Standalone View
Standalone View
swh/model/tests/test_model.py
Show All 37 Lines | from swh.model.model import ( | ||||
RawExtrinsicMetadata, | RawExtrinsicMetadata, | ||||
Release, | Release, | ||||
Revision, | Revision, | ||||
SkippedContent, | SkippedContent, | ||||
Snapshot, | Snapshot, | ||||
TargetType, | TargetType, | ||||
Timestamp, | Timestamp, | ||||
TimestampWithTimezone, | TimestampWithTimezone, | ||||
type_validator, | optimized_validator, | ||||
) | ) | ||||
import swh.model.swhids | import swh.model.swhids | ||||
from swh.model.swhids import CoreSWHID, ExtendedSWHID, ObjectType | from swh.model.swhids import CoreSWHID, ExtendedSWHID, ObjectType | ||||
from swh.model.tests.swh_model_data import TEST_OBJECTS | from swh.model.tests.swh_model_data import TEST_OBJECTS | ||||
from swh.model.tests.test_identifiers import ( | from swh.model.tests.test_identifiers import ( | ||||
TS_DATETIMES, | TS_DATETIMES, | ||||
TS_TIMEZONES, | TS_TIMEZONES, | ||||
directory_example, | directory_example, | ||||
▲ Show 20 Lines • Show All 215 Lines • ▼ Show 20 Lines | |||||
@pytest.mark.parametrize( | @pytest.mark.parametrize( | ||||
"type_,value", | "type_,value", | ||||
[ | [ | ||||
pytest.param(type_, value, id=f"type={type_}, value={value}") | pytest.param(type_, value, id=f"type={type_}, value={value}") | ||||
for (type_, values, _) in _TYPE_VALIDATOR_PARAMETERS | for (type_, values, _) in _TYPE_VALIDATOR_PARAMETERS | ||||
for value in values | for value in values | ||||
], | ], | ||||
) | ) | ||||
def test_type_validator_valid(type_, value): | def test_optimized_type_validator_valid(type_, value): | ||||
type_validator()(None, attr.ib(type=type_), value) | validator = optimized_validator(type_) | ||||
validator(None, attr.ib(type=type_), value) | |||||
@pytest.mark.parametrize( | @pytest.mark.parametrize( | ||||
"type_,value", | "type_,value", | ||||
[ | [ | ||||
pytest.param(type_, value, id=f"type={type_}, value={value}") | pytest.param(type_, value, id=f"type={type_}, value={value}") | ||||
for (type_, _, values) in _TYPE_VALIDATOR_PARAMETERS | for (type_, _, values) in _TYPE_VALIDATOR_PARAMETERS | ||||
for value in values | for value in values | ||||
], | ], | ||||
) | ) | ||||
def test_type_validator_invalid(type_, value): | def test_optimized_type_validator_invalid(type_, value): | ||||
validator = optimized_validator(type_) | |||||
with pytest.raises(AttributeTypeError): | with pytest.raises(AttributeTypeError): | ||||
type_validator()(None, attr.ib(type=type_), value) | validator(None, attr.ib(type=type_), value) | ||||
@pytest.mark.parametrize("object_type, objects", TEST_OBJECTS.items()) | @pytest.mark.parametrize("object_type, objects", TEST_OBJECTS.items()) | ||||
def test_swh_model_todict_fromdict(object_type, objects): | def test_swh_model_todict_fromdict(object_type, objects): | ||||
"""checks model objects in swh_model_data are in correct shape""" | """checks model objects in swh_model_data are in correct shape""" | ||||
assert objects | assert objects | ||||
for obj in objects: | for obj in objects: | ||||
# Check the composition of from_dict and to_dict is the identity | # Check the composition of from_dict and to_dict is the identity | ||||
▲ Show 20 Lines • Show All 1,521 Lines • Show Last 20 Lines |