1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
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:
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 "):
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 "):
return False
if e1.attrib != e2.attrib:
return False
if 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
|