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

MAINT: refactored test fixtures

parent 3bb7861a
No related branches found
No related tags found
2 merge requests!181Release 0.9.0,!174XML Converter
Pipeline #54372 failed
...@@ -84,8 +84,8 @@ def converter_registry(): ...@@ -84,8 +84,8 @@ def converter_registry():
@pytest.fixture @pytest.fixture
def basic_cfood(): def basic_xmltag_converter(converter_registry):
xml_cfood = yaml.safe_load(""" return XMLTagConverter(yaml.safe_load("""
type: XMLTag type: XMLTag
match_tag: a match_tag: a
match_attrib: # default is the empty dictionary match_attrib: # default is the empty dictionary
...@@ -93,33 +93,13 @@ 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 alt: (.+) # this attribute must be present and contain at least one character
match_text: \\s*(?P<node_text>.+)\\s* 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: 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: img:
type: XMLTag type: XMLTag
match_name: img match_name: img
match_attrib: match_attrib:
src: test2 src: test2
""") """), "TestXMLTagConverter", converter_registry)
return xml_cfood
@pytest.fixture
def basic_xmltag_converter(basic_cfood, converter_registry):
converter = XMLTagConverter(basic_cfood, "TestXMLTagConverter", converter_registry)
return converter
...@@ -187,7 +167,6 @@ def test_not_matching(basic_xmltag_converter): ...@@ -187,7 +167,6 @@ def test_not_matching(basic_xmltag_converter):
# TODO: how to match " ajskdlfjaldsf ajsdklfjadkl " without the whitespaces in regexp correctly? # 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):
""" """
Test for xml conversion including children. Test for xml conversion including children.
...@@ -203,9 +182,29 @@ def test_nested_simple_xml(basic_xmltag_converter): ...@@ -203,9 +182,29 @@ def test_nested_simple_xml(basic_xmltag_converter):
assert m is not None assert m is not None
general_store = GeneralStore() 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) children = basic_xmltag_converter.create_children(general_store, tag)
assert len(children) == 1 assert len(children) == 1
assert isinstance(children[0], XMLTagElement) assert isinstance(children[0], XMLTagElement)
assert children[0].name == "img" assert children[0].name == "img"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment