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
d38d3612
Commit
d38d3612
authored
3 years ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
FIX: type checking was broken
parent
031cdd39
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!57
RELEASE 0.7.3
,
!52
F refactor high level api
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/caosdb/high_level_api.py
+1
-1
1 addition, 1 deletion
src/caosdb/high_level_api.py
unittests/test_high_level_api.py
+34
-4
34 additions, 4 deletions
unittests/test_high_level_api.py
with
35 additions
and
5 deletions
src/caosdb/high_level_api.py
+
1
−
1
View file @
d38d3612
...
...
@@ -793,7 +793,7 @@ def convert_to_python_object(entity: Union[db.Container, db.Entity],
return
[
convert_to_python_object
(
i
,
references
)
for
i
in
entity
]
for
entity_type
in
entity_map
:
if
isinstanc
e
(
entity
,
entity_type
)
:
if
typ
e
(
entity
)
==
entity_type
:
# TODO: mypy fails here, the case "db.Container" is already treated above
return
_single_convert_to_python_object
(
entity_map
[
entity_type
](),
entity
,
references
)
...
...
This diff is collapsed.
Click to expand it.
unittests/test_high_level_api.py
+
34
−
4
View file @
d38d3612
...
...
@@ -28,7 +28,7 @@ import caosdb as db
from
caosdb.high_level_api
import
(
convert_to_entity
,
convert_to_python_object
)
from
caosdb.high_level_api
import
(
CaosDBPythonUnresolvedParent
,
CaosDBPythonUnresolvedReference
,
CaosDBPythonRecord
)
CaosDBPythonRecord
,
CaosDBPythonFile
)
from
caosdb.apiutils
import
compare_entities
import
pytest
...
...
@@ -247,7 +247,7 @@ def test_conversion_to_entity():
assert
equal_entities
(
r
,
rconv
)
# With
datatyp
e:
# With
a referenc
e:
r_ref
=
db
.
Record
()
r_ref
.
add_parent
(
"
bla
"
)
r_ref
.
add_property
(
name
=
"
a
"
,
value
=
42
)
...
...
@@ -258,5 +258,35 @@ def test_conversion_to_entity():
rconv
=
convert_to_entity
(
obj
)
assert
(
rconv
.
get_property
(
"
ref
"
).
value
.
get_property
(
"
a
"
).
value
==
r
.
get_property
(
"
ref
"
).
value
.
get_property
(
"
a
"
).
value
)
# TODO: improve compare_entities function
raise
NotImplementedError
()
# TODO: add more tests here
def
test_empty
():
r
=
db
.
Record
()
obj
=
convert_to_python_object
(
r
)
assert
isinstance
(
obj
,
CaosDBPythonRecord
)
assert
len
(
obj
.
get_properties
())
==
0
assert
len
(
obj
.
get_parents
())
==
0
rconv
=
convert_to_entity
(
obj
)
assert
len
(
rconv
.
properties
)
==
0
def
test_files
():
# empty file:
r
=
db
.
File
()
obj
=
convert_to_python_object
(
r
)
print
(
type
(
obj
))
assert
isinstance
(
obj
,
CaosDBPythonFile
)
assert
len
(
obj
.
get_properties
())
==
0
assert
len
(
obj
.
get_parents
())
==
0
rconv
=
convert_to_entity
(
obj
)
assert
len
(
rconv
.
properties
)
==
0
r
.
path
=
"
test.dat
"
r
.
file
=
"
/local/path/test.dat
"
obj
=
convert_to_python_object
(
r
)
assert
r
.
path
==
"
test.dat
"
assert
r
.
file
==
"
/local/path/test.dat
"
assert
isinstance
(
obj
,
CaosDBPythonFile
)
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