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
4ebec82b
Commit
4ebec82b
authored
1 year ago
by
florian
Browse files
Options
Downloads
Patches
Plain Diff
STY: autopep8'd
parent
37bb9562
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
#36807
passed
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
+2
-3
2 additions, 3 deletions
src/caosdb/apiutils.py
unittests/test_apiutils.py
+8
-4
8 additions, 4 deletions
unittests/test_apiutils.py
with
10 additions
and
7 deletions
src/caosdb/apiutils.py
+
2
−
3
View file @
4ebec82b
...
...
@@ -239,7 +239,7 @@ def compare_entities(old_entity: Entity, new_entity: 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
"
:
[]}
...
...
@@ -347,7 +347,6 @@ def compare_entities(old_entity: Entity, new_entity: Entity,
newdiff
[
"
properties
"
].
pop
(
prop
.
name
)
olddiff
[
"
properties
"
].
pop
(
prop
.
name
)
# Check whether there are missing properties in old_entity, additionally
# check for multi-properties that are currently not supported:
for
prop
in
new_entity
.
properties
:
...
...
@@ -355,7 +354,7 @@ def compare_entities(old_entity: Entity, new_entity: Entity,
if
len
(
matching
)
>
1
:
raise
NotImplementedError
(
"
Comparison not implemented for multi-properties.
"
)
if
len
([
0
for
p
in
old_entity
.
properties
if
p
.
name
==
prop
.
name
])
==
0
:
newdiff
[
"
properties
"
][
prop
.
name
]
=
{}
...
...
This diff is collapsed.
Click to expand it.
unittests/test_apiutils.py
+
8
−
4
View file @
4ebec82b
...
...
@@ -109,7 +109,8 @@ def test_compare_entities():
r1
.
add_property
(
"
tester
"
,
value
=
3
)
r2
.
add_property
(
"
tester
"
,
)
# a property where r2 has no value
r1
.
add_property
(
"
tests_234234
"
,
value
=
45
)
r2
.
add_property
(
"
tests_TT
"
,
value
=
45
)
# one additional property that the other one does not have for both
# one additional property that the other one does not have for both
r2
.
add_property
(
"
tests_TT
"
,
value
=
45
)
diff_r1
,
diff_r2
=
compare_entities
(
r1
,
r2
)
...
...
@@ -134,6 +135,7 @@ def test_compare_entities():
assert
diff_r1
[
"
properties
"
][
"
tests
"
][
"
value
"
]
==
3
assert
diff_r2
[
"
properties
"
][
"
tests
"
][
"
value
"
]
==
45
def
test_compare_equality
():
r1
=
db
.
Record
()
r2
=
db
.
Record
()
...
...
@@ -241,6 +243,7 @@ def test_compare_special_properties():
assert
len
(
diff_r1
[
"
properties
"
])
==
0
assert
len
(
diff_r2
[
"
properties
"
])
==
0
def
test_compare_importances
():
r1
=
db
.
Record
()
r2
=
db
.
Record
()
...
...
@@ -253,7 +256,7 @@ def test_compare_importances():
for
diff
in
(
diff_r1
,
diff_r2
):
assert
len
(
diff
[
"
properties
"
][
"
test
"
])
==
1
assert
len
(
diff
[
"
parents
"
])
==
0
def
test_compare_properties
():
p1
=
db
.
Property
()
...
...
@@ -262,13 +265,14 @@ 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
)
...
...
@@ -299,7 +303,7 @@ def test_multi_properties():
# 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
)
...
...
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