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
442acd02
Commit
442acd02
authored
3 years ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
TST: added tests for serialization
parent
097a2a5c
No related branches found
No related tags found
2 merge requests
!57
RELEASE 0.7.3
,
!52
F refactor high level api
Pipeline
#19931
failed
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
+33
-10
33 additions, 10 deletions
src/caosdb/high_level_api.py
unittests/test_high_level_api.py
+18
-0
18 additions, 0 deletions
unittests/test_high_level_api.py
with
51 additions
and
10 deletions
src/caosdb/high_level_api.py
+
33
−
10
View file @
442acd02
...
...
@@ -146,10 +146,16 @@ class CaosDBPythonEntity(object):
"""
Getter for the file.
"""
if
type
(
self
)
!=
CaosDBPythonFile
:
raise
RuntimeError
(
"
Please don
'
t use the file attribute for entities
"
"
that are no files.
"
)
return
self
.
_file
@
nam
e.setter
@
fil
e.setter
def
file
(
self
,
val
:
str
):
if
val
is
not
None
and
type
(
self
)
!=
CaosDBPythonFile
:
raise
RuntimeError
(
"
Please don
'
t use the file attribute for entities
"
"
that are no files.
"
)
self
.
_file
=
val
@property
...
...
@@ -157,10 +163,16 @@ class CaosDBPythonEntity(object):
"""
Getter for the path.
"""
if
type
(
self
)
!=
CaosDBPythonFile
:
raise
RuntimeError
(
"
Please don
'
t use the path attribute for entities
"
"
that are no files.
"
)
return
self
.
_path
@
name
.setter
@
path
.setter
def
path
(
self
,
val
:
str
):
if
val
is
not
None
and
type
(
self
)
!=
CaosDBPythonFile
:
raise
RuntimeError
(
"
Please don
'
t use the path attribute for entities
"
"
that are no files.
"
)
self
.
_path
=
val
@property
...
...
@@ -526,6 +538,9 @@ class CaosDBPythonEntity(object):
properties
=
dict
()
parents
=
list
()
# The full information to be returned:
fulldict
=
dict
()
for
parent
in
self
.
_parents
:
if
isinstance
(
parent
,
CaosDBPythonEntity
):
parents
.
append
(
parent
.
serialize
())
...
...
@@ -535,6 +550,15 @@ class CaosDBPythonEntity(object):
else
:
raise
RuntimeError
(
"
Incompatible class used as parent.
"
)
for
baseprop
in
(
"
name
"
,
"
id
"
,
"
description
"
,
"
version
"
):
val
=
self
.
__getattribute__
(
baseprop
)
if
val
is
not
None
:
fulldict
[
baseprop
]
=
val
if
type
(
self
)
==
CaosDBPythonFile
:
fulldict
[
"
file
"
]
=
self
.
file
fulldict
[
"
path
"
]
=
self
.
path
for
p
in
self
.
get_properties
():
m
=
self
.
get_property_metadata
(
p
)
metadata
[
p
]
=
dict
()
...
...
@@ -550,14 +574,13 @@ class CaosDBPythonEntity(object):
properties
[
p
]
=
val
.
serialize
(
without_metadata
)
else
:
properties
[
p
]
=
val
if
without_metadata
:
return
{
"
properties
"
:
properties
,
"
parents
"
:
parents
}
return
{
"
metadata
"
:
metadata
,
"
properties
"
:
properties
,
"
parents
"
:
parents
}
fulldict
[
"
properties
"
]
=
properties
fulldict
[
"
parents
"
]
=
parents
if
not
without_metadata
:
fulldict
[
"
metadata
"
]
=
metadata
return
fulldict
def
__str__
(
self
):
return
yaml
.
dump
(
self
.
serialize
(
False
))
...
...
This diff is collapsed.
Click to expand it.
unittests/test_high_level_api.py
+
18
−
0
View file @
442acd02
...
...
@@ -280,6 +280,20 @@ def test_wrong_entity_for_file():
with
pytest
.
raises
(
RuntimeError
):
obj
=
convert_to_python_object
(
r
)
def
test_serialization
():
r
=
db
.
Record
(
id
=
5
,
name
=
"
test
"
,
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
)
teststrs
=
[
"
description: ok
"
,
"
id: 5
"
,
"
datatype: INTEGER
"
,
"
importance: RECOMMENDED
"
,
"
unit: kpx
"
,
"
name: test
"
,
"
v: 15
"
]
for
teststr
in
teststrs
:
assert
teststr
in
text
def
test_files
():
# empty file:
r
=
db
.
File
()
...
...
@@ -301,3 +315,7 @@ 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