Skip to content

Commit

Permalink
Add unit tests for build_schema_node_tree()
Browse files Browse the repository at this point in the history
  • Loading branch information
brunato committed Jul 25, 2023
1 parent c0ec1e6 commit 2d6516e
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion tests/test_tree_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="elem1"/>
<xs:element name="elem2"/>
<xs:element name="elem3"/>
<xs:element ref="root"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>"""))

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()

0 comments on commit 2d6516e

Please sign in to comment.