Skip to content
Snippets Groups Projects

XML Converter

Merged Alexander Schlemmer requested to merge f-xml-converter into dev
All threads resolved!
Compare and Show latest version
1 file
+ 23
24
Compare changes
  • Side-by-side
  • Inline
@@ -84,8 +84,8 @@ def converter_registry():
@pytest.fixture
def basic_cfood():
xml_cfood = yaml.safe_load("""
def basic_xmltag_converter(converter_registry):
return XMLTagConverter(yaml.safe_load("""
type: XMLTag
match_tag: a
match_attrib: # default is the empty dictionary
@@ -93,33 +93,13 @@ match_attrib: # default is the empty dictionary
alt: (.+) # this attribute must be present and contain at least one character
match_text: \\s*(?P<node_text>.+)\\s*
# _*_ marks the default:
attribs_as_children: true # true / _false_
text_as_children: true # true / _false_
tags_as_children: true # _true_ / false
subtree:
text: # this would be created by the text_as_children-flag
type: XMLTextNode
match: test
alt: # this would be created by the attribs_as_children-flag
type: TextElement
match_name: alt
match_value: ^(?P<text>.*)$
img:
type: XMLTag
match_name: img
match_attrib:
src: test2
""")
return xml_cfood
@pytest.fixture
def basic_xmltag_converter(basic_cfood, converter_registry):
converter = XMLTagConverter(basic_cfood, "TestXMLTagConverter", converter_registry)
return converter
"""), "TestXMLTagConverter", converter_registry)
@@ -187,7 +167,6 @@ 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):
"""
Test for xml conversion including children.
@@ -203,9 +182,29 @@ def test_nested_simple_xml(basic_xmltag_converter):
assert m is not None
general_store = GeneralStore()
children = basic_xmltag_converter.create_children(general_store, tag)
assert len(children) == 1
assert isinstance(children[0], XMLTagElement)
assert children[0].name == "img"
xml_text = """
<a href="test1" alt="no link">
test <img src="test2">
<testnode/> </img>
</a>
"""
tag = XMLTagElement(fromstring(xml_text))
m = basic_xmltag_converter.match(tag)
assert m is not None
general_store = GeneralStore()
children = basic_xmltag_converter.create_children(general_store, tag)
assert len(children) == 1
assert isinstance(children[0], XMLTagElement)
assert children[0].name == "img"
Loading