summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2014-08-31 10:44:16 +0100
committerMichael Williamson <mike@zwobble.org>2014-08-31 10:44:16 +0100
commit045edf1c661b09957e4f87c37981b209a29512ae (patch)
tree3223ba0425a32fb98d7d639da7dbcbbfbcbae45c
parent7145a7199033988065f472af5a964587acbe06eb (diff)
Fix support on different Python versions
-rw-r--r--mammoth/conversion.py7
-rw-r--r--tests/conversion_tests.py6
-rw-r--r--tests/docx/footnotes_xml_tests.py4
-rw-r--r--tests/mammoth_tests.py12
4 files changed, 19 insertions, 10 deletions
diff --git a/mammoth/conversion.py b/mammoth/conversion.py
index c1299f6..0a91a1d 100644
--- a/mammoth/conversion.py
+++ b/mammoth/conversion.py
@@ -2,6 +2,7 @@
import base64
import random
+import sys
from . import documents, results, html_paths, images
from .html_generation import HtmlGenerator, satisfy_html_path
@@ -161,7 +162,7 @@ class DocumentConverter(object):
self._convert_elements_to_html(footnote.body, footnote_generator)
footnote_generator.text(" ")
footnote_generator.start("a", {"href": "#footnote-ref-{0}".format(uid)})
- footnote_generator.text(u"↑")
+ footnote_generator.text(_up_arrow)
footnote_generator.end_all()
html_generator.append(footnote_generator)
html_generator.end()
@@ -213,3 +214,7 @@ def _document_matcher_matches(matcher, element, element_type):
matcher.numbering == element.numbering
)
)
+
+_up_arrow = "↑"
+if sys.version_info[0] < 3:
+ _up_arrow = _up_arrow.decode("utf8")
diff --git a/tests/conversion_tests.py b/tests/conversion_tests.py
index 508d457..d9dde3e 100644
--- a/tests/conversion_tests.py
+++ b/tests/conversion_tests.py
@@ -1,5 +1,7 @@
# coding=utf-8
+from __future__ import unicode_literals
+
import io
from nose.tools import istest, assert_equal
@@ -286,8 +288,8 @@ def footnotes_are_included_after_the_main_body():
document,
generate_uniquifier=lambda: 42
)
- expected_html = (u'<p>Knock knock<sup><a href="#footnote-42-4" id="footnote-ref-42-4">[1]</a></sup></p>' +
- u'<ol><li id="footnote-42-4"><p>Who\'s there? <a href="#footnote-ref-42-4">↑</a></p></li></ol>')
+ expected_html = ('<p>Knock knock<sup><a href="#footnote-42-4" id="footnote-ref-42-4">[1]</a></sup></p>' +
+ '<ol><li id="footnote-42-4"><p>Who\'s there? <a href="#footnote-ref-42-4">↑</a></p></li></ol>')
assert_equal(expected_html, result.value)
diff --git a/tests/docx/footnotes_xml_tests.py b/tests/docx/footnotes_xml_tests.py
index c3fed04..645f3d0 100644
--- a/tests/docx/footnotes_xml_tests.py
+++ b/tests/docx/footnotes_xml_tests.py
@@ -1,4 +1,4 @@
-from nose.tools import istest, assert_equal, assert_is
+from nose.tools import istest, assert_equal
from mammoth.docx.xmlparser import element as xml_element
from mammoth.docx.footnotes_xml import read_footnotes_xml_element
@@ -11,7 +11,7 @@ def id_and_body_of_footnote_are_read():
xml_element("w:footnote", {"w:id": "1"}, footnote_body),
]))
assert_equal(1, len(footnotes))
- assert_is(footnote_body, footnotes[0].body)
+ assert footnote_body is footnotes[0].body
assert_equal("1", footnotes[0].id)
diff --git a/tests/mammoth_tests.py b/tests/mammoth_tests.py
index f744711..70fac7d 100644
--- a/tests/mammoth_tests.py
+++ b/tests/mammoth_tests.py
@@ -1,5 +1,7 @@
# coding=utf-8
+from __future__ import unicode_literals
+
from nose.tools import istest, assert_equal
from .testing import test_path
@@ -58,11 +60,11 @@ def word_tables_are_converted_to_html_tables():
@istest
def footnotes_are_appended_to_text():
# TODO: don't duplicate footnotes with multiple references
- expected_html = (u'<p>Ouch' +
- u'<sup><a href="#footnote-42-1" id="footnote-ref-42-1">[1]</a></sup>.' +
- u'<sup><a href="#footnote-42-2" id="footnote-ref-42-2">[2]</a></sup></p>' +
- u'<ol><li id="footnote-42-1"><p> A tachyon walks into a bar. <a href="#footnote-ref-42-1">↑</a></p></li>' +
- u'<li id="footnote-42-2"><p> Fin. <a href="#footnote-ref-42-2">↑</a></p></li></ol>')
+ expected_html = ('<p>Ouch' +
+ '<sup><a href="#footnote-42-1" id="footnote-ref-42-1">[1]</a></sup>.' +
+ '<sup><a href="#footnote-42-2" id="footnote-ref-42-2">[2]</a></sup></p>' +
+ '<ol><li id="footnote-42-1"><p> A tachyon walks into a bar. <a href="#footnote-ref-42-1">↑</a></p></li>' +
+ '<li id="footnote-42-2"><p> Fin. <a href="#footnote-ref-42-2">↑</a></p></li></ol>')
with open(test_path("footnotes.docx"), "rb") as fileobj:
result = mammoth.convert_to_html(fileobj=fileobj, generate_uniquifier=lambda: 42)