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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-pylib
Commits
9b3d756a
Commit
9b3d756a
authored
1 year ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
FIX: compare_entities now raises an error when trying to compare abstract properties directly
parent
ab379939
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!107
ENH: add entity getters and cached functions
,
!103
Improving the compare_entities functions
Pipeline
#36396
passed with warnings
1 year ago
Stage: code_style
Stage: linting
Stage: test
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/caosdb/apiutils.py
+7
-1
7 additions, 1 deletion
src/caosdb/apiutils.py
unittests/test_apiutils.py
+11
-36
11 additions, 36 deletions
unittests/test_apiutils.py
with
18 additions
and
37 deletions
src/caosdb/apiutils.py
+
7
−
1
View file @
9b3d756a
...
...
@@ -219,7 +219,7 @@ def compare_entities(old_entity: Entity, new_entity: Entity,
of circular references).
NOTE: This function does not work for abstract properties! I.e. it is not possible
to directly compare two entities that are of class db.Property.
to directly compare two entities that are of class
caos
db.Property.
Parameters
----------
...
...
@@ -233,6 +233,12 @@ def compare_entities(old_entity: Entity, new_entity: Entity,
identical records are stored in different objects. Default is False.
"""
for
entity
in
(
old_entity
,
new_entity
):
if
isinstance
(
entity
,
Property
):
raise
NotImplementedError
(
"
The function compare_entities does not work for
"
"
comparing abstract properties.
"
)
olddiff
:
Dict
[
str
,
Any
]
=
{
"
properties
"
:
{},
"
parents
"
:
[]}
newdiff
:
Dict
[
str
,
Any
]
=
{
"
properties
"
:
{},
"
parents
"
:
[]}
...
...
This diff is collapsed.
Click to expand it.
unittests/test_apiutils.py
+
11
−
36
View file @
9b3d756a
...
...
@@ -130,6 +130,10 @@ def test_compare_entities():
assert
"
tests_234234
"
in
diff_r1
[
"
properties
"
]
assert
"
tests_TT
"
in
diff_r2
[
"
properties
"
]
# Check the value:
assert
diff_r1
[
"
properties
"
][
"
tests
"
][
"
value
"
]
==
3
assert
diff_r2
[
"
properties
"
][
"
tests
"
][
"
value
"
]
==
45
def
test_compare_equality
():
r1
=
db
.
Record
()
r2
=
db
.
Record
()
...
...
@@ -187,6 +191,10 @@ def test_compare_entities_units():
assert
diff_r1
[
"
properties
"
][
"
test
"
][
"
unit
"
]
==
"
cm
"
assert
diff_r2
[
"
properties
"
][
"
test
"
][
"
unit
"
]
==
"
m
"
# Check the value:
assert
diff_r1
[
"
properties
"
][
"
tests
"
][
"
value
"
]
==
3
assert
diff_r2
[
"
properties
"
][
"
tests
"
][
"
value
"
]
==
45
def
test_compare_special_properties
():
# Test for all known special properties:
...
...
@@ -247,46 +255,13 @@ def test_compare_importances():
assert
len
(
diff
[
"
parents
"
])
==
0
@pytest.mark.xfail
def
test_compare_properties
():
p1
=
db
.
Property
()
p2
=
db
.
Property
()
diff_r1
,
diff_r2
=
compare_entities
(
p1
,
p2
)
assert
len
(
diff_r1
[
"
parents
"
])
==
0
assert
len
(
diff_r2
[
"
parents
"
])
==
0
assert
len
(
diff_r1
[
"
properties
"
])
==
0
assert
len
(
diff_r2
[
"
properties
"
])
==
0
p1
.
importance
=
"
SUGGESTED
"
diff_r1
,
diff_r2
=
compare_entities
(
p1
,
p2
)
assert
len
(
diff_r1
[
"
parents
"
])
==
0
assert
len
(
diff_r2
[
"
parents
"
])
==
0
assert
len
(
diff_r1
[
"
properties
"
])
==
0
assert
len
(
diff_r2
[
"
properties
"
])
==
0
assert
"
importance
"
in
diff_r1
assert
diff_r1
[
"
importance
"
]
==
"
SUGGESTED
"
# TODO: I'm not sure why it is not like this:
# assert diff_r2["importance"] is None
# ... but:
assert
"
importance
"
not
in
diff_r2
p2
.
importance
=
"
SUGGESTED
"
p1
.
value
=
42
p2
.
value
=
4
diff_r1
,
diff_r2
=
compare_entities
(
p1
,
p2
)
assert
len
(
diff_r1
[
"
parents
"
])
==
0
assert
len
(
diff_r2
[
"
parents
"
])
==
0
assert
len
(
diff_r1
[
"
properties
"
])
==
0
assert
len
(
diff_r2
[
"
properties
"
])
==
0
# Comparing values currently does not seem to be implemented:
assert
"
value
"
in
diff_r1
assert
diff_r1
[
"
value
"
]
==
42
assert
"
value
"
in
diff_r2
assert
diff_r2
[
"
value
"
]
==
4
with
pytest
.
raises
(
NotImplementedError
,
match
=
"
.*abstract properties.*
"
):
compare_entities
(
p1
,
p2
)
def
test_copy_entities
():
...
...
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