diff options
| author | Michael Williamson <mike@zwobble.org> | 2014-06-08 21:58:14 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2014-06-08 21:58:14 +0100 |
| commit | 84dcb27be96635789073cc547d6a3b8ee462769e (patch) | |
| tree | 071f331db5d8017d7a40504653109ba413cb1b72 /tests | |
| parent | 178a640539e1af27fb7b64fc540adc17e58c30c4 (diff) | |
Add basic style XML reading
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/docx/styles_xml_tests.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/docx/styles_xml_tests.py b/tests/docx/styles_xml_tests.py new file mode 100644 index 0000000..7e58333 --- /dev/null +++ b/tests/docx/styles_xml_tests.py @@ -0,0 +1,29 @@ +from nose.tools import istest, assert_equal + +from mammoth.docx.xmlparser import element as xml_element +from mammoth.docx.styles_xml import read_styles_xml_element + + +@istest +def paragraph_style_is_null_if_no_style_with_that_id_exists(): + element = xml_element("w:styles") + styles = read_styles_xml_element(element) + assert_equal(None, styles.find_paragraph_style_by_id("Heading1")) + + +@istest +def paragraph_style_can_be_found_by_id(): + element = xml_element("w:styles", {}, [ + _paragraph_style_element("Heading1", "Heading 1"), + ]) + styles = read_styles_xml_element(element) + assert_equal("Heading1", styles.find_paragraph_style_by_id("Heading1").style_id) + + +def _paragraph_style_element(style_id, name): + return _style_element("paragraph", style_id, name) + +def _style_element(element_type, style_id, name): + return xml_element("w:style", {"w:type": element_type, "w:styleId": style_id}, [ + xml_element("w:name", {"w:val": name}, []) + ]) |
