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
e39e681b
Commit
e39e681b
authored
3 years ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
FIX: for missing entries in comparison
parent
2fff66ff
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!43
F fix comparison
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/caosdb/apiutils.py
+4
-4
4 additions, 4 deletions
src/caosdb/apiutils.py
unittests/test_apiutils.py
+52
-0
52 additions, 0 deletions
unittests/test_apiutils.py
with
56 additions
and
4 deletions
src/caosdb/apiutils.py
+
4
−
4
View file @
e39e681b
...
...
@@ -558,8 +558,8 @@ def getCommitIn(folder):
return
t
.
readline
().
strip
()
COMPARED
=
[
"
name
"
,
"
role
"
,
"
datatype
"
,
"
description
"
,
"
importance
"
]
COMPARED
=
[
"
name
"
,
"
role
"
,
"
datatype
"
,
"
description
"
,
"
importance
"
,
"
id
"
,
"
path
"
,
"
checksum
"
,
"
size
"
]
def
compare_entities
(
old_entity
:
Entity
,
new_entity
:
Entity
):
"""
...
...
@@ -613,7 +613,7 @@ def compare_entities(old_entity: Entity, new_entity: Entity):
if
new_entity_attr_exists
:
newdiff
[
attr
]
=
newattr
# properties
for
prop
in
old_entity
.
properties
:
...
...
@@ -653,7 +653,7 @@ def compare_entities(old_entity: Entity, new_entity: Entity):
olddiff
[
"
properties
"
].
pop
(
prop
.
name
)
else
:
raise
NotImplementedError
()
raise
NotImplementedError
(
"
Comparison not implemented for multi-properties.
"
)
for
prop
in
new_entity
.
properties
:
if
len
([
0
for
p
in
old_entity
.
properties
if
p
.
name
==
prop
.
name
])
==
0
:
...
...
This diff is collapsed.
Click to expand it.
unittests/test_apiutils.py
+
52
−
0
View file @
e39e681b
...
...
@@ -179,3 +179,55 @@ def test_compare_entities_units():
assert
diff_r1
[
"
properties
"
][
"
test
"
][
"
unit
"
]
==
"
cm
"
assert
diff_r2
[
"
properties
"
][
"
test
"
][
"
unit
"
]
==
"
m
"
def
test_compare_special_properties
():
# Test for all known special properties:
SPECIAL_PROPERTIES
=
(
"
description
"
,
"
name
"
,
"
checksum
"
,
"
size
"
,
"
path
"
,
"
id
"
)
INTS
=
(
"
size
"
,
"
id
"
)
HIDDEN
=
(
"
checksum
"
,
"
size
"
)
for
key
in
SPECIAL_PROPERTIES
:
set_key
=
key
if
key
in
HIDDEN
:
set_key
=
"
_
"
+
key
r1
=
db
.
Record
()
r2
=
db
.
Record
()
if
key
not
in
INTS
:
setattr
(
r1
,
set_key
,
"
bla 1
"
)
setattr
(
r2
,
set_key
,
"
bla 1
"
)
else
:
setattr
(
r1
,
set_key
,
1
)
setattr
(
r2
,
set_key
,
1
)
diff_r1
,
diff_r2
=
compare_entities
(
r1
,
r2
)
print
(
diff_r1
)
print
(
diff_r2
)
assert
key
not
in
diff_r1
assert
key
not
in
diff_r2
assert
len
(
diff_r1
[
"
parents
"
])
==
0
assert
len
(
diff_r2
[
"
parents
"
])
==
0
assert
len
(
diff_r1
[
"
properties
"
])
==
0
assert
len
(
diff_r2
[
"
properties
"
])
==
0
if
key
not
in
INTS
:
setattr
(
r2
,
set_key
,
"
bla test
"
)
else
:
setattr
(
r2
,
set_key
,
2
)
diff_r1
,
diff_r2
=
compare_entities
(
r1
,
r2
)
print
(
r1
)
print
(
r2
)
print
(
diff_r1
)
print
(
diff_r2
)
assert
key
in
diff_r1
assert
key
in
diff_r2
if
key
not
in
INTS
:
assert
diff_r1
[
key
]
==
"
bla 1
"
assert
diff_r2
[
key
]
==
"
bla test
"
else
:
assert
diff_r1
[
key
]
==
1
assert
diff_r2
[
key
]
==
2
assert
len
(
diff_r1
[
"
properties
"
])
==
0
assert
len
(
diff_r2
[
"
properties
"
])
==
0
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