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
bceb49a9
Commit
bceb49a9
authored
1 year ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
ENH: added missing check for multi-properties and added corresponding test cases
parent
f70a3716
No related branches found
No related tags found
2 merge requests
!107
ENH: add entity getters and cached functions
,
!103
Improving the compare_entities functions
Pipeline
#36400
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
+9
-1
9 additions, 1 deletion
src/caosdb/apiutils.py
unittests/test_apiutils.py
+68
-0
68 additions, 0 deletions
unittests/test_apiutils.py
with
77 additions
and
1 deletion
src/caosdb/apiutils.py
+
9
−
1
View file @
bceb49a9
...
...
@@ -267,7 +267,7 @@ def compare_entities(old_entity: Entity, new_entity: Entity,
continue
if
((
old_entity_attr_exists
!=
new_entity_attr_exists
)
or
(
oldattr
!=
newattr
)):
or
(
oldattr
!=
newattr
)):
if
old_entity_attr_exists
:
olddiff
[
attr
]
=
oldattr
...
...
@@ -278,8 +278,16 @@ def compare_entities(old_entity: Entity, new_entity: Entity,
# properties
for
prop
in
old_entity
.
properties
:
# Find the corresponding property in new_entity:
matching
=
[
p
for
p
in
new_entity
.
properties
if
p
.
name
==
prop
.
name
]
# This is needed for checking for multi properties in old_entity:
# TODO: is there a better way?
matching_old
=
[
p
for
p
in
old_entity
.
properties
if
p
.
name
==
prop
.
name
]
if
len
(
matching_old
)
!=
1
:
raise
NotImplementedError
(
"
Comparison not implemented for multi-properties.
"
)
if
len
(
matching
)
==
0
:
olddiff
[
"
properties
"
][
prop
.
name
]
=
{}
elif
len
(
matching
)
==
1
:
...
...
This diff is collapsed.
Click to expand it.
unittests/test_apiutils.py
+
68
−
0
View file @
bceb49a9
...
...
@@ -261,7 +261,75 @@ def test_compare_properties():
with
pytest
.
raises
(
NotImplementedError
,
match
=
"
.*abstract properties.*
"
):
compare_entities
(
p1
,
p2
)
def
test_multi_properties
():
# This test is rather lengthy, because:
# - previously the check for multi-properties was only implemented for the
# new_entity paramter of the function.
# - Because of the API of pylib the behavior depended on the order of adding the
# properties to the records.
r1
=
db
.
Record
()
r2
=
db
.
Record
()
r1
.
add_property
(
"
test
"
,
value
=
2
)
r1
.
add_property
(
"
test
"
,
value
=
4
)
r2
.
add_property
(
"
test
"
,
value
=
2
)
# That would be expected:
# assert not empty_diff(r1, r2)
with
pytest
.
raises
(
NotImplementedError
,
match
=
"
.*multi-properties.*
"
):
compare_entities
(
r1
,
r2
)
r1
=
db
.
Record
()
r2
=
db
.
Record
()
r1
.
add_property
(
"
test
"
,
value
=
4
)
r1
.
add_property
(
"
test
"
,
value
=
2
)
r2
.
add_property
(
"
test
"
,
value
=
2
)
# That would be expected:
# assert not empty_diff(r1, r2)
with
pytest
.
raises
(
NotImplementedError
,
match
=
"
.*multi-properties.*
"
):
compare_entities
(
r1
,
r2
)
r1
=
db
.
Record
()
r2
=
db
.
Record
()
r1
.
add_property
(
"
test
"
,
value
=
4
)
r1
.
add_property
(
"
test
"
,
value
=
2
)
r2
.
add_property
(
"
test
"
,
value
=
2
)
r2
.
add_property
(
"
test
"
,
value
=
4
)
# That would be expected:
# assert empty_diff(r1, r2)
with
pytest
.
raises
(
NotImplementedError
,
match
=
"
.*multi-properties.*
"
):
compare_entities
(
r1
,
r2
)
r1
=
db
.
Record
()
r2
=
db
.
Record
()
r1
.
add_property
(
"
test
"
,
value
=
4
)
r2
.
add_property
(
"
test
"
,
value
=
4
)
r2
.
add_property
(
"
test
"
,
value
=
2
)
# That would be expected:
# assert not empty_diff(r1, r2)
with
pytest
.
raises
(
NotImplementedError
,
match
=
"
.*multi-properties.*
"
):
compare_entities
(
r1
,
r2
)
r1
=
db
.
Record
()
r2
=
db
.
Record
()
r1
.
add_property
(
"
test
"
,
value
=
4
)
r2
.
add_property
(
"
test
"
,
value
=
2
)
r2
.
add_property
(
"
test
"
,
value
=
4
)
# That would be expected:
# assert not empty_diff(r1, r2)
with
pytest
.
raises
(
NotImplementedError
,
match
=
"
.*multi-properties.*
"
):
compare_entities
(
r1
,
r2
)
r1
=
db
.
Record
()
r2
=
db
.
Record
()
r1
.
add_property
(
"
test
"
,
value
=
4
)
r1
.
add_property
(
"
test
"
,
value
=
2
)
r2
.
add_property
(
"
test
"
,
value
=
2
)
r2
.
add_property
(
"
test
"
,
value
=
5
)
# That would be expected:
# assert empty_diff(r1, r2)
with
pytest
.
raises
(
NotImplementedError
,
match
=
"
.*multi-properties.*
"
):
compare_entities
(
r1
,
r2
)
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