Skip to content
Snippets Groups Projects
Verified Commit 89c2bea3 authored by Daniel Hornung's avatar Daniel Hornung
Browse files

ENH: Improved test for xml serialization. #89

parent da66ac22
No related branches found
No related tags found
No related merge requests found
Pipeline #34452 failed
......@@ -140,20 +140,22 @@ def test_container_xml(tmp_path):
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()
# 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()
with warnings.catch_warnings(record=True) as raised_warnings:
cont_restored = db.Container.from_xml(xml_str)
assert not raised_warnings, (
f"Loading from xml did not run smoothly.\n{raised_warnings[0].message}"
)
# Test if the serialization and deserialization worked.
assert cont[0].id == cont_restored[0].id
assert cont[0].name == cont_restored[0].name
# Test if the serialization and deserialization worked.
assert cont[0].id == cont_restored[0].id
assert cont[0].name == cont_restored[0].name
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment