"""Helpers for unit tests.""" from typing import cast from lxml import etree class Helpers: """Helpers for tests.""" @staticmethod def print_xml(element) -> str: """Render the element to an XML string.""" etree.indent(element, space=' ') document_buffer = etree.tostring( element, encoding='utf-8', pretty_print=True, ) stringified = cast(bytes, document_buffer).decode('utf-8') # Remove namespace declarations from the output for cleaner assertions import re stringified = re.sub(r' xmlns:[^=]+="[^"]+"', '', stringified) return stringified.strip()