# coding=utf-8 from __future__ import unicode_literals import io import shutil import os import tempman from nose.tools import istest, assert_equal from .testing import test_path import mammoth from mammoth import results @istest def docx_containing_one_paragraph_is_converted_to_single_p_element(): with open(test_path("single-paragraph.docx"), "rb") as fileobj: result = mammoth.convert_to_html(fileobj=fileobj) assert_equal("
Walking on imported air
", result.value) assert_equal([], result.messages) @istest def can_read_xml_files_with_utf8_bom(): with open(test_path("utf8-bom.docx"), "rb") as fileobj: result = mammoth.convert_to_html(fileobj=fileobj) assert_equal("This XML has a byte order mark.
", result.value) assert_equal([], result.messages) @istest def empty_paragraphs_are_ignored_by_default(): with open(test_path("empty.docx"), "rb") as fileobj: result = mammoth.convert_to_html(fileobj=fileobj) assert_equal("", result.value) assert_equal([], result.messages) @istest def empty_paragraphs_are_preserved_if_ignore_empty_paragraphs_is_false(): with open(test_path("empty.docx"), "rb") as fileobj: result = mammoth.convert_to_html(fileobj=fileobj, ignore_empty_paragraphs=False) assert_equal("", result.value) assert_equal([], result.messages) @istest def warning_if_style_mapping_is_not_understood(): style_map = """ !!!! p => h1""" with open(test_path("single-paragraph.docx"), "rb") as fileobj: result = mammoth.convert_to_html(fileobj=fileobj, style_map=style_map) assert_equal("Above
" + "Top left | Top right |
Bottom left | Bottom right |
Below
") with open(test_path("tables.docx"), "rb") as fileobj: result = mammoth.convert_to_html(fileobj=fileobj) assert_equal([], result.messages) assert_equal(expected_html, result.value) @istest def footnotes_are_appended_to_text(): # TODO: don't duplicate footnotes with multiple references expected_html = ('' + '') with open(test_path("footnotes.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 endnotes_are_appended_to_text(): expected_html = ('' + '') with open(test_path("endnotes.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 relationships_are_handled_properly_in_footnotes(): expected_html = ( '' + '') 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) assert_equal('Datum plane
', result.value) @istest def underline_is_ignored_by_defualt(): with open(test_path("underline.docx"), "rb") as fileobj: result = mammoth.convert_to_html(fileobj=fileobj) assert_equal('The Sunset Tree
', result.value) @istest def underline_can_be_configured_with_convert_underline_option(): with open(test_path("underline.docx"), "rb") as fileobj: result = mammoth.convert_to_html(fileobj=fileobj, convert_underline=mammoth.underline.element("em")) assert_equal('The Sunset Tree
', result.value) @istest def underline_can_be_configured_with_style_mapping(): with open(test_path("underline.docx"), "rb") as fileobj: result = mammoth.convert_to_html(fileobj=fileobj, style_map="u => em") assert_equal('The Sunset Tree
', result.value) @istest def strikethrough_is_converted_to_s_element_by_default(): with open(test_path("strikethrough.docx"), "rb") as fileobj: result = mammoth.convert_to_html(fileobj=fileobj) assert_equal("Today's Special: Salmon Sold out
Today's Special: Salmon Sold out