diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-07-04 13:52:28 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-07-04 13:52:28 +0100 |
| commit | 3a363314e6149361b16959d4e3c2ebb6cd97ab1f (patch) | |
| tree | 1ce2159a0ccdd9d0ceac90ecbda6cdc924254f27 /tests | |
| parent | 044398430b84b73fa6fce57405254f4a63c42424 (diff) | |
Handle relationships in notes
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/docx/document_xml_tests.py | 6 | ||||
| -rw-r--r-- | tests/docx/notes_xml_tests.py | 16 | ||||
| -rw-r--r-- | tests/mammoth_tests.py | 12 | ||||
| -rwxr-xr-x | tests/test-data/footnote-hyperlink.docx | bin | 0 -> 16271 bytes |
4 files changed, 23 insertions, 11 deletions
diff --git a/tests/docx/document_xml_tests.py b/tests/docx/document_xml_tests.py index b09f481..fa63775 100644 --- a/tests/docx/document_xml_tests.py +++ b/tests/docx/document_xml_tests.py @@ -3,7 +3,6 @@ from nose.tools import istest, assert_equal from mammoth import documents from mammoth.docx.xmlparser import element as xml_element, text as xml_text from mammoth.docx.document_xml import read_document_xml_element -from mammoth.docx.notes_xml import NoteElement from mammoth.docx import body_xml @@ -19,13 +18,12 @@ class ReadXmlElementTests(object): @istest def footnotes_of_document_are_read(self): - paragraph_xml = xml_element("w:p") - footnotes = [NoteElement("footnote", "4", [paragraph_xml])] + notes = [documents.note("footnote", "4", [documents.paragraph([])])] body_xml = xml_element("w:body") document_xml = xml_element("w:document", {}, [body_xml]) - document = _read_and_get_document_xml_element(document_xml, footnote_elements=footnotes) + document = _read_and_get_document_xml_element(document_xml, notes=notes) footnote = document.notes.find_note("footnote", "4") assert_equal("4", footnote.note_id) assert isinstance(footnote.body[0], documents.Paragraph) diff --git a/tests/docx/notes_xml_tests.py b/tests/docx/notes_xml_tests.py index 90de8f8..b912991 100644 --- a/tests/docx/notes_xml_tests.py +++ b/tests/docx/notes_xml_tests.py @@ -1,18 +1,20 @@ from nose.tools import istest, assert_equal +from mammoth import documents from mammoth.docx.xmlparser import element as xml_element -from mammoth.docx.notes_xml import read_footnotes_xml_element +from mammoth.docx.notes_xml import create_footnotes_reader +from mammoth.docx import body_xml @istest def id_and_body_of_footnote_are_read(): footnote_body = [xml_element("w:p")] - footnotes = read_footnotes_xml_element(xml_element("w:footnotes", {}, [ + footnotes = create_footnotes_reader(body_xml.reader())(xml_element("w:footnotes", {}, [ xml_element("w:footnote", {"w:id": "1"}, footnote_body), ])) - assert_equal(1, len(footnotes)) - assert footnote_body is footnotes[0].body - assert_equal("1", footnotes[0].id) + assert_equal(1, len(footnotes.value)) + assert isinstance(footnotes.value[0].body[0], documents.Paragraph) + assert_equal("1", footnotes.value[0].note_id) @istest @@ -27,8 +29,8 @@ def separator_is_ignored(): def _assert_footnote_type_is_ignored(footnote_type): footnote_body = [xml_element("w:p")] - footnotes = read_footnotes_xml_element(xml_element("w:footnotes", {}, [ + footnotes = create_footnotes_reader(None)(xml_element("w:footnotes", {}, [ xml_element("w:footnote", {"w:id": "1", "w:type": footnote_type}, footnote_body), ])) - assert_equal(0, len(footnotes)) + assert_equal(0, len(footnotes.value)) diff --git a/tests/mammoth_tests.py b/tests/mammoth_tests.py index 9f37db0..2c7262c 100644 --- a/tests/mammoth_tests.py +++ b/tests/mammoth_tests.py @@ -103,6 +103,18 @@ def endnotes_are_appended_to_text(): @istest +def relationships_are_handled_properly_in_footnotes(): + expected_html = ( + '<p><sup><a href="#doc-42-footnote-1" id="doc-42-footnote-ref-1">[1]</a></sup></p>' + + '<ol><li id="doc-42-footnote-1"><p> <a href="http://www.example.com">Example</a> <a href="#doc-42-footnote-ref-1">↑</a></p></li></ol>') + + with open(test_path("footnote-hyperlink.docx"), "rb") as fileobj: + result = mammoth.convert_to_html(fileobj=fileobj, id_prefix="doc-42") + assert_equal([], result.messages) + assert_equal(expected_html, result.value) + + +@istest def text_boxes_are_read(): with open(test_path("text-box.docx"), "rb") as fileobj: result = mammoth.convert_to_html(fileobj=fileobj) diff --git a/tests/test-data/footnote-hyperlink.docx b/tests/test-data/footnote-hyperlink.docx Binary files differnew file mode 100755 index 0000000..208f3dc --- /dev/null +++ b/tests/test-data/footnote-hyperlink.docx |
