diff --git a/unittests/test_xml_converter.py b/unittests/test_xml_converter.py index 0a7b007760f7a73da934e4be6b65d4e8ec0749c1..6bfb1cccad1d7835f83f37b5263d579b84641c20 100644 --- a/unittests/test_xml_converter.py +++ b/unittests/test_xml_converter.py @@ -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"