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
394d2f5d
Commit
394d2f5d
authored
2 years ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Plain Diff
Merge branch 'f-merge-entities' into f-copy-entity
parents
a99a3538
a73c710e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!57
RELEASE 0.7.3
,
!45
F copy entity
Pipeline
#21456
passed
2 years 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
+14
-6
14 additions, 6 deletions
src/caosdb/apiutils.py
unittests/test_apiutils.py
+68
-0
68 additions, 0 deletions
unittests/test_apiutils.py
with
82 additions
and
6 deletions
src/caosdb/apiutils.py
+
14
−
6
View file @
394d2f5d
...
...
@@ -735,14 +735,14 @@ def merge_entities(entity_a: Entity, entity_b: Entity):
for
key
in
diff_r2
[
"
properties
"
]:
if
key
in
diff_r1
[
"
properties
"
]:
if
(
"
importance
"
in
diff_r1
[
"
properties
"
][
key
]
and
"
importance
"
in
diff_r2
[
"
properties
"
][
key
]):
"
importance
"
in
diff_r2
[
"
properties
"
][
key
]):
if
(
diff_r1
[
"
properties
"
][
key
][
"
importance
"
]
!=
diff_r2
[
"
properties
"
][
key
][
"
importance
"
]):
diff_r2
[
"
properties
"
][
key
][
"
importance
"
]):
raise
NotImplementedError
()
elif
(
"
importance
"
in
diff_r1
[
"
properties
"
][
key
]
or
"
importance
"
in
diff_r2
[
"
properties
"
][
key
]):
raise
NotImplementedError
()
for
attribute
in
(
"
datatype
"
,
"
unit
"
,
"
value
"
):
if
diff_r1
[
"
properties
"
][
key
][
attribute
]
is
None
:
setattr
(
entity_a
.
get_property
(
key
),
attribute
,
...
...
@@ -750,9 +750,17 @@ def merge_entities(entity_a: Entity, entity_b: Entity):
else
:
raise
RuntimeError
(
"
Merge conflict.
"
)
else
:
entity_a
.
add_property
(
entity_b
.
get_property
(
key
),
importance
=
entity_b
.
get_importance
(
key
))
# TODO: This is a temporary FIX for
# https://gitlab.indiscale.com/caosdb/src/caosdb-pylib/-/issues/105
entity_a
.
add_property
(
id
=
entity_b
.
get_property
(
key
).
id
,
name
=
entity_b
.
get_property
(
key
).
name
,
datatype
=
entity_b
.
get_property
(
key
).
datatype
,
value
=
entity_b
.
get_property
(
key
).
value
,
unit
=
entity_b
.
get_property
(
key
).
unit
,
importance
=
entity_b
.
get_importance
(
key
))
# entity_a.add_property(
# entity_b.get_property(key),
# importance=entity_b.get_importance(key))
for
special_attribute
in
(
"
name
"
,
"
description
"
):
sa_a
=
getattr
(
entity_a
,
special_attribute
)
...
...
This diff is collapsed.
Click to expand it.
unittests/test_apiutils.py
+
68
−
0
View file @
394d2f5d
...
...
@@ -35,6 +35,8 @@ from caosdb.apiutils import (apply_to_ids, compare_entities, create_id_query,
from
.test_property
import
testrecord
import
pytest
def
test_convert_object
():
r2
=
db
.
apiutils
.
convert_to_python_object
(
testrecord
)
...
...
@@ -251,3 +253,69 @@ def test_copy_entities():
assert
c
.
properties
[
i
]
!=
r
.
properties
[
i
]
assert
c
.
properties
[
i
].
value
==
r
.
properties
[
i
].
value
assert
c
.
get_importance
(
c
.
properties
[
i
])
==
r
.
get_importance
(
r
.
properties
[
i
])
def
test_merge_entities
():
r
=
db
.
Record
(
name
=
"
A
"
)
r
.
add_parent
(
name
=
"
B
"
)
r
.
add_property
(
name
=
"
C
"
,
value
=
4
,
importance
=
"
OBLIGATORY
"
)
r
.
add_property
(
name
=
"
D
"
,
value
=
[
3
,
4
,
7
],
importance
=
"
OBLIGATORY
"
)
r
.
description
=
"
A fancy test record
"
r2
=
db
.
Record
()
r2
.
add_property
(
name
=
"
F
"
,
value
=
"
text
"
)
merge_entities
(
r2
,
r
)
assert
r2
.
get_parents
()[
0
].
name
==
"
B
"
assert
r2
.
get_property
(
"
C
"
).
name
==
"
C
"
assert
r2
.
get_property
(
"
C
"
).
value
==
4
assert
r2
.
get_property
(
"
D
"
).
name
==
"
D
"
assert
r2
.
get_property
(
"
D
"
).
value
==
[
3
,
4
,
7
]
assert
r2
.
get_property
(
"
F
"
).
name
==
"
F
"
assert
r2
.
get_property
(
"
F
"
).
value
==
"
text
"
def
test_merge_bug_109
():
rt
=
db
.
RecordType
(
name
=
"
TestBug
"
)
p
=
db
.
Property
(
name
=
"
test_bug_property
"
,
datatype
=
db
.
LIST
(
db
.
INTEGER
))
r_b
=
db
.
Record
(
name
=
"
TestRecord
"
)
r_b
.
add_parent
(
rt
)
r_b
.
add_property
(
p
,
value
=
[
18
,
19
])
r_a
=
db
.
Record
(
name
=
"
TestRecord
"
)
r_a
.
add_parent
(
rt
)
merge_entities
(
r_a
,
r_b
)
assert
r_b
.
get_property
(
"
test_bug_property
"
).
value
==
[
18
,
19
]
assert
r_a
.
get_property
(
"
test_bug_property
"
).
value
==
[
18
,
19
]
assert
"
<Value>18</Value>
\n
<Value>19</Value>
"
in
str
(
r_b
)
assert
"
<Value>18</Value>
\n
<Value>19</Value>
\n
<Value>18</Value>
\n
<Value>19</Value>
"
not
in
str
(
r_b
)
assert
"
<Value>18</Value>
\n
<Value>19</Value>
"
in
str
(
r_a
)
assert
"
<Value>18</Value>
\n
<Value>19</Value>
\n
<Value>18</Value>
\n
<Value>19</Value>
"
not
in
str
(
r_a
)
@pytest.mark.xfail
def
test_bug_109
():
rt
=
db
.
RecordType
(
name
=
"
TestBug
"
)
p
=
db
.
Property
(
name
=
"
test_bug_property
"
,
datatype
=
db
.
LIST
(
db
.
INTEGER
))
r_b
=
db
.
Record
(
name
=
"
TestRecord
"
)
r_b
.
add_parent
(
rt
)
r_b
.
add_property
(
p
,
value
=
[
18
,
19
])
r_a
=
db
.
Record
(
name
=
"
TestRecord
"
)
r_a
.
add_parent
(
rt
)
r_a
.
add_property
(
r_b
.
get_property
(
"
test_bug_property
"
))
assert
r_b
.
get_property
(
"
test_bug_property
"
).
value
==
[
18
,
19
]
assert
r_a
.
get_property
(
"
test_bug_property
"
).
value
==
[
18
,
19
]
assert
"
<Value>18</Value>
\n
<Value>19</Value>
"
in
str
(
r_b
)
assert
"
<Value>18</Value>
\n
<Value>19</Value>
\n
<Value>18</Value>
\n
<Value>19</Value>
"
not
in
str
(
r_b
)
assert
"
<Value>18</Value>
\n
<Value>19</Value>
"
in
str
(
r_a
)
assert
"
<Value>18</Value>
\n
<Value>19</Value>
\n
<Value>18</Value>
\n
<Value>19</Value>
"
not
in
str
(
r_a
)
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