diff --git a/tests/test_tree_builders.py b/tests/test_tree_builders.py index 3f709a57..46503656 100644 --- a/tests/test_tree_builders.py +++ b/tests/test_tree_builders.py @@ -12,14 +12,22 @@ import io import sys import xml.etree.ElementTree as ElementTree +from textwrap import dedent try: import lxml.etree as lxml_etree except ImportError: lxml_etree = None +try: + import xmlschema +except ImportError: + xmlschema = None +else: + xmlschema.XMLSchema.meta_schema.build() + from elementpath.tree_builders import build_node_tree, \ - build_lxml_node_tree + build_lxml_node_tree, build_schema_node_tree from elementpath.xpath_nodes import ElementNode, \ DocumentNode, TextNode, CommentNode, ProcessingInstructionNode @@ -183,6 +191,33 @@ def test_build_lxml_node_tree_with_element_tree(self): self.assertIs(node.document, root) self.assertEqual(len(node.children), 0) + @unittest.skipIf(xmlschema is None, "xmlschema library is not installed!") + def test_build_schema_node_tree(self): + schema = xmlschema.XMLSchema(dedent("""\n + + + + + + + + + + + + """)) + + root_node = build_schema_node_tree(schema) + self.assertIs(root_node.elem, schema) + + global_elements = [] + root_node = build_schema_node_tree(schema, global_elements=global_elements) + self.assertIs(root_node.elem, schema) + self.assertIn(root_node, global_elements) + + root_node = build_schema_node_tree(schema.elements['root']) + self.assertIs(root_node.elem, schema.elements['root']) + if __name__ == '__main__': unittest.main()