From c504f7e8db518e15ad419c4bf146a73d855d185b Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 26 Feb 2016 13:09:03 +0100 Subject: [PATCH] tests: add helper to check XML documents --- tests/xml_utils.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/xml_utils.py diff --git a/tests/xml_utils.py b/tests/xml_utils.py new file mode 100644 index 0000000..670c6b4 --- /dev/null +++ b/tests/xml_utils.py @@ -0,0 +1,15 @@ +from lxml import etree as ET + + +def assert_xml_constraints(content, constraint, namespaces={}): + d = ET.fromstring(content) + def check(constraint, prefix=''): + path, count = constraint[:2] + path = prefix + path + if not count is None: + l = d.xpath(path, namespaces=namespaces) + assert len(l) == count, 'len(xpath(%s)) is not %s but %s' % (path, count, len(l)) + if len(constraint) > 2: + for constraint in constraint[2:]: + check(constraint, prefix=path) + check(constraint)