Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-pylib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-pylib
Commits
d73bcf20
Commit
d73bcf20
authored
7 months ago
by
Florian Spreckelsen
Browse files
Options
Downloads
Plain Diff
Merge branch 'f-version-convenience' into 'dev'
ENH: add convenience functions See merge request
!177
parents
670ddc67
1a8c6372
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!189
ENH: add convenience functions
,
!177
ENH: add convenience functions
Pipeline
#60237
passed with warnings
7 months ago
Stage: code_style
Stage: linting
Stage: test
Stage: deploy
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.md
+1
-0
1 addition, 0 deletions
CHANGELOG.md
src/linkahead/common/models.py
+27
-0
27 additions, 0 deletions
src/linkahead/common/models.py
unittests/test_entity.py
+29
-1
29 additions, 1 deletion
unittests/test_entity.py
with
57 additions
and
1 deletion
CHANGELOG.md
+
1
−
0
View file @
d73bcf20
...
...
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ##
### Added ###
-
convenience functions
`value_matches_versionid`
,
`get_id_from_versionid`
and
`get_versionid`
### Changed ###
...
...
This diff is collapsed.
Click to expand it.
src/linkahead/common/models.py
+
27
−
0
View file @
d73bcf20
...
...
@@ -505,6 +505,10 @@ class Entity:
return self
def get_versionid(self):
"""Returns the concatenation of ID and version"""
return str(self.id)+"@"+str(self.version.id)
def get_importance(self, property): # @ReservedAssignment
"""Get the importance of a given property regarding this entity."""
...
...
@@ -2125,6 +2129,14 @@ class Property(Entity):
else:
return is_reference(self.datatype)
def value_matches_versionid(self):
"""Returns True if the value matches the pattern <id>@<version>"""
return value_matches_versionid(self.value)
def get_id_from_versionid_value(self):
"""Returns the ID part of the versionid with the pattern <id>@<version>"""
return get_id_from_versionid(self.value)
class Message(object):
...
...
@@ -5670,3 +5682,18 @@ def _filter_entity_list_by_identity(listobject: list[Entity],
if pid_none and name_match:
matches.append(candidate)
return matches
def value_matches_versionid(value: Union[int, str]):
"""Returns True if the value matches the pattern <id>@<version>"""
if isinstance(value, int):
return False
if not isinstance(value, str):
raise ValueError(f"A reference value needs to be int or str. It was {type(value)}. "
"Did you call value_matches_versionid on a non reference value?")
return "@" in value
def get_id_from_versionid(versionid: str):
"""Returns the ID part of the versionid with the pattern <id>@<version>"""
return versionid.split("@")[0]
This diff is collapsed.
Click to expand it.
unittests/test_entity.py
+
29
−
1
View file @
d73bcf20
...
...
@@ -30,7 +30,9 @@ import linkahead
from
linkahead
import
(
INTEGER
,
Entity
,
Parent
,
Property
,
Record
,
RecordType
,
configure_connection
)
import
warnings
from
linkahead.common.models
import
SPECIAL_ATTRIBUTES
from
linkahead.common.models
import
(
SPECIAL_ATTRIBUTES
,
get_id_from_versionid
,
value_matches_versionid
)
from
linkahead.common.versioning
import
Version
from
linkahead.connection.mockup
import
MockUpServerConnection
from
lxml
import
etree
from
pytest
import
raises
...
...
@@ -295,3 +297,29 @@ def test_filter_by_identity():
t
.
parents
.
filter
(
pid
=
234
)
assert
issubclass
(
w
[
-
1
].
category
,
DeprecationWarning
)
assert
"
This function was renamed
"
in
str
(
w
[
-
1
].
message
)
def
test_value_matches_versionid
():
assert
value_matches_versionid
(
234
)
is
False
,
"
integer is no version id
"
assert
value_matches_versionid
(
"
234
"
)
is
False
,
(
"
string that only contains an integer is no
"
"
version id
"
)
assert
value_matches_versionid
(
"
234@bfe1a42cb37aae8ac625a757715d38814c274158
"
)
is
True
,
(
"
integer is no version id
"
)
is
True
with
raises
(
ValueError
):
value_matches_versionid
(
234.0
)
p
=
Property
(
value
=
234
)
assert
p
.
value_matches_versionid
()
is
False
p
=
Property
(
value
=
"
234@bfe1a42cb37aae8ac625a757715d38814c274158
"
)
assert
p
.
value_matches_versionid
()
is
True
def
test_get_id_from_versionid
():
assert
get_id_from_versionid
(
"
234@bfe1a42cb37aae8ac625a757715d38814c274158
"
)
==
"
234
"
p
=
Property
(
value
=
"
234@bfe1a42cb37aae8ac625a757715d38814c274158
"
)
assert
p
.
get_id_from_versionid_value
()
==
"
234
"
def
test_get_versionid
():
e
=
Entity
(
id
=
234
)
e
.
version
=
Version
(
id
=
"
bfe1a42cb37aae8ac625a757715d38814c274158
"
)
assert
e
.
get_versionid
()
==
"
234@bfe1a42cb37aae8ac625a757715d38814c274158
"
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