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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-pylib
Commits
ca71283a
Commit
ca71283a
authored
3 years ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
FIX: compare condition
parent
2af1695f
No related branches found
No related tags found
2 merge requests
!36
RELEASE: 0.6.1
,
!35
F fix compare entities branch2
Pipeline
#16451
passed
3 years ago
Stage: code_style
Stage: linting
Stage: test
Stage: deploy
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/caosdb/apiutils.py
+6
-9
6 additions, 9 deletions
src/caosdb/apiutils.py
unittests/test_apiutils.py
+19
-7
19 additions, 7 deletions
unittests/test_apiutils.py
unittests/test_property.py
+8
-4
8 additions, 4 deletions
unittests/test_property.py
with
33 additions
and
20 deletions
src/caosdb/apiutils.py
+
6
−
9
View file @
ca71283a
...
@@ -30,15 +30,15 @@ Some simplified functions for generation of records etc.
...
@@ -30,15 +30,15 @@ Some simplified functions for generation of records etc.
import
sys
import
sys
import
tempfile
import
tempfile
from
collections.abc
import
Iterable
import
warnings
import
warnings
from
collections.abc
import
Iterable
from
subprocess
import
call
from
subprocess
import
call
from
caosdb.common.datatype
import
(
BOOLEAN
,
DATETIME
,
DOUBLE
,
FILE
,
INTEGER
,
from
caosdb.common.datatype
import
(
BOOLEAN
,
DATETIME
,
DOUBLE
,
FILE
,
INTEGER
,
REFERENCE
,
TEXT
,
is_reference
)
REFERENCE
,
TEXT
,
is_reference
)
from
caosdb.common.models
import
(
Container
,
Entity
,
File
,
Property
,
Query
,
from
caosdb.common.models
import
(
Container
,
Entity
,
File
,
Property
,
Query
,
Record
,
RecordType
,
get_config
,
Record
,
RecordType
,
execute_query
,
execute_query
)
get_config
)
def
new_record
(
record_type
,
name
=
None
,
description
=
None
,
def
new_record
(
record_type
,
name
=
None
,
description
=
None
,
...
@@ -632,16 +632,12 @@ def compare_entities(old_entity: Entity, new_entity: Entity):
...
@@ -632,16 +632,12 @@ def compare_entities(old_entity: Entity, new_entity: Entity):
newdiff
[
"
properties
"
][
prop
.
name
][
"
importance
"
]
=
\
newdiff
[
"
properties
"
][
prop
.
name
][
"
importance
"
]
=
\
new_entity
.
get_importance
(
prop
.
name
)
new_entity
.
get_importance
(
prop
.
name
)
if
((
prop
.
datatype
is
not
None
and
if
(
prop
.
datatype
!=
matching
[
0
].
datatype
):
matching
[
0
].
datatype
is
not
None
)
and
(
prop
.
datatype
!=
matching
[
0
].
datatype
)):
olddiff
[
"
properties
"
][
prop
.
name
][
"
datatype
"
]
=
prop
.
datatype
olddiff
[
"
properties
"
][
prop
.
name
][
"
datatype
"
]
=
prop
.
datatype
newdiff
[
"
properties
"
][
prop
.
name
][
"
datatype
"
]
=
\
newdiff
[
"
properties
"
][
prop
.
name
][
"
datatype
"
]
=
\
matching
[
0
].
datatype
matching
[
0
].
datatype
if
((
prop
.
value
is
not
None
and
if
(
prop
.
value
!=
matching
[
0
].
value
):
matching
[
0
].
value
is
not
None
)
and
(
prop
.
value
!=
matching
[
0
].
value
)):
olddiff
[
"
properties
"
][
prop
.
name
][
"
value
"
]
=
prop
.
value
olddiff
[
"
properties
"
][
prop
.
name
][
"
value
"
]
=
prop
.
value
newdiff
[
"
properties
"
][
prop
.
name
][
"
value
"
]
=
\
newdiff
[
"
properties
"
][
prop
.
name
][
"
value
"
]
=
\
matching
[
0
].
value
matching
[
0
].
value
...
@@ -723,6 +719,7 @@ def apply_to_ids(entities, func):
...
@@ -723,6 +719,7 @@ def apply_to_ids(entities, func):
entities : list of Entity
entities : list of Entity
func : function with one parameter.
func : function with one parameter.
"""
"""
for
entity
in
entities
:
for
entity
in
entities
:
_apply_to_ids_of_entity
(
entity
,
func
)
_apply_to_ids_of_entity
(
entity
,
func
)
...
...
This diff is collapsed.
Click to expand it.
unittests/test_apiutils.py
+
19
−
7
View file @
ca71283a
...
@@ -26,11 +26,14 @@
...
@@ -26,11 +26,14 @@
# Test apiutils
# Test apiutils
# A. Schlemmer, 02/2018
# A. Schlemmer, 02/2018
import
caosdb
as
db
import
pickle
import
pickle
import
tempfile
import
tempfile
from
caosdb.apiutils
import
apply_to_ids
,
create_id_query
,
resolve_reference
,
compare_entities
import
caosdb
as
db
import
caosdb.apiutils
import
caosdb.apiutils
from
caosdb.apiutils
import
(
apply_to_ids
,
compare_entities
,
create_id_query
,
resolve_reference
)
from
.test_property
import
testrecord
from
.test_property
import
testrecord
...
@@ -67,7 +70,8 @@ def test_apply_to_ids():
...
@@ -67,7 +70,8 @@ def test_apply_to_ids():
def
test_id_query
():
def
test_id_query
():
ids
=
[
1
,
2
,
3
,
4
,
5
]
ids
=
[
1
,
2
,
3
,
4
,
5
]
assert
create_id_query
(
ids
)
==
'
FIND ENTITY WITH ID=1 OR ID=2 OR ID=3 OR ID=4 OR ID=5
'
assert
create_id_query
(
ids
)
==
'
FIND ENTITY WITH ID=1 OR ID=2 OR ID=3 OR
'
\
'
ID=4 OR ID=5
'
def
test_resolve_reference
():
def
test_resolve_reference
():
...
@@ -77,8 +81,10 @@ def test_resolve_reference():
...
@@ -77,8 +81,10 @@ def test_resolve_reference():
prop
=
db
.
Property
(
id
=
1
,
datatype
=
db
.
REFERENCE
,
value
=
100
)
prop
=
db
.
Property
(
id
=
1
,
datatype
=
db
.
REFERENCE
,
value
=
100
)
prop
.
is_valid
=
lambda
:
True
prop
.
is_valid
=
lambda
:
True
items
=
[
200
,
300
,
400
]
items
=
[
200
,
300
,
400
]
prop_list
=
db
.
Property
(
datatype
=
db
.
LIST
(
db
.
REFERENCE
),
value
=
items
)
prop_list
=
db
.
Property
(
datatype
=
db
.
LIST
(
db
.
REFERENCE
),
prop_list2
=
db
.
Property
(
datatype
=
db
.
LIST
(
db
.
REFERENCE
),
value
=
[
db
.
Record
(
id
=
500
)])
value
=
items
)
prop_list2
=
db
.
Property
(
datatype
=
db
.
LIST
(
db
.
REFERENCE
),
value
=
[
db
.
Record
(
id
=
500
)])
resolve_reference
(
prop
)
resolve_reference
(
prop
)
resolve_reference
(
prop_list
)
resolve_reference
(
prop_list
)
resolve_reference
(
prop_list2
)
resolve_reference
(
prop_list2
)
...
@@ -86,6 +92,7 @@ def test_resolve_reference():
...
@@ -86,6 +92,7 @@ def test_resolve_reference():
assert
isinstance
(
prop
.
value
,
db
.
Entity
)
assert
isinstance
(
prop
.
value
,
db
.
Entity
)
prop_list_ids
=
[]
prop_list_ids
=
[]
for
i
in
prop_list
.
value
:
for
i
in
prop_list
.
value
:
prop_list_ids
.
append
(
i
.
id
)
prop_list_ids
.
append
(
i
.
id
)
assert
isinstance
(
i
,
db
.
Entity
)
assert
isinstance
(
i
,
db
.
Entity
)
...
@@ -114,6 +121,8 @@ def test_compare_entities():
...
@@ -114,6 +121,8 @@ def test_compare_entities():
r2
.
add_property
(
"
test
"
,
value
=
2
)
r2
.
add_property
(
"
test
"
,
value
=
2
)
r1
.
add_property
(
"
tests
"
,
value
=
3
)
r1
.
add_property
(
"
tests
"
,
value
=
3
)
r2
.
add_property
(
"
tests
"
,
value
=
45
)
r2
.
add_property
(
"
tests
"
,
value
=
45
)
r1
.
add_property
(
"
tester
"
,
value
=
3
)
r2
.
add_property
(
"
tester
"
,
)
r1
.
add_property
(
"
tests_234234
"
,
value
=
45
)
r1
.
add_property
(
"
tests_234234
"
,
value
=
45
)
r2
.
add_property
(
"
tests_TT
"
,
value
=
45
)
r2
.
add_property
(
"
tests_TT
"
,
value
=
45
)
...
@@ -121,8 +130,8 @@ def test_compare_entities():
...
@@ -121,8 +130,8 @@ def test_compare_entities():
assert
len
(
diff_r1
[
"
parents
"
])
==
1
assert
len
(
diff_r1
[
"
parents
"
])
==
1
assert
len
(
diff_r2
[
"
parents
"
])
==
0
assert
len
(
diff_r2
[
"
parents
"
])
==
0
assert
len
(
diff_r1
[
"
properties
"
])
==
2
assert
len
(
diff_r1
[
"
properties
"
])
==
3
assert
len
(
diff_r2
[
"
properties
"
])
==
2
assert
len
(
diff_r2
[
"
properties
"
])
==
3
assert
"
test
"
not
in
diff_r1
[
"
properties
"
]
assert
"
test
"
not
in
diff_r1
[
"
properties
"
]
assert
"
test
"
not
in
diff_r2
[
"
properties
"
]
assert
"
test
"
not
in
diff_r2
[
"
properties
"
]
...
@@ -130,5 +139,8 @@ def test_compare_entities():
...
@@ -130,5 +139,8 @@ def test_compare_entities():
assert
"
tests
"
in
diff_r1
[
"
properties
"
]
assert
"
tests
"
in
diff_r1
[
"
properties
"
]
assert
"
tests
"
in
diff_r2
[
"
properties
"
]
assert
"
tests
"
in
diff_r2
[
"
properties
"
]
assert
"
tester
"
in
diff_r1
[
"
properties
"
]
assert
"
tester
"
in
diff_r2
[
"
properties
"
]
assert
"
tests_234234
"
in
diff_r1
[
"
properties
"
]
assert
"
tests_234234
"
in
diff_r1
[
"
properties
"
]
assert
"
tests_TT
"
in
diff_r2
[
"
properties
"
]
assert
"
tests_TT
"
in
diff_r2
[
"
properties
"
]
This diff is collapsed.
Click to expand it.
unittests/test_property.py
+
8
−
4
View file @
ca71283a
...
@@ -24,14 +24,17 @@
...
@@ -24,14 +24,17 @@
# ** end header
# ** end header
#
#
"""
Tests for the Property class.
"""
"""
Tests for the Property class.
"""
import
os
import
caosdb
as
db
import
caosdb
as
db
from
caosdb
import
Entity
,
Property
,
Record
from
caosdb
import
Entity
,
Property
,
Record
# pylint: disable=missing-docstring
# pylint: disable=missing-docstring
from
lxml
import
etree
from
lxml
import
etree
parser
=
etree
.
XMLParser
(
remove_comments
=
True
)
parser
=
etree
.
XMLParser
(
remove_comments
=
True
)
testrecord
=
Record
.
_from_xml
(
Record
(),
testrecord
=
Record
.
_from_xml
(
etree
.
parse
(
"
unittests/test_record.xml
"
,
Record
(),
etree
.
parse
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"
test_record.xml
"
),
parser
).
getroot
())
parser
).
getroot
())
...
@@ -48,7 +51,8 @@ def test_instance_variables():
...
@@ -48,7 +51,8 @@ def test_instance_variables():
def
test_null_empty_text_value_1
():
def
test_null_empty_text_value_1
():
assert
testrecord
.
get_property
(
"
LISTofTEXT
"
).
value
==
[
"
One
"
,
"
Two
"
,
"
Three
"
,
None
,
""
]
assert
testrecord
.
get_property
(
"
LISTofTEXT
"
).
value
==
[
"
One
"
,
"
Two
"
,
"
Three
"
,
None
,
""
]
def
test_null_empty_text_value_2
():
def
test_null_empty_text_value_2
():
...
...
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