summaryrefslogtreecommitdiff
path: root/tests/conftest.py
blob: 1a9af58b232a8f5d9f4eb55e1f21436bf2b6b98e (plain)
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
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):
    if e1.tag != e2.tag: return False
    if e1.text != e2.text: return False
    if e1.tail.strip() != e2.tail.strip(): 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():
    def inner(e: et.Element, s: str):
        return elements_equal(e, et.fromstring(s))
    return inner