Skip to content
Snippets Groups Projects
Commit 10df18a9 authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

TST: added test for generating children using xpath in the xml converter

parent 072bffdb
No related branches found
No related tags found
2 merge requests!181Release 0.9.0,!174XML Converter
Pipeline #54373 failed
......@@ -101,6 +101,28 @@ subtree:
src: test2
"""), "TestXMLTagConverter", converter_registry)
@pytest.fixture
def basic_xpath_xmltag_converter(converter_registry):
return XMLTagConverter(yaml.safe_load("""
type: XMLTag
match_tag: a
match_attrib: # default is the empty dictionary
"(?P<ref>(href|url))": "test(?P<number>[0-9])" # either the "href" or the "url" attribute must be set
alt: (.+) # this attribute must be present and contain at least one character
match_text: \\s*(?P<node_text>.+)\\s*
xpath: child::*/*
subtree:
img:
type: XMLTag
match_name: img
match_attrib:
src: test2
testnode:
type: XMLTag
match_name: testnode
"""), "TestXMLTagConverter", converter_registry)
def test_simple_xml(basic_xmltag_converter):
......@@ -167,7 +189,7 @@ def test_not_matching(basic_xmltag_converter):
# TODO: how to match " ajskdlfjaldsf ajsdklfjadkl " without the whitespaces in regexp correctly?
def test_nested_simple_xml(basic_xmltag_converter):
def test_nested_simple_xml(basic_xmltag_converter, basic_xpath_xmltag_converter):
"""
Test for xml conversion including children.
"""
......@@ -198,13 +220,13 @@ def test_nested_simple_xml(basic_xmltag_converter):
"""
tag = XMLTagElement(fromstring(xml_text))
m = basic_xmltag_converter.match(tag)
m = basic_xpath_xmltag_converter.match(tag)
assert m is not None
general_store = GeneralStore()
children = basic_xmltag_converter.create_children(general_store, tag)
children = basic_xpath_xmltag_converter.create_children(general_store, tag)
assert len(children) == 1
assert isinstance(children[0], XMLTagElement)
assert children[0].name == "img"
assert children[0].name == "img/testnode"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment