From 045edf1c661b09957e4f87c37981b209a29512ae Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 31 Aug 2014 10:44:16 +0100 Subject: Fix support on different Python versions --- mammoth/conversion.py | 7 ++++++- tests/conversion_tests.py | 6 ++++-- tests/docx/footnotes_xml_tests.py | 4 ++-- tests/mammoth_tests.py | 12 +++++++----- 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'

Knock knock[1]

' + - u'
  1. Who\'s there? ↑

') + expected_html = ('

Knock knock[1]

' + + '
  1. Who\'s there? ↑

') 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'

Ouch' + - u'[1].' + - u'[2]

' + - u'
  1. A tachyon walks into a bar. ↑

  2. ' + - u'
  3. Fin. ↑

') + expected_html = ('

Ouch' + + '[1].' + + '[2]

' + + '
  1. A tachyon walks into a bar. ↑

  2. ' + + '
  3. Fin. ↑

') with open(test_path("footnotes.docx"), "rb") as fileobj: result = mammoth.convert_to_html(fileobj=fileobj, generate_uniquifier=lambda: 42) -- cgit v1.2.3