Skip to content
Snippets Groups Projects

XML Converter

Merged Alexander Schlemmer requested to merge f-xml-converter into dev
Compare and Show latest version
1 file
+ 26
4
Compare changes
  • Side-by-side
  • Inline
@@ -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"
Loading