Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-model
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Renaud Boyer
swh-model
Commits
8e011996
Commit
8e011996
authored
4 years ago
by
vlorentz
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
swh/model/identifiers.py
+11
-0
11 additions, 0 deletions
swh/model/identifiers.py
swh/model/tests/test_identifiers.py
+12
-0
12 additions, 0 deletions
swh/model/tests/test_identifiers.py
with
23 additions
and
0 deletions
swh/model/identifiers.py
+
11
−
0
View file @
8e011996
...
...
@@ -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
):
...
...
This diff is collapsed.
Click to expand it.
swh/model/tests/test_identifiers.py
+
12
−
0
View file @
8e011996
...
...
@@ -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
"
,
[
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment