diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-06-15 15:14:28 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-06-15 15:14:28 +0100 |
| commit | 604e19be95f13c5e3b4396c3e747a2ee957b1893 (patch) | |
| tree | 0deb3c302c609f078a26a0e6c496098c02582596 /tests | |
| parent | 111ecfe14e4be1b1c9aeb480148b9694e10e1e53 (diff) | |
Fix: find_child errors on text children
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/docx/xmlparser_tests.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/docx/xmlparser_tests.py b/tests/docx/xmlparser_tests.py index 5e33778..65a2f25 100644 --- a/tests/docx/xmlparser_tests.py +++ b/tests/docx/xmlparser_tests.py @@ -63,6 +63,29 @@ def namespace_of_attributes_is_mapped_to_prefix(): def whitespace_between_xml_declaration_and_root_tag_is_ignored(): xml = _parse_xml_string(b'<?xml version="1.0" ?>\n<body/>') assert_equal("body", xml.name) + + +@istest +class FindChildTests(object): + @istest + def returns_none_if_no_children(self): + xml = xml_element("a") + assert_equal(None, xml.find_child("b")) + + @istest + def returns_none_if_no_matching_children(self): + xml = xml_element("a", {}, [xml_element("c")]) + assert_equal(None, xml.find_child("b")) + + @istest + def returns_first_matching_child(self): + xml = xml_element("a", {}, [xml_element("b", {"id": 1}), xml_element("b", {"id": 2})]) + assert_equal(1, xml.find_child("b").attributes["id"]) + + @istest + def ignores_text_nodes(self): + xml = xml_element("a", {}, [xml_text("Hello!")]) + assert_equal(None, xml.find_child("b")) def _parse_xml_string(string, namespace_mapping=None): |
