-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpytest_helpers.py
More file actions
executable file
·29 lines (21 loc) · 1 KB
/
pytest_helpers.py
File metadata and controls
executable file
·29 lines (21 loc) · 1 KB
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
from typing import Any, List
from lxml import etree
from to_cei.config import CHARTER_NSS
from to_cei.xml_assembler import XmlAssembler
def e(value: Any) -> List[etree._Element]:
"""Makes sure that the provided value is a List of etree._Elements. Raises an exception otherwise."""
if not isinstance(value, List):
raise Exception("Not a list")
list: List[etree._Element] = value
return list
def xp(assembler: XmlAssembler, xpath: str) -> List[etree._Element]:
"""Evaluates an xpath on the charters xml content. Raises an exception if the provided assembler doesn't produce XML."""
xml = assembler.to_xml()
if xml is None:
raise Exception("XML is empty")
return e(xml.xpath(xpath, namespaces=CHARTER_NSS))
def xps(assembler: XmlAssembler, xpath: str) -> etree._Element:
"""Evaluates an xpath on the charters xml content, asserts that it only has a single element and returns the element."""
list = xp(assembler, xpath)
assert len(list) == 1
return list[0]