import datetime as dt import xml.etree.ElementTree as et import pytest from blc2.workspace import Workspace from blc2.topology import Fixture @pytest.fixture def ws(): """Return a workspace.""" return Workspace("", "" ,"", dt.datetime.now()) @pytest.fixture def aws(): """Return a more advanced workspace with 4 channels on 1 fixture.""" w = Workspace("", "", "", dt.datetime.now()) Fixture(w, id_=0, channel_count=4) return w def elements_equal(e1, e2): """Determine if two XML elements are equal.""" if e1.tag != e2.tag: print("tag", e1.tag, e2.tag) return False if ("" if e1.text is None else e1.text).strip("\r\n\t ") != ("" if e2.text is None else e2.text).strip("\r\n\t "): print("text", repr(e1.text), repr(e2.text)) return False if ("" if e1.tail is None else e1.tail).strip("\r\n\t ") != ("" if e2.tail is None else e2.tail).strip("\r\n\t "): print("tail", repr(e1.tail), repr(e2.tail)) return False if e1.attrib != e2.attrib: print("attrib", repr(e1.attrib), repr(e2.attrib)) return False if len(e1) != len(e2): print("len", len(e1), len(e2)) return False return all(elements_equal(c1, c2) for c1, c2 in zip(e1, e2)) @pytest.fixture def test_xml_eq(): """Use for testing serialization functions.""" def inner(e: et.Element, s: str): return elements_equal(e, et.fromstring(s)) return inner