diff options
| author | Michael Williamson <mike@zwobble.org> | 2013-12-01 11:47:48 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2013-12-01 11:47:48 +0000 |
| commit | f8d72dbba832db282a3ec04a5108fbd090f49a4f (patch) | |
| tree | e86971aec308963c55afde6263091f6591bb08d8 /tests/docx_tests.py | |
| parent | 833c867189d757efb5b13e1e783869a4039860de (diff) | |
Move docx reading into separate package
Diffstat (limited to 'tests/docx_tests.py')
| -rw-r--r-- | tests/docx_tests.py | 97 |
1 files changed, 0 insertions, 97 deletions
diff --git a/tests/docx_tests.py b/tests/docx_tests.py deleted file mode 100644 index 792ff14..0000000 --- a/tests/docx_tests.py +++ /dev/null @@ -1,97 +0,0 @@ -from nose.tools import istest, assert_equal - -from mammoth import docx, documents -from mammoth.xmlparser import element as xml_element, text as xml_text -from .testing import test_path - -@istest -class ReadTests(object): - @istest - def can_read_document_with_single_paragraph_with_single_run_of_text(self): - with open(test_path("single-paragraph.docx")) as fileobj: - result = docx.read(fileobj=fileobj) - expected_document = documents.Document([ - documents.paragraph([ - documents.Run([ - documents.Text("Walking on imported air") - ]) - ]) - ]) - assert_equal(expected_document, result.value) - - -@istest -class ReadXmlElementTests(object): - @istest - def text_from_text_element_is_read(self): - element = _text_element("Hello!") - assert_equal(documents.Text("Hello!"), docx.read_xml_element(element)) - - @istest - def can_read_text_within_run(self): - element = _run_element_with_text("Hello!") - assert_equal( - documents.Run([documents.Text("Hello!")]), - docx.read_xml_element(element) - ) - - @istest - def can_read_text_within_paragraph(self): - element = _paragraph_element_with_text("Hello!") - assert_equal( - documents.paragraph([documents.Run([documents.Text("Hello!")])]), - docx.read_xml_element(element) - ) - - @istest - def can_read_text_within_document(self): - element = _document_element_with_text("Hello!") - assert_equal( - documents.Document([documents.paragraph([documents.Run([documents.Text("Hello!")])])]), - docx.read_xml_element(element) - ) - - @istest - def paragraph_has_no_style_if_it_has_no_properties(self): - element = xml_element("w:p") - assert_equal(None, docx.read_xml_element(element).style_name) - - @istest - def paragraph_has_style_name_read_from_paragraph_properties_if_present(self): - style_xml = xml_element("w:pStyle", {"w:val": "Heading1"}) - properties_xml = xml_element("w:pPr", {}, [style_xml]) - paragraph_xml = xml_element("w:p", {}, [properties_xml]) - paragraph = docx.read_xml_element(paragraph_xml) - assert_equal("Heading1", paragraph.style_name) - - @istest - def unrecognised_elements_are_ignored(self): - element = xml_element("w:huh", {}, []) - assert_equal(None, docx.read_xml_element(element)) - - @istest - def unrecognised_children_are_ignored(self): - element = xml_element("w:r", {}, [_text_element("Hello!"), xml_element("w:huh", {}, [])]) - assert_equal( - documents.Run([documents.Text("Hello!")]), - docx.read_xml_element(element) - ) - - -def _document_element_with_text(text): - return xml_element("w:document", {}, [ - xml_element("w:body", {}, [_paragraph_element_with_text(text)]) - ]) - - -def _paragraph_element_with_text(text): - return xml_element("w:p", {}, [_run_element_with_text(text)]) - - -def _run_element_with_text(text): - return xml_element("w:r", {}, [_text_element(text)]) - - -def _text_element(value): - return xml_element("w:t", {}, [xml_text(value)]) - |
