Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
CaosDB Python Integration Tests
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 Python Integration Tests
Commits
da66ac22
Verified
Commit
da66ac22
authored
2 years ago
by
Daniel Hornung
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Test for xml (de)serialization.
parent
6ed0398a
No related branches found
No related tags found
No related merge requests found
Pipeline
#33750
failed
2 years ago
Stage: info
Stage: setup
Stage: cert
Stage: style
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_xmlparsing.py
+37
-0
37 additions, 0 deletions
tests/test_xmlparsing.py
with
37 additions
and
0 deletions
tests/test_xmlparsing.py
+
37
−
0
View file @
da66ac22
...
@@ -5,6 +5,8 @@
...
@@ -5,6 +5,8 @@
#
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
# Copyright (C) 2023 Indiscale GmbH <info@indiscale.com>
# Copyright (C) 2023 Daniel Hornung <d.hornung@indiscale.com>
#
#
# This program is free software: you can redistribute it and/or modify
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# it under the terms of the GNU Affero General Public License as
...
@@ -25,9 +27,20 @@
...
@@ -25,9 +27,20 @@
@author: tf
@author: tf
"""
"""
import
os
import
warnings
import
caosdb
as
db
import
pytest
import
pytest
def
teardown_function
(
function
):
d
=
db
.
execute_query
(
"
FIND Test*
"
)
if
len
(
d
)
>
0
:
d
.
delete
()
@pytest.mark.local_server
@pytest.mark.local_server
def
test_parse_xml
():
def
test_parse_xml
():
from
lxml
import
etree
from
lxml
import
etree
...
@@ -120,3 +133,27 @@ def test_parse_xml():
...
@@ -120,3 +133,27 @@ def test_parse_xml():
assert
isinstance
(
msg
,
Message
)
assert
isinstance
(
msg
,
Message
)
assert_equal
(
msg
.
type
.
lower
(),
tmp_msg_type
.
lower
())
assert_equal
(
msg
.
type
.
lower
(),
tmp_msg_type
.
lower
())
assert_equal
(
msg
.
body
,
tmp_msg_body
)
assert_equal
(
msg
.
body
,
tmp_msg_body
)
def
test_container_xml
(
tmp_path
):
"""
Test if after writing to xml, the result can be read without problems.
For issue 89: https://gitlab.com/caosdb/caosdb-pylib/-/issues/89
"""
with
warnings
.
catch_warnings
():
# Create XML with container with one RecordType.
db
.
RecordType
(
name
=
"
TestRT
"
).
insert
()
cont
=
db
.
execute_query
(
"
FIND RecordType TestRT
"
)
xml_file
=
os
.
path
.
join
(
tmp_path
,
"
tmp.xml
"
)
with
open
(
xml_file
,
"
w
"
,
encoding
=
"
utf-8
"
)
as
opened
:
opened
.
write
(
str
(
cont
))
# Read from file again.
with
open
(
xml_file
,
"
r
"
,
encoding
=
"
utf-8
"
)
as
opened
:
xml_str
=
opened
.
read
()
cont_restored
=
db
.
Container
.
from_xml
(
xml_str
)
# Test if the serialization and deserialization worked.
assert
cont
[
0
].
id
==
cont_restored
[
0
].
id
assert
cont
[
0
].
name
==
cont_restored
[
0
].
name
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