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
80708974
Commit
80708974
authored
Mar 3, 2022
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
FIX: added correct handling of base attributes
parent
442acd02
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!57
RELEASE 0.7.3
,
!52
F refactor high level api
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/caosdb/high_level_api.py
+10
-11
10 additions, 11 deletions
src/caosdb/high_level_api.py
unittests/test_high_level_api.py
+33
-1
33 additions, 1 deletion
unittests/test_high_level_api.py
with
43 additions
and
12 deletions
src/caosdb/high_level_api.py
+
10
−
11
View file @
80708974
...
...
@@ -52,8 +52,6 @@ class CaosDBPropertyMetaData:
# name is already the name of the attribute
unit
:
Optional
[
str
]
=
None
datatype
:
Optional
[
str
]
=
None
file
:
Optional
[
str
]
=
None
path
:
Optional
[
str
]
=
None
description
:
Optional
[
str
]
=
None
id
:
Optional
[
int
]
=
None
importance
:
Optional
[
str
]
=
None
...
...
@@ -638,8 +636,9 @@ def _single_convert_to_python_object(robj: CaosDBPythonEntity,
Returns the input object robj.
"""
for
base_attribute
in
BASE_ATTRIBUTES
:
robj
.
__setattr__
(
base_attribute
,
entity
.
__getattribute__
(
base_attribute
))
val
=
entity
.
__getattribute__
(
base_attribute
)
if
val
is
not
None
:
robj
.
__setattr__
(
base_attribute
,
val
)
for
prop
in
entity
.
properties
:
robj
.
_set_property_from_entity
(
prop
,
entity
.
get_importance
(
prop
),
references
)
...
...
@@ -663,13 +662,13 @@ def _single_convert_to_entity(entity: db.Entity,
The CaosDBPythonEntity that is supposed to be converted to the entity.
"""
#
for base_attribute in BASE_ATTRIBUTES:
#
modified_
base_attribute
= base_attribute
#
if base_attribute in ("file", "path"):
#
modified_base_attribute = "_" + modified_
base_attribute
for
base_attribute
in
BASE_ATTRIBUTES
:
if
base_attribute
in
(
"
file
"
,
"
path
"
)
and
not
isinstance
(
robj
,
CaosDBPythonFile
):
continue
val
=
robj
.
__getattribute__
(
base_attribute
)
#
entity.__setattr__(modified_base_attribute,
#
robj
.__
g
etattr
ibute
__(base_attribute
)
)
if
val
is
not
None
:
entity
.
__
s
etattr__
(
base_attribute
,
val
)
for
parent
in
robj
.
get_parents
():
if
isinstance
(
parent
,
CaosDBPythonUnresolvedParent
):
...
...
This diff is collapsed.
Click to expand it.
unittests/test_high_level_api.py
+
33
−
1
View file @
80708974
...
...
@@ -260,6 +260,31 @@ def test_conversion_to_entity():
==
r
.
get_property
(
"
ref
"
).
value
.
get_property
(
"
a
"
).
value
)
# TODO: add more tests here
def
test_base_properties
():
r
=
db
.
Record
(
id
=
5
,
name
=
"
test
"
,
description
=
"
ok
"
)
r
.
add_property
(
name
=
"
v
"
,
value
=
15
,
datatype
=
db
.
INTEGER
,
unit
=
"
kpx
"
,
importance
=
"
RECOMMENDED
"
,
description
=
"
description
"
)
obj
=
convert_to_python_object
(
r
)
assert
obj
.
name
==
"
test
"
assert
obj
.
id
==
5
assert
obj
.
description
==
"
ok
"
metadata
=
obj
.
get_property_metadata
(
"
v
"
)
assert
metadata
.
id
is
None
assert
metadata
.
datatype
==
db
.
INTEGER
assert
metadata
.
unit
==
"
kpx
"
assert
metadata
.
importance
==
"
RECOMMENDED
"
assert
metadata
.
description
==
"
description
"
rconv
=
convert_to_entity
(
obj
)
assert
rconv
.
name
==
"
test
"
assert
rconv
.
id
==
5
assert
rconv
.
description
==
"
ok
"
prop
=
rconv
.
get_property
(
"
v
"
)
assert
prop
.
value
==
15
assert
prop
.
datatype
==
db
.
INTEGER
assert
prop
.
unit
==
"
kpx
"
assert
prop
.
description
==
"
description
"
assert
rconv
.
get_importance
(
"
v
"
)
==
"
RECOMMENDED
"
def
test_empty
():
r
=
db
.
Record
()
...
...
@@ -293,6 +318,14 @@ def test_serialization():
for
teststr
in
teststrs
:
assert
teststr
in
text
r
=
db
.
Record
(
description
=
"
ok
"
)
r
.
add_property
(
name
=
"
v
"
,
value
=
15
,
datatype
=
db
.
INTEGER
,
unit
=
"
kpx
"
,
importance
=
"
RECOMMENDED
"
)
obj
=
convert_to_python_object
(
r
)
text
=
str
(
obj
)
assert
"
name
"
not
in
text
assert
"
id
"
not
in
text
def
test_files
():
# empty file:
...
...
@@ -316,6 +349,5 @@ def test_files():
assert
obj
.
path
==
"
test.dat
"
assert
obj
.
file
==
"
/local/path/test.dat
"
print
(
obj
)
assert
"
path: test.dat
"
in
str
(
obj
)
assert
"
file: /local/path/test.dat
"
in
str
(
obj
)
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