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
c752e975
Commit
c752e975
authored
3 years ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
TST: more tests for the high level python api
parent
6901905e
No related branches found
No related tags found
2 merge requests
!57
RELEASE 0.7.3
,
!52
F refactor high level api
Pipeline
#19886
failed
3 years ago
Stage: code_style
Stage: linting
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
unittests/test_high_level_api.py
+48
-2
48 additions, 2 deletions
unittests/test_high_level_api.py
with
48 additions
and
2 deletions
unittests/test_high_level_api.py
+
48
−
2
View file @
c752e975
...
...
@@ -26,13 +26,16 @@
import
caosdb
as
db
from
caosdb.high_level_api
import
(
convert_to_entity
,
convert_to_python_object
)
from
caosdb.high_level_api
import
(
CaosDBPythonUnresolvedParent
,)
from
caosdb.high_level_api
import
(
CaosDBPythonUnresolvedParent
,
CaosDBPythonUnresolvedReference
)
import
pytest
from
lxml
import
etree
import
os
import
tempfile
import
pickle
import
sys
,
traceback
,
pdb
@pytest.fixture
def
testrecord
():
parser
=
etree
.
XMLParser
(
remove_comments
=
True
)
...
...
@@ -104,5 +107,48 @@ def test_convert_with_references():
r
=
db
.
Record
()
r
.
add_property
(
name
=
"
ref
"
,
value
=
r_ref
)
# try:
obj
=
convert_to_python_object
(
r
)
# except:
# extype, value, tb = sys.exc_info()
# traceback.print_exc()
# pdb.post_mortem(tb)
assert
obj
.
ref
.
a
==
42
# With datatype:
r_ref
=
db
.
Record
()
r_ref
.
add_parent
(
"
bla
"
)
r_ref
.
add_property
(
name
=
"
a
"
,
value
=
42
)
r
=
db
.
Record
()
r
.
add_property
(
name
=
"
ref
"
,
value
=
r_ref
)
obj
=
convert_to_python_object
(
r
)
assert
obj
.
ref
.
a
==
42
# Parent does not automatically lead to a datatype:
assert
obj
.
get_property_metadata
(
"
ref
"
).
datatype
is
None
assert
obj
.
ref
.
has_parent
(
"
bla
"
)
is
True
# Add datatype explicitely:
r_ref
=
db
.
Record
()
r_ref
.
add_parent
(
"
bla
"
)
r_ref
.
add_property
(
name
=
"
a
"
,
value
=
42
)
r
=
db
.
Record
()
r
.
add_property
(
name
=
"
ref
"
,
value
=
r_ref
,
datatype
=
"
bla
"
)
obj
=
convert_to_python_object
(
r
)
assert
obj
.
ref
.
a
==
42
# Parent does not automatically lead to a datatype:
assert
obj
.
get_property_metadata
(
"
ref
"
).
datatype
is
"
bla
"
assert
obj
.
ref
.
has_parent
(
"
bla
"
)
is
True
# Unresolved Reference:
r
=
db
.
Record
()
r
.
add_property
(
name
=
"
ref
"
,
value
=
27
,
datatype
=
"
bla
"
)
obj
=
convert_to_python_object
(
r
)
breakpoint
()
# Parent does not automatically lead to a datatype:
assert
obj
.
get_property_metadata
(
"
ref
"
).
datatype
is
"
bla
"
assert
isinstance
(
obj
.
ref
,
CaosDBPythonUnresolvedReference
)
assert
obj
.
ref
.
id
==
27
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