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)