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
2597fb38
Commit
2597fb38
authored
3 years ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
ENH: initial implementaiton of deserialization done
parent
5469ff58
No related branches found
No related tags found
2 merge requests
!57
RELEASE 0.7.3
,
!52
F refactor high level api
Pipeline
#20048
canceled
3 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/high_level_api.py
+45
-1
45 additions, 1 deletion
src/caosdb/high_level_api.py
unittests/test_high_level_api.py
+33
-0
33 additions, 0 deletions
unittests/test_high_level_api.py
with
78 additions
and
1 deletion
src/caosdb/high_level_api.py
+
45
−
1
View file @
2597fb38
...
@@ -605,7 +605,51 @@ class CaosDBPythonEntity(object):
...
@@ -605,7 +605,51 @@ class CaosDBPythonEntity(object):
"""
"""
Deserialize a yaml representation of an entity in high level API form.
Deserialize a yaml representation of an entity in high level API form.
"""
"""
pass
entity
=
high_level_type_for_role
(
serialization
[
"
role
"
])()
for
parent
in
serialization
[
"
parents
"
]:
if
"
unresolved
"
in
parent
:
entity
.
add_parent
(
CaosDBPythonUnresolvedParent
(
id
=
parent
[
"
id
"
],
name
=
parent
[
"
name
"
]))
else
:
raise
NotImplementedError
()
for
baseprop
in
(
"
name
"
,
"
id
"
,
"
description
"
,
"
version
"
):
if
baseprop
in
serialization
:
entity
.
__setattr__
(
baseprop
,
serialization
[
baseprop
])
if
type
(
entity
)
==
CaosDBPythonFile
:
entity
.
file
=
serialization
[
"
file
"
]
entity
.
path
=
serialization
[
"
path
"
]
for
p
in
serialization
[
"
properties
"
]:
# The property needs to be set first:
prop
=
serialization
[
"
properties
"
][
p
]
if
isinstance
(
prop
,
dict
):
if
"
unresolved
"
in
prop
:
entity
.
__setattr__
(
p
,
CaosDBPythonUnresolvedReference
(
id
=
prop
[
"
id
"
]))
else
:
entity
.
__setattr__
(
p
,
entity
.
deserialize
(
prop
))
else
:
entity
.
__setattr__
(
p
,
prop
)
# if there is no metadata in the yaml file just initialize an empty metadata object
if
"
metadata
"
in
serialization
and
p
in
serialization
[
"
metadata
"
]:
metadata
=
serialization
[
"
metadata
"
][
p
]
propmeta
=
entity
.
get_property_metadata
(
p
)
for
f
in
fields
(
propmeta
):
if
f
.
name
in
metadata
:
propmeta
.
__setattr__
(
f
.
name
,
metadata
[
f
.
name
])
else
:
raise
NotImplementedError
()
return
entity
def
serialize
(
self
,
without_metadata
:
bool
=
False
):
def
serialize
(
self
,
without_metadata
:
bool
=
False
):
...
...
This diff is collapsed.
Click to expand it.
unittests/test_high_level_api.py
+
33
−
0
View file @
2597fb38
...
@@ -534,3 +534,36 @@ def test_type_conversion():
...
@@ -534,3 +534,36 @@ def test_type_conversion():
with
pytest
.
raises
(
RuntimeError
,
match
=
"
Incompatible type.
"
):
with
pytest
.
raises
(
RuntimeError
,
match
=
"
Incompatible type.
"
):
high_level_type_for_standard_type
(
"
ajsdkfjasfkj
"
)
high_level_type_for_standard_type
(
"
ajsdkfjasfkj
"
)
def
test_deserialization
():
r
=
db
.
Record
(
id
=
17
,
name
=
"
test
"
)
r
.
add_parent
(
"
bla
"
)
r
.
add_property
(
name
=
"
a
"
,
value
=
42
)
r
.
add_property
(
name
=
"
b
"
,
value
=
"
test
"
)
obj
=
convert_to_python_object
(
r
)
serial
=
obj
.
serialize
()
obj_des
=
CaosDBPythonEntity
.
deserialize
(
serial
)
assert
obj_des
.
name
==
"
test
"
assert
obj_des
.
id
==
17
assert
obj_des
.
has_parent
(
CaosDBPythonUnresolvedParent
(
name
=
"
bla
"
))
print
(
obj
)
print
(
obj_des
)
assert
obj
.
serialize
()
==
obj_des
.
serialize
()
f
=
db
.
File
()
f
.
file
=
"
bla.test
"
f
.
path
=
"
/test/n/bla.test
"
obj
=
convert_to_python_object
(
f
)
serial
=
obj
.
serialize
()
obj_des
=
CaosDBPythonEntity
.
deserialize
(
serial
)
assert
obj_des
.
file
==
"
bla.test
"
assert
obj_des
.
path
==
"
/test/n/bla.test
"
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