Skip to content
Snippets Groups Projects
Commit 8e011996 authored by vlorentz's avatar vlorentz
Browse files

Add CoreSWHID.to_extended()

This is a useful shorthand when generating SWHIDs in tests.
parent 31a8a0f2
No related branches found
No related tags found
No related merge requests found
......@@ -857,6 +857,17 @@ class CoreSWHID(_BaseSWHID[ObjectType]):
)
"""the type of object the identifier points to"""
def to_extended(self) -> ExtendedSWHID:
"""Converts this CoreSWHID into an ExtendedSWHID.
As ExtendedSWHID is a superset of CoreSWHID, this is lossless."""
return ExtendedSWHID(
namespace=self.namespace,
scheme_version=self.scheme_version,
object_type=ExtendedObjectType(self.object_type.value),
object_id=self.object_id,
)
def _parse_core_swhid(swhid: Union[str, CoreSWHID, None]) -> Optional[CoreSWHID]:
if swhid is None or isinstance(swhid, CoreSWHID):
......
......@@ -1368,6 +1368,18 @@ def test_parse_unparse_swhids(string, core, qualified, extended):
assert string == str(parsed_swhid)
@pytest.mark.parametrize(
"core,extended",
[
pytest.param(core, extended, id=string)
for (string, core, qualified, extended) in VALID_SWHIDS
if core is not None
],
)
def test_core_to_extended(core, extended):
assert core.to_extended() == extended
@pytest.mark.parametrize(
"ns,version,type,id,qualifiers",
[
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment