Changeset View
Changeset View
Standalone View
Standalone View
swh/model/tests/test_identifiers.py
Show First 20 Lines • Show All 1,236 Lines • ▼ Show 20 Lines | ( | ||||
object_type=ObjectType.CONTENT, | object_type=ObjectType.CONTENT, | ||||
object_id=_x(HASH), | object_id=_x(HASH), | ||||
origin="https://github.com/python/cpython", | origin="https://github.com/python/cpython", | ||||
lines=(1, 18), | lines=(1, 18), | ||||
), | ), | ||||
None, # Neither does ExtendedSWHID | None, # Neither does ExtendedSWHID | ||||
), | ), | ||||
( | ( | ||||
f"swh:1:cnt:{HASH};origin=https://github.com/python/cpython;lines=1-18/", | |||||
None, # likewise | |||||
None, | |||||
None, # likewise | |||||
), | |||||
( | |||||
f"swh:1:cnt:{HASH};origin=https://github.com/python/cpython;lines=18", | f"swh:1:cnt:{HASH};origin=https://github.com/python/cpython;lines=18", | ||||
None, # likewise | None, # likewise | ||||
QualifiedSWHID( | QualifiedSWHID( | ||||
object_type=ObjectType.CONTENT, | object_type=ObjectType.CONTENT, | ||||
object_id=_x(HASH), | object_id=_x(HASH), | ||||
origin="https://github.com/python/cpython", | origin="https://github.com/python/cpython", | ||||
lines=(18, None), | lines=(18, None), | ||||
), | ), | ||||
Show All 40 Lines | @pytest.mark.parametrize( | ||||
], | ], | ||||
) | ) | ||||
def test_parse_unparse_swhids(string, core, qualified, extended): | def test_parse_unparse_swhids(string, core, qualified, extended): | ||||
"""Tests parsing and serializing valid SWHIDs with the various SWHID classes.""" | """Tests parsing and serializing valid SWHIDs with the various SWHID classes.""" | ||||
classes = [CoreSWHID, QualifiedSWHID, ExtendedSWHID] | classes = [CoreSWHID, QualifiedSWHID, ExtendedSWHID] | ||||
for (cls, parsed_swhid) in zip(classes, [core, qualified, extended]): | for (cls, parsed_swhid) in zip(classes, [core, qualified, extended]): | ||||
if parsed_swhid is None: | if parsed_swhid is None: | ||||
# This class should not accept this SWHID | # This class should not accept this SWHID | ||||
with pytest.raises(ValidationError): | with pytest.raises(ValidationError) as excinfo: | ||||
cls.from_string(string) | cls.from_string(string) | ||||
# Check string serialization for exception | |||||
assert str(excinfo.value) is not None | |||||
else: | else: | ||||
# This class should | # This class should | ||||
assert cls.from_string(string) == parsed_swhid | assert cls.from_string(string) == parsed_swhid | ||||
# Also check serialization | # Also check serialization | ||||
assert string == str(parsed_swhid) | assert string == str(parsed_swhid) | ||||
▲ Show 20 Lines • Show All 426 Lines • Show Last 20 Lines |