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
24a9f86e
Commit
24a9f86e
authored
3 years ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
ENH: enhanced utility function and added test
parent
a56e8186
No related branches found
No related tags found
2 merge requests
!57
RELEASE 0.7.3
,
!52
F refactor high level api
Pipeline
#20046
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
+31
-7
31 additions, 7 deletions
src/caosdb/high_level_api.py
unittests/test_high_level_api.py
+16
-3
16 additions, 3 deletions
unittests/test_high_level_api.py
with
47 additions
and
10 deletions
src/caosdb/high_level_api.py
+
31
−
7
View file @
24a9f86e
...
...
@@ -48,21 +48,37 @@ from datetime import datetime
from
dateutil
import
parser
def
standard_type_for_high_level_type
(
high_level_record
):
def
standard_type_for_high_level_type
(
high_level_record
:
"
CaosDBPythonEntity
"
,
return_string
:
bool
=
False
):
"""
For a given CaosDBPythonEntity either return the corresponding
class in the standard CaosDB API or - if return_string is True - return
the role as a string.
"""
if
type
(
high_level_record
)
==
CaosDBPythonRecord
:
return
db
.
Record
if
not
return_string
:
return
db
.
Record
return
"
Record
"
elif
type
(
high_level_record
)
==
CaosDBPythonFile
:
return
db
.
File
if
not
return_string
:
return
db
.
File
return
"
File
"
elif
type
(
high_level_record
)
==
CaosDBPythonProperty
:
return
db
.
Property
if
not
return_string
:
return
db
.
Property
return
"
Property
"
elif
type
(
high_level_record
)
==
CaosDBPythonRecordType
:
return
db
.
RecordType
if
not
return_string
:
return
db
.
RecordType
return
"
RecordType
"
elif
type
(
high_level_record
)
==
CaosDBPythonEntity
:
return
db
.
Entity
if
not
return_string
:
return
db
.
Entity
return
"
Entity
"
raise
RuntimeError
(
"
Incompatible type.
"
)
def
high_level_type_for_standard_type
(
standard_record
):
def
high_level_type_for_standard_type
(
standard_record
:
db
.
Entity
):
if
type
(
standard_record
)
==
db
.
Record
:
return
CaosDBPythonRecord
elif
type
(
standard_record
)
==
db
.
File
:
...
...
@@ -588,6 +604,9 @@ class CaosDBPythonEntity(object):
# The full information to be returned:
fulldict
=
dict
()
# Add CaosDB role:
for
parent
in
self
.
_parents
:
if
isinstance
(
parent
,
CaosDBPythonEntity
):
parents
.
append
(
parent
.
serialize
())
...
...
@@ -729,6 +748,11 @@ def _single_convert_to_entity(entity: db.Entity,
for
base_attribute
in
BASE_ATTRIBUTES
:
if
base_attribute
in
(
"
file
"
,
"
path
"
)
and
not
isinstance
(
robj
,
CaosDBPythonFile
):
continue
# Skip version:
if
base_attribute
==
"
version
"
:
continue
val
=
robj
.
__getattribute__
(
base_attribute
)
if
val
is
not
None
:
...
...
This diff is collapsed.
Click to expand it.
unittests/test_high_level_api.py
+
16
−
3
View file @
24a9f86e
...
...
@@ -26,10 +26,13 @@
import
caosdb
as
db
from
caosdb.high_level_api
import
(
convert_to_entity
,
convert_to_python_object
,
new_high_level_entity
_for_record_type
)
new_high_level_entity
)
from
caosdb.high_level_api
import
(
CaosDBPythonUnresolvedParent
,
CaosDBPythonUnresolvedReference
,
CaosDBPythonRecord
,
CaosDBPythonFile
)
CaosDBPythonRecord
,
CaosDBPythonFile
,
high_level_type_for_standard_type
,
standard_type_for_high_level_type
,
CaosDBPythonEntity
)
from
caosdb.apiutils
import
compare_entities
from
caosdb.common.datatype
import
(
is_list_datatype
,
...
...
@@ -413,7 +416,7 @@ def test_record_generator():
simrt
=
db
.
RecordType
(
name
=
"
SimOutput
"
)
rt
.
add_property
(
name
=
"
outputfile
"
,
datatype
=
"
SimOutput
"
)
obj
=
new_high_level_entity
_for_record_type
(
obj
=
new_high_level_entity
(
rt
,
"
SUGGESTED
"
,
""
,
True
)
print
(
obj
)
assert
False
...
...
@@ -509,3 +512,13 @@ def test_list_types():
text
=
[
line
[
4
:]
for
line
in
text
.
split
(
"
\n
"
)]
for
line
in
text2
:
assert
line
in
text
# Test utility functions:
def
test_type_conversion
():
assert
high_level_type_for_standard_type
(
db
.
Record
())
==
CaosDBPythonRecord
assert
high_level_type_for_standard_type
(
db
.
Entity
())
==
CaosDBPythonEntity
assert
standard_type_for_high_level_type
(
CaosDBPythonRecord
())
==
db
.
Record
assert
standard_type_for_high_level_type
(
CaosDBPythonEntity
())
==
db
.
Entity
assert
standard_type_for_high_level_type
(
CaosDBPythonFile
(),
True
)
==
"
File
"
assert
standard_type_for_high_level_type
(
CaosDBPythonRecord
(),
True
)
==
"
Record
"
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