aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-12-14 17:54:05 +0000
committerMichael Williamson <mike@zwobble.org>2013-12-14 17:54:05 +0000
commit673f1c46b7c3dbf0494612056fe3c86da9e0dc0a (patch)
treea1d71c27c5c8a227f5245f6b998cee1bf8393564
parentdd44939b3ec3c59a3c8a89e8d5d4128642bb7b59 (diff)
Parse outputted HTML in test to avoid reliance on attribute order
-rw-r--r--mammoth/html_generation.py2
-rw-r--r--tests/conversion_tests.py6
2 files changed, 5 insertions, 3 deletions
diff --git a/mammoth/html_generation.py b/mammoth/html_generation.py
index 9716ac2..f6f62af 100644
--- a/mammoth/html_generation.py
+++ b/mammoth/html_generation.py
@@ -45,7 +45,7 @@ class HtmlGenerator(object):
self._fragments.append(fragment)
def html_string(self):
- return "".join(self._fragments)
+ return u"".join(self._fragments)
class _Element(object):
diff --git a/tests/conversion_tests.py b/tests/conversion_tests.py
index cb9b064..a041561 100644
--- a/tests/conversion_tests.py
+++ b/tests/conversion_tests.py
@@ -4,6 +4,7 @@ from nose.tools import istest, assert_equal
from mammoth import documents, style_reader, results
from mammoth.conversion import convert_document_element_to_html
+from mammoth.docx.xmlparser import parse_xml
@istest
@@ -154,14 +155,15 @@ def images_are_converted_to_img_tags_with_data_uri():
def images_have_alt_tags_if_available():
image = documents.image(alt_text="It's a hat", content_type="image/png", open=lambda: io.BytesIO(b"abc"))
result = convert_document_element_to_html(image)
- assert_equal('<img src="data:image/png;base64,YWJj" alt="It\'s a hat" />', result.value)
+ image_html = parse_xml(io.StringIO(result.value))
+ assert_equal('It\'s a hat', image_html.attributes["alt"])
@istest
def can_define_custom_conversion_for_images():
def convert_image(image, html_generator):
with image.open() as image_file:
- html_generator.self_closing("img", {"alt": image_file.read()})
+ html_generator.self_closing("img", {"alt": image_file.read().decode("ascii")})
image = documents.image(alt_text=None, content_type="image/png", open=lambda: io.BytesIO(b"abc"))
result = convert_document_element_to_html(image, convert_image=convert_image)