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): ...@@ -140,20 +140,22 @@ def test_container_xml(tmp_path):
For issue 89: https://gitlab.com/caosdb/caosdb-pylib/-/issues/89 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()
# Create XML with container with one RecordType. cont = db.execute_query("FIND RecordType TestRT")
db.RecordType(name="TestRT").insert() xml_file = os.path.join(tmp_path, "tmp.xml")
cont = db.execute_query("FIND RecordType TestRT") with open(xml_file, "w", encoding="utf-8") as opened:
xml_file = os.path.join(tmp_path, "tmp.xml") opened.write(str(cont))
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:
# Read from file again. xml_str = opened.read()
with open(xml_file, "r", encoding="utf-8") as opened: with warnings.catch_warnings(record=True) as raised_warnings:
xml_str = opened.read()
cont_restored = db.Container.from_xml(xml_str) 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. # Test if the serialization and deserialization worked.
assert cont[0].id == cont_restored[0].id assert cont[0].id == cont_restored[0].id
assert cont[0].name == cont_restored[0].name 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