From 5093d72b9fece1a7c3d7a3d19e4161387ee6475a Mon Sep 17 00:00:00 2001
From: Michael Williamson Walking on imported air Hello Hello there Tip Tip Tip Tip Tip Hello
', result.value)
-@istest
-def bulleted_styles_dont_match_plain_paragraph():
+def test_bulleted_styles_dont_match_plain_paragraph():
result = convert_document_element_to_html(
documents.paragraph(children=[
_run_with_text("Hello")
@@ -147,16 +134,14 @@ def bulleted_styles_dont_match_plain_paragraph():
assert_equal('Hello", result.value)
-@istest
-def strikethrough_runs_can_be_configured_with_style_mapping():
+def test_strikethrough_runs_can_be_configured_with_style_mapping():
result = convert_document_element_to_html(
documents.run(children=[documents.text("Hello")], is_strikethrough=True),
style_map=[
@@ -230,16 +208,14 @@ def strikethrough_runs_can_be_configured_with_style_mapping():
assert_equal("Hello", result.value)
-@istest
-def sml_caps_runs_are_ignored_by_default():
+def test_sml_caps_runs_are_ignored_by_default():
result = convert_document_element_to_html(
documents.run(children=[documents.text("Hello")], is_all_caps=True),
)
assert_equal("Hello", result.value)
-@istest
-def all_caps_runs_can_be_mapped_using_style_mapping():
+def test_all_caps_runs_can_be_mapped_using_style_mapping():
result = convert_document_element_to_html(
documents.run(children=[documents.text("Hello")], is_all_caps=True),
style_map=[
@@ -249,16 +225,14 @@ def all_caps_runs_can_be_mapped_using_style_mapping():
assert_equal("Hello", result.value)
-@istest
-def small_caps_runs_are_ignored_by_default():
+def test_small_caps_runs_are_ignored_by_default():
result = convert_document_element_to_html(
documents.run(children=[documents.text("Hello")], is_small_caps=True),
)
assert_equal("Hello", result.value)
-@istest
-def small_caps_runs_can_be_mapped_using_style_mapping():
+def test_small_caps_runs_can_be_mapped_using_style_mapping():
result = convert_document_element_to_html(
documents.run(children=[documents.text("Hello")], is_small_caps=True),
style_map=[
@@ -268,8 +242,7 @@ def small_caps_runs_can_be_mapped_using_style_mapping():
assert_equal("Hello", result.value)
-@istest
-def superscript_runs_are_wrapped_in_sup_tags():
+def test_superscript_runs_are_wrapped_in_sup_tags():
result = convert_document_element_to_html(
documents.run(
children=[documents.text("Hello")],
@@ -279,8 +252,7 @@ def superscript_runs_are_wrapped_in_sup_tags():
assert_equal("Hello", result.value)
-@istest
-def subscript_runs_are_wrapped_in_sub_tags():
+def test_subscript_runs_are_wrapped_in_sub_tags():
result = convert_document_element_to_html(
documents.run(
children=[documents.text("Hello")],
@@ -290,8 +262,7 @@ def subscript_runs_are_wrapped_in_sub_tags():
assert_equal("Hello", result.value)
-@istest
-def runs_are_converted_by_satisfying_matching_paths():
+def test_runs_are_converted_by_satisfying_matching_paths():
result = convert_document_element_to_html(
documents.run(style_id="TipsRun", children=[documents.Text("Tip")]),
style_map=[
@@ -301,16 +272,14 @@ def runs_are_converted_by_satisfying_matching_paths():
assert_equal('Tip', result.value)
-@istest
-def docx_hyperlink_with_href_is_converted_to_anchor_tag():
+def test_docx_hyperlink_with_href_is_converted_to_anchor_tag():
result = convert_document_element_to_html(
documents.hyperlink(href="http://example.com", children=[documents.Text("Hello")]),
)
assert_equal('Hello', result.value)
-@istest
-def docx_hyperlinks_can_be_collapsed():
+def test_docx_hyperlinks_can_be_collapsed():
result = convert_document_element_to_html(
documents.document(children=[
documents.hyperlink(href="http://example.com", children=[documents.Text("Hello ")]),
@@ -320,8 +289,7 @@ def docx_hyperlinks_can_be_collapsed():
assert_equal('Hello world', result.value)
-@istest
-def docx_hyperlink_with_internal_anchor_reference_is_converted_to_anchor_tag():
+def test_docx_hyperlink_with_internal_anchor_reference_is_converted_to_anchor_tag():
result = convert_document_element_to_html(
documents.hyperlink(anchor="start", children=[documents.Text("Hello")]),
id_prefix="doc-42-",
@@ -329,8 +297,7 @@ def docx_hyperlink_with_internal_anchor_reference_is_converted_to_anchor_tag():
assert_equal('Hello', result.value)
-@istest
-def hyperlink_target_frame_is_used_as_anchor_target():
+def test_hyperlink_target_frame_is_used_as_anchor_target():
result = convert_document_element_to_html(
documents.hyperlink(
anchor="start",
@@ -341,8 +308,7 @@ def hyperlink_target_frame_is_used_as_anchor_target():
assert_equal('Hello', result.value)
-@istest
-def bookmarks_are_converted_to_anchors_with_ids():
+def test_bookmarks_are_converted_to_anchors_with_ids():
result = convert_document_element_to_html(
documents.bookmark(name="start"),
id_prefix="doc-42-",
@@ -350,14 +316,12 @@ def bookmarks_are_converted_to_anchors_with_ids():
assert_equal('', result.value)
-@istest
-def docx_tab_is_converted_to_tab_in_html():
+def test_docx_tab_is_converted_to_tab_in_html():
result = convert_document_element_to_html(documents.tab())
assert_equal('\t', result.value)
-@istest
-def docx_table_is_converted_to_table_in_html():
+def test_docx_table_is_converted_to_table_in_html():
table = documents.table([
documents.table_row([
documents.table_cell([_paragraph_with_text("Top left")]),
@@ -377,8 +341,7 @@ def docx_table_is_converted_to_table_in_html():
assert_equal(expected_html, result.value)
-@istest
-def table_style_mappings_can_be_used_to_map_tables():
+def test_table_style_mappings_can_be_used_to_map_tables():
table = documents.table([], style_name="Normal Table")
result = convert_document_element_to_html(
table,
@@ -390,8 +353,7 @@ def table_style_mappings_can_be_used_to_map_tables():
assert_equal(expected_html, result.value)
-@istest
-def header_rows_are_wrapped_in_thead():
+def test_header_rows_are_wrapped_in_thead():
table = documents.table([
documents.table_row([documents.table_cell([])], is_header=True),
documents.table_row([documents.table_cell([])], is_header=True),
@@ -406,8 +368,7 @@ def header_rows_are_wrapped_in_thead():
assert_equal(expected_html, result.value)
-@istest
-def tbody_is_omitted_if_all_rows_are_headers():
+def test_tbody_is_omitted_if_all_rows_are_headers():
table = documents.table([
documents.table_row([documents.table_cell([])], is_header=True),
])
@@ -419,8 +380,7 @@ def tbody_is_omitted_if_all_rows_are_headers():
assert_equal(expected_html, result.value)
-@istest
-def unexpected_table_children_do_not_cause_error():
+def test_unexpected_table_children_do_not_cause_error():
table = documents.table([
documents.tab(),
])
@@ -429,8 +389,7 @@ def unexpected_table_children_do_not_cause_error():
assert_equal(expected_html, result.value)
-@istest
-def empty_cells_are_preserved_in_table():
+def test_empty_cells_are_preserved_in_table():
table = documents.table([
documents.table_row([
documents.table_cell([_paragraph_with_text("")]),
@@ -445,8 +404,7 @@ def empty_cells_are_preserved_in_table():
assert_equal(expected_html, result.value)
-@istest
-def empty_rows_are_preserved_in_table():
+def test_empty_rows_are_preserved_in_table():
table = documents.table([
documents.table_row([
documents.table_cell([_paragraph_with_text("Row 1")]),
@@ -461,8 +419,7 @@ def empty_rows_are_preserved_in_table():
assert_equal(expected_html, result.value)
-@istest
-def table_cells_are_written_with_colspan_if_not_equal_to_one():
+def test_table_cells_are_written_with_colspan_if_not_equal_to_one():
table = documents.table([
documents.table_row([
documents.table_cell([_paragraph_with_text("Top left")], colspan=2),
@@ -477,8 +434,7 @@ def table_cells_are_written_with_colspan_if_not_equal_to_one():
assert_equal(expected_html, result.value)
-@istest
-def table_cells_are_written_with_rowspan_if_not_equal_to_one():
+def test_table_cells_are_written_with_rowspan_if_not_equal_to_one():
table = documents.table([
documents.table_row([
documents.table_cell([], rowspan=2),
@@ -492,20 +448,17 @@ def table_cells_are_written_with_rowspan_if_not_equal_to_one():
assert_equal(expected_html, result.value)
-@istest
-def line_break_is_converted_to_br():
+def test_line_break_is_converted_to_br():
result = convert_document_element_to_html(documents.line_break)
assert_equal("
", result.value)
-@istest
-def breaks_that_are_not_line_breaks_are_ignored():
+def test_breaks_that_are_not_line_breaks_are_ignored():
result = convert_document_element_to_html(documents.page_break)
assert_equal("", result.value)
-@istest
-def breaks_can_be_mapped_using_style_mappings():
+def test_breaks_can_be_mapped_using_style_mappings():
result = convert_document_element_to_html(
documents.page_break,
style_map=[
@@ -515,23 +468,20 @@ def breaks_can_be_mapped_using_style_mappings():
assert_equal("
", result.value)
-@istest
-def images_are_converted_to_img_tags_with_data_uri():
+def test_images_are_converted_to_img_tags_with_data_uri():
image = documents.image(alt_text=None, content_type="image/png", open=lambda: io.BytesIO(b"abc"))
result = convert_document_element_to_html(image)
assert_equal('', result.value)
-@istest
-def images_have_alt_tags_if_available():
+def test_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)
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 test_can_define_custom_conversion_for_images():
def convert_image(image):
with image.open() as image_file:
return [html.element("img", {"alt": image_file.read().decode("ascii")})]
@@ -541,8 +491,7 @@ def can_define_custom_conversion_for_images():
assert_equal('
', result.value)
-@istest
-def footnote_reference_is_converted_to_superscript_intra_page_link():
+def test_footnote_reference_is_converted_to_superscript_intra_page_link():
footnote_reference = documents.note_reference("footnote", "4")
result = convert_document_element_to_html(
footnote_reference,
@@ -551,8 +500,7 @@ def footnote_reference_is_converted_to_superscript_intra_page_link():
assert_equal('[1]', result.value)
-@istest
-def footnotes_are_included_after_the_main_body():
+def test_footnotes_are_included_after_the_main_body():
footnote_reference = documents.note_reference("footnote", "4")
document = documents.document(
[documents.paragraph([
@@ -572,8 +520,7 @@ def footnotes_are_included_after_the_main_body():
assert_equal(expected_html, result.value)
-@istest
-def comments_are_ignored_by_default():
+def test_comments_are_ignored_by_default():
reference = documents.comment_reference("4")
comment = documents.comment(
comment_id="4",
@@ -591,8 +538,7 @@ def comments_are_ignored_by_default():
assert_equal(expected_html, result.value)
-@istest
-def comment_references_are_linked_to_comment_after_main_body():
+def test_comment_references_are_linked_to_comment_after_main_body():
reference = documents.comment_reference("4")
comment = documents.comment(
comment_id="4",
@@ -621,8 +567,7 @@ def comment_references_are_linked_to_comment_after_main_body():
assert_equal(expected_html, result.value)
-@istest
-def when_initials_are_not_blank_then_comment_author_label_is_initials():
+def test_when_initials_are_not_blank_then_comment_author_label_is_initials():
assert_equal("TP", _comment_author_label(documents.comment(
comment_id="0",
body=[],
@@ -630,8 +575,7 @@ def when_initials_are_not_blank_then_comment_author_label_is_initials():
)))
-@istest
-def when_initials_are_blank_then_comment_author_label_is_blank():
+def test_when_initials_are_blank_then_comment_author_label_is_blank():
assert_equal("", _comment_author_label(documents.comment(
comment_id="0",
body=[],
diff --git a/tests/docx/body_xml_tests.py b/tests/docx/body_xml_tests.py
index d7f5509..eade1e6 100644
--- a/tests/docx/body_xml_tests.py
+++ b/tests/docx/body_xml_tests.py
@@ -3,10 +3,9 @@
import io
import sys
-from precisely import assert_that, is_sequence
-from nose.tools import istest, assert_equal
-from nose_parameterized import parameterized, param
import funk
+from precisely import assert_that, is_sequence
+import pytest
from mammoth import documents, results
from mammoth.docx.xmlparser import element as xml_element, text as xml_text
@@ -23,27 +22,25 @@ from .document_matchers import (
is_table,
is_row,
)
+from ..testing import assert_equal
if sys.version_info >= (3, ):
unichr = chr
-@istest
-def text_from_text_element_is_read():
+def test_text_from_text_element_is_read():
element = _text_element("Hello!")
assert_equal(documents.Text("Hello!"), _read_and_get_document_xml_element(element))
-@istest
-def can_read_text_within_run():
+def test_can_read_text_within_run():
element = _run_element_with_text("Hello!")
assert_equal(
documents.run([documents.Text("Hello!")]),
_read_and_get_document_xml_element(element)
)
-@istest
-def can_read_text_within_paragraph():
+def test_can_read_text_within_paragraph():
element = _paragraph_element_with_text("Hello!")
assert_equal(
documents.paragraph([documents.run([documents.Text("Hello!")])]),
@@ -51,15 +48,12 @@ def can_read_text_within_paragraph():
)
-@istest
class ParagraphTests(object):
- @istest
- def paragraph_has_no_style_if_it_has_no_properties(self):
+ def test_paragraph_has_no_style_if_it_has_no_properties(self):
element = xml_element("w:p")
assert_equal(None, _read_and_get_document_xml_element(element).style_id)
- @istest
- def paragraph_has_style_id_and_name_read_from_paragraph_properties_if_present(self):
+ def test_paragraph_has_style_id_and_name_read_from_paragraph_properties_if_present(self):
style_xml = xml_element("w:pStyle", {"w:val": "Heading1"})
properties_xml = xml_element("w:pPr", {}, [style_xml])
paragraph_xml = xml_element("w:p", {}, [properties_xml])
@@ -72,8 +66,7 @@ class ParagraphTests(object):
assert_equal("Heading1", paragraph.style_id)
assert_equal("Heading 1", paragraph.style_name)
- @istest
- def warning_is_emitted_when_paragraph_style_cannot_be_found(self):
+ def test_warning_is_emitted_when_paragraph_style_cannot_be_found(self):
style_xml = xml_element("w:pStyle", {"w:val": "Heading1"})
properties_xml = xml_element("w:pPr", {}, [style_xml])
paragraph_xml = xml_element("w:p", {}, [properties_xml])
@@ -84,27 +77,23 @@ class ParagraphTests(object):
assert_equal(None, paragraph.style_name)
assert_equal([results.warning("Paragraph style with ID Heading1 was referenced but not defined in the document")], result.messages)
- @istest
- def paragraph_has_no_justification_if_it_has_no_justificiation_properties(self):
+ def test_paragraph_has_no_justification_if_it_has_no_justificiation_properties(self):
paragraph_xml = xml_element("w:p")
paragraph = _read_and_get_document_xml_element(paragraph_xml)
assert_equal(None, paragraph.alignment)
- @istest
- def paragraph_has_justification_read_from_paragraph_properties_if_present(self):
+ def test_paragraph_has_justification_read_from_paragraph_properties_if_present(self):
justification_xml = xml_element("w:jc", {"w:val": "center"})
properties_xml = xml_element("w:pPr", {}, [justification_xml])
paragraph_xml = xml_element("w:p", {}, [properties_xml])
paragraph = _read_and_get_document_xml_element(paragraph_xml)
assert_equal("center", paragraph.alignment)
- @istest
- def paragraph_has_no_numbering_if_it_has_no_numbering_properties(self):
+ def test_paragraph_has_no_numbering_if_it_has_no_numbering_properties(self):
element = xml_element("w:p")
assert_equal(None, _read_and_get_document_xml_element(element).numbering)
- @istest
- def paragraph_has_numbering_properties_from_paragraph_properties_if_present(self):
+ def test_paragraph_has_numbering_properties_from_paragraph_properties_if_present(self):
paragraph_xml = self._paragraph_with_numbering_properties([
xml_element("w:ilvl", {"w:val": "1"}),
xml_element("w:numId", {"w:val": "42"}),
@@ -116,8 +105,7 @@ class ParagraphTests(object):
assert_equal("1", paragraph.numbering.level_index)
assert_equal(True, paragraph.numbering.is_ordered)
- @istest
- def numbering_on_paragraph_style_takes_precedence_over_numpr(self):
+ def test_numbering_on_paragraph_style_takes_precedence_over_numpr(self):
numbering_properties_xml = xml_element("w:numPr", {}, [
xml_element("w:ilvl", {"w:val": "1"}),
xml_element("w:numId", {"w:val": "42"}),
@@ -136,8 +124,7 @@ class ParagraphTests(object):
assert_equal(True, paragraph.numbering.is_ordered)
- @istest
- def numbering_properties_are_ignored_if_lvl_is_missing(self):
+ def test_numbering_properties_are_ignored_if_lvl_is_missing(self):
paragraph_xml = self._paragraph_with_numbering_properties([
xml_element("w:numId", {"w:val": "42"}),
])
@@ -147,8 +134,7 @@ class ParagraphTests(object):
assert_equal(None, paragraph.numbering)
- @istest
- def numbering_properties_are_ignored_if_num_id_is_missing(self):
+ def test_numbering_properties_are_ignored_if_num_id_is_missing(self):
paragraph_xml = self._paragraph_with_numbering_properties([
xml_element("w:ilvl", {"w:val": "1"}),
])
@@ -164,46 +150,38 @@ class ParagraphTests(object):
return xml_element("w:p", {}, [properties_xml])
-@istest
class ParagraphIndentTests(object):
- @istest
- def when_w_start_is_set_then_start_indent_is_read_from_w_start(self):
+ def test_when_w_start_is_set_then_start_indent_is_read_from_w_start(self):
paragraph_xml = self._paragraph_with_indent({"w:start": "720", "w:left": "40"})
paragraph = _read_and_get_document_xml_element(paragraph_xml)
assert_equal("720", paragraph.indent.start)
- @istest
- def when_w_start_is_not_set_then_start_indent_is_read_from_w_left(self):
+ def test_when_w_start_is_not_set_then_start_indent_is_read_from_w_left(self):
paragraph_xml = self._paragraph_with_indent({"w:left": "720"})
paragraph = _read_and_get_document_xml_element(paragraph_xml)
assert_equal("720", paragraph.indent.start)
- @istest
- def when_w_end_is_set_then_end_indent_is_read_from_w_end(self):
+ def test_when_w_end_is_set_then_end_indent_is_read_from_w_end(self):
paragraph_xml = self._paragraph_with_indent({"w:end": "720", "w:right": "40"})
paragraph = _read_and_get_document_xml_element(paragraph_xml)
assert_equal("720", paragraph.indent.end)
- @istest
- def when_w_end_is_not_set_then_end_indent_is_read_from_w_right(self):
+ def test_when_w_end_is_not_set_then_end_indent_is_read_from_w_right(self):
paragraph_xml = self._paragraph_with_indent({"w:right": "720"})
paragraph = _read_and_get_document_xml_element(paragraph_xml)
assert_equal("720", paragraph.indent.end)
- @istest
- def paragraph_has_indent_first_line_read_from_paragraph_properties_if_present(self):
+ def test_paragraph_has_indent_first_line_read_from_paragraph_properties_if_present(self):
paragraph_xml = self._paragraph_with_indent({"w:firstLine": "720"})
paragraph = _read_and_get_document_xml_element(paragraph_xml)
assert_equal("720", paragraph.indent.first_line)
- @istest
- def paragraph_has_indent_hanging_read_from_paragraph_properties_if_present(self):
+ def test_paragraph_has_indent_hanging_read_from_paragraph_properties_if_present(self):
paragraph_xml = self._paragraph_with_indent({"w:hanging": "720"})
paragraph = _read_and_get_document_xml_element(paragraph_xml)
assert_equal("720", paragraph.indent.hanging)
- @istest
- def when_indent_attributes_arent_set_then_indents_are_none(self):
+ def test_when_indent_attributes_arent_set_then_indents_are_none(self):
paragraph_xml = self._paragraph_with_indent({})
paragraph = _read_and_get_document_xml_element(paragraph_xml)
assert_equal(None, paragraph.indent.start)
@@ -217,15 +195,12 @@ class ParagraphIndentTests(object):
return xml_element("w:p", {}, [properties_xml])
-@istest
class RunTests(object):
- @istest
- def run_has_no_style_if_it_has_no_properties(self):
+ def test_run_has_no_style_if_it_has_no_properties(self):
element = xml_element("w:r")
assert_equal(None, _read_and_get_document_xml_element(element).style_id)
- @istest
- def run_has_style_id_and_name_read_from_run_properties_if_present(self):
+ def test_run_has_style_id_and_name_read_from_run_properties_if_present(self):
style_xml = xml_element("w:rStyle", {"w:val": "Heading1Char"})
styles = Styles.create(
@@ -236,8 +211,7 @@ class RunTests(object):
assert_equal("Heading1Char", run.style_id)
assert_equal("Heading 1 Char", run.style_name)
- @istest
- def warning_is_emitted_when_run_style_cannot_be_found(self):
+ def test_warning_is_emitted_when_run_style_cannot_be_found(self):
style_xml = xml_element("w:rStyle", {"w:val": "Heading1Char"})
properties_xml = xml_element("w:rPr", {}, [style_xml])
run_xml = xml_element("w:r", {}, [properties_xml])
@@ -249,139 +223,118 @@ class RunTests(object):
assert_equal([results.warning("Run style with ID Heading1Char was referenced but not defined in the document")], result.messages)
- @istest
- def run_is_not_bold_if_bold_element_is_not_present(self):
+ def test_run_is_not_bold_if_bold_element_is_not_present(self):
run = self._read_run_with_properties([])
assert_equal(False, run.is_bold)
- @istest
- def run_is_bold_if_bold_element_is_present(self):
+ def test_run_is_bold_if_bold_element_is_present(self):
run = self._read_run_with_properties([xml_element("w:b")])
assert_equal(True, run.is_bold)
- @istest
- def run_is_not_italic_if_italic_element_is_not_present(self):
+ def test_run_is_not_italic_if_italic_element_is_not_present(self):
run = self._read_run_with_properties([])
assert_equal(False, run.is_italic)
- @istest
- def run_is_italic_if_italic_element_is_present(self):
+ def test_run_is_italic_if_italic_element_is_present(self):
run = self._read_run_with_properties([xml_element("w:i")])
assert_equal(True, run.is_italic)
- @istest
- def run_is_not_underlined_if_underline_element_is_not_present(self):
+ def test_run_is_not_underlined_if_underline_element_is_not_present(self):
run = self._read_run_with_properties([])
assert_equal(False, run.is_underline)
- @istest
- def run_is_not_underlined_if_underline_element_is_present_without_val_attribute(self):
+ def test_run_is_not_underlined_if_underline_element_is_present_without_val_attribute(self):
run = self._read_run_with_properties([xml_element("w:u")])
assert_equal(False, run.is_underline)
- @istest
- def run_is_not_underlined_if_underline_element_is_present_and_val_is_false(self):
+ def test_run_is_not_underlined_if_underline_element_is_present_and_val_is_false(self):
run = self._read_run_with_properties([xml_element("w:u", {"w:val": "false"})])
assert_equal(False, run.is_underline)
- @istest
- def run_is_not_underlined_if_underline_element_is_present_and_val_is_0(self):
+ def test_run_is_not_underlined_if_underline_element_is_present_and_val_is_0(self):
run = self._read_run_with_properties([xml_element("w:u", {"w:val": "0"})])
assert_equal(False, run.is_underline)
- @istest
- def run_is_not_underlined_if_underline_element_is_present_and_val_is_none(self):
+ def test_run_is_not_underlined_if_underline_element_is_present_and_val_is_none(self):
run = self._read_run_with_properties([xml_element("w:u", {"w:val": "none"})])
assert_equal(False, run.is_underline)
- @istest
- def run_is_underlined_if_underline_element_is_present_and_val_is_not_none_or_falsy(self):
+ def test_run_is_underlined_if_underline_element_is_present_and_val_is_not_none_or_falsy(self):
run = self._read_run_with_properties([xml_element("w:u", {"w:val": "single"})])
assert_equal(True, run.is_underline)
- @istest
- def run_is_not_struckthrough_if_strikethrough_element_is_not_present(self):
+ def test_run_is_not_struckthrough_if_strikethrough_element_is_not_present(self):
run = self._read_run_with_properties([])
assert_equal(False, run.is_strikethrough)
- @istest
- def run_is_struckthrough_if_strikethrough_element_is_present(self):
+ def test_run_is_struckthrough_if_strikethrough_element_is_present(self):
run = self._read_run_with_properties([xml_element("w:strike")])
assert_equal(True, run.is_strikethrough)
- @istest
- def run_is_not_small_caps_if_small_caps_element_is_not_present(self):
+ def test_run_is_not_small_caps_if_small_caps_element_is_not_present(self):
run = self._read_run_with_properties([])
assert_equal(False, run.is_small_caps)
- @istest
- def run_is_small_caps_if_small_caps_element_is_present(self):
+ def test_run_is_small_caps_if_small_caps_element_is_present(self):
run = self._read_run_with_properties([xml_element("w:smallCaps")])
assert_equal(True, run.is_small_caps)
- run_boolean_property_test = lambda func: parameterized([
- param(attr_name="is_bold", tag_name="w:b"),
- param(attr_name="is_underline", tag_name="w:u"),
- param(attr_name="is_italic", tag_name="w:i"),
- param(attr_name="is_strikethrough", tag_name="w:strike"),
- param(attr_name="is_all_caps", tag_name="w:caps"),
- param(attr_name="is_small_caps", tag_name="w:smallCaps"),
- ])(istest(func))
-
- @run_boolean_property_test
- def run_boolean_property_is_false_if_element_is_present_and_val_is_false(self, attr_name, tag_name):
+ run_boolean_property_test_params = [
+ ("is_bold", "w:b"),
+ ("is_underline", "w:u"),
+ ("is_italic", "w:i"),
+ ("is_strikethrough", "w:strike"),
+ ("is_all_caps", "w:caps"),
+ ("is_small_caps", "w:smallCaps"),
+ ]
+
+ @pytest.mark.parametrize("attr_name, tag_name", run_boolean_property_test_params)
+ def test_run_boolean_property_is_false_if_element_is_present_and_val_is_false(self, attr_name, tag_name):
run = self._read_run_with_properties([xml_element(tag_name, {"w:val": "false"})])
assert_equal(False, getattr(run, attr_name))
- @run_boolean_property_test
- def run_boolean_property_is_false_if_element_is_present_and_val_is_0(self, attr_name, tag_name):
+ @pytest.mark.parametrize("attr_name, tag_name", run_boolean_property_test_params)
+ def test_run_boolean_property_is_false_if_element_is_present_and_val_is_0(self, attr_name, tag_name):
run = self._read_run_with_properties([xml_element(tag_name, {"w:val": "0"})])
assert_equal(False, getattr(run, attr_name))
- @run_boolean_property_test
- def run_boolean_property_is_true_if_element_is_present_and_val_is_true(self, attr_name, tag_name):
+ @pytest.mark.parametrize("attr_name, tag_name", run_boolean_property_test_params)
+ def test_run_boolean_property_is_true_if_element_is_present_and_val_is_true(self, attr_name, tag_name):
run = self._read_run_with_properties([xml_element(tag_name, {"w:val": "true"})])
assert_equal(True, getattr(run, attr_name))
- @run_boolean_property_test
- def run_boolean_property_is_true_if_element_is_present_and_val_is_1(self, attr_name, tag_name):
+ @pytest.mark.parametrize("attr_name, tag_name", run_boolean_property_test_params)
+ def test_run_boolean_property_is_true_if_element_is_present_and_val_is_1(self, attr_name, tag_name):
run = self._read_run_with_properties([xml_element(tag_name, {"w:val": "1"})])
assert_equal(True, getattr(run, attr_name))
- @istest
- def run_has_baseline_vertical_alignment_if_vertical_alignment_element_is_not_present(self):
+ def test_run_has_baseline_vertical_alignment_if_vertical_alignment_element_is_not_present(self):
run = self._read_run_with_properties([])
assert_equal(documents.VerticalAlignment.baseline, run.vertical_alignment)
- @istest
- def run_has_vertical_alignment_read_from_vertical_alignment_element(self):
+ def test_run_has_vertical_alignment_read_from_vertical_alignment_element(self):
run = self._read_run_with_properties([xml_element("w:vertAlign", {"w:val": "superscript"})])
assert_equal(documents.VerticalAlignment.superscript, run.vertical_alignment)
- @istest
- def run_has_none_font_by_default(self):
+ def test_run_has_none_font_by_default(self):
run = self._read_run_with_properties([])
assert_equal(None, run.font)
- @istest
- def run_has_font_read_from_properties(self):
+ def test_run_has_font_read_from_properties(self):
font_xml = xml_element("w:rFonts", {"w:ascii": "Arial"})
run = self._read_run_with_properties([font_xml])
assert_equal("Arial", run.font)
- @istest
- def run_has_none_font_size_by_default(self):
+ def test_run_has_none_font_size_by_default(self):
run = self._read_run_with_properties([])
assert_equal(None, run.font_size)
- @istest
- def run_has_font_size_read_from_properties(self):
+ def test_run_has_font_size_read_from_properties(self):
font_size_xml = xml_element("w:sz", {"w:val": "28"})
run = self._read_run_with_properties([font_size_xml])
assert_equal(14, run.font_size)
- @istest
- def run_with_invalid_w_sz_has_none_font_size(self):
+ def test_run_with_invalid_w_sz_has_none_font_size(self):
font_size_xml = xml_element("w:sz", {"w:val": "28a"})
run = self._read_run_with_properties([font_size_xml])
assert_equal(None, run.font_size)
@@ -392,7 +345,6 @@ class RunTests(object):
return _read_and_get_document_xml_element(run_xml, styles=styles)
-@istest
class ComplexFieldTests(object):
_URI = "http://example.com"
_BEGIN_COMPLEX_FIELD = xml_element("w:r", {}, [
@@ -417,8 +369,7 @@ class ComplexFieldTests(object):
def _is_empty_hyperlinked_run(self):
return self._is_hyperlinked_run(children=[])
- @istest
- def runs_in_a_complex_field_for_hyperlinks_without_switch_are_read_as_external_hyperlinks(self):
+ def test_runs_in_a_complex_field_for_hyperlinks_without_switch_are_read_as_external_hyperlinks(self):
element = xml_element("w:p", {}, [
self._BEGIN_COMPLEX_FIELD,
self._HYPERLINK_INSTRTEXT,
@@ -440,8 +391,7 @@ class ComplexFieldTests(object):
is_empty_run,
)))
- @istest
- def runs_in_a_complex_field_for_hyperlinks_with_l_switch_are_read_as_internal_hyperlinks(self):
+ def test_runs_in_a_complex_field_for_hyperlinks_with_l_switch_are_read_as_internal_hyperlinks(self):
element = xml_element("w:p", {}, [
self._BEGIN_COMPLEX_FIELD,
xml_element("w:instrText", {}, [
@@ -465,8 +415,7 @@ class ComplexFieldTests(object):
is_empty_run,
)))
- @istest
- def runs_after_a_complex_field_for_hyperlinks_are_not_read_as_hyperlinks(self):
+ def test_runs_after_a_complex_field_for_hyperlinks_are_not_read_as_hyperlinks(self):
element = xml_element("w:p", {}, [
self._BEGIN_COMPLEX_FIELD,
self._HYPERLINK_INSTRTEXT,
@@ -485,8 +434,7 @@ class ComplexFieldTests(object):
)),
)))
- @istest
- def can_handle_split_instr_text_elements(self):
+ def test_can_handle_split_instr_text_elements(self):
element = xml_element("w:p", {}, [
self._BEGIN_COMPLEX_FIELD,
xml_element("w:instrText", {}, [
@@ -513,8 +461,7 @@ class ComplexFieldTests(object):
is_empty_run,
)))
- @istest
- def hyperlink_is_not_ended_by_end_of_nested_complex_field(self):
+ def test_hyperlink_is_not_ended_by_end_of_nested_complex_field(self):
element = xml_element("w:p", {}, [
self._BEGIN_COMPLEX_FIELD,
self._HYPERLINK_INSTRTEXT,
@@ -545,8 +492,7 @@ class ComplexFieldTests(object):
is_empty_run,
)))
- @istest
- def complex_field_nested_within_a_hyperlink_complex_field_is_wrapped_with_the_hyperlink(self):
+ def test_complex_field_nested_within_a_hyperlink_complex_field_is_wrapped_with_the_hyperlink(self):
element = xml_element("w:p", {}, [
self._BEGIN_COMPLEX_FIELD,
self._HYPERLINK_INSTRTEXT,
@@ -577,8 +523,7 @@ class ComplexFieldTests(object):
is_empty_run,
)))
- @istest
- def field_without_separate_fld_char_is_ignored(self):
+ def test_field_without_separate_fld_char_is_ignored(self):
element = xml_element("w:p", {}, [
self._BEGIN_COMPLEX_FIELD,
self._HYPERLINK_INSTRTEXT,
@@ -605,43 +550,37 @@ class ComplexFieldTests(object):
)))
-@istest
-def can_read_tab_element():
+def test_can_read_tab_element():
element = xml_element("w:tab")
tab = _read_and_get_document_xml_element(element)
assert_equal(documents.tab(), tab)
-@istest
-def no_break_hyphen_element_is_read_as_non_breaking_hyphen_character():
+def test_no_break_hyphen_element_is_read_as_non_breaking_hyphen_character():
element = xml_element("w:noBreakHyphen")
tab = _read_and_get_document_xml_element(element)
assert_equal(documents.text(unichr(0x2011)), tab)
-@istest
-def soft_hyphen_element_is_read_as_soft_hyphen_character():
+def test_soft_hyphen_element_is_read_as_soft_hyphen_character():
element = xml_element("w:softHyphen")
tab = _read_and_get_document_xml_element(element)
assert_equal(documents.text(u"\u00ad"), tab)
-@istest
-def w_sym_with_supported_font_and_supported_code_point_in_ascii_range_is_converted_to_text():
+def test_w_sym_with_supported_font_and_supported_code_point_in_ascii_range_is_converted_to_text():
element = xml_element("w:sym", {"w:font": "Wingdings", "w:char": "28"})
text = _read_and_get_document_xml_element(element)
assert_equal(documents.text(u"🕿"), text)
-@istest
-def w_sym_with_supported_font_and_supported_code_point_in_private_use_area_is_converted_to_text():
+def test_w_sym_with_supported_font_and_supported_code_point_in_private_use_area_is_converted_to_text():
element = xml_element("w:sym", {"w:font": "Wingdings", "w:char": "F028"})
text = _read_and_get_document_xml_element(element)
assert_equal(documents.text(u"🕿"), text)
-@istest
-def w_sym_with_unsupported_font_and_code_point_produces_empty_result_with_warning():
+def test_w_sym_with_unsupported_font_and_code_point_produces_empty_result_with_warning():
element = xml_element("w:sym", {"w:font": "Dingwings", "w:char": "28"})
result = _read_document_xml_element(element)
@@ -651,10 +590,8 @@ def w_sym_with_unsupported_font_and_code_point_produces_empty_result_with_warnin
assert_equal(None, result.value)
-@istest
class TableTests(object):
- @istest
- def word_table_is_read_as_document_table_element(self):
+ def test_word_table_is_read_as_document_table_element(self):
element = xml_element("w:tbl", {}, [
xml_element("w:tr", {}, [
xml_element("w:tc", {}, [
@@ -672,13 +609,11 @@ class TableTests(object):
])
assert_equal(expected_result, table)
- @istest
- def table_has_no_style_if_it_has_no_properties(self):
+ def test_table_has_no_style_if_it_has_no_properties(self):
element = xml_element("w:tbl")
assert_equal(None, _read_and_get_document_xml_element(element).style_id)
- @istest
- def table_has_style_id_and_name_read_from_paragraph_properties_if_present(self):
+ def test_table_has_style_id_and_name_read_from_paragraph_properties_if_present(self):
style_xml = xml_element("w:tblStyle", {"w:val": "TableNormal"})
properties_xml = xml_element("w:tblPr", {}, [style_xml])
table_xml = xml_element("w:tbl", {}, [properties_xml])
@@ -691,8 +626,7 @@ class TableTests(object):
assert_equal("TableNormal", paragraph.style_id)
assert_equal("Normal Table", paragraph.style_name)
- @istest
- def warning_is_emitted_when_table_style_cannot_be_found(self):
+ def test_warning_is_emitted_when_table_style_cannot_be_found(self):
style_xml = xml_element("w:tblStyle", {"w:val": "TableNormal"})
properties_xml = xml_element("w:tblPr", {}, [style_xml])
table_xml = xml_element("w:tbl", {}, [properties_xml])
@@ -703,8 +637,7 @@ class TableTests(object):
assert_equal(None, table.style_name)
assert_equal([results.warning("Table style with ID TableNormal was referenced but not defined in the document")], result.messages)
- @istest
- def tbl_header_marks_table_row_as_header(self):
+ def test_tbl_header_marks_table_row_as_header(self):
element = xml_element("w:tbl", {}, [
xml_element("w:tr", {}, [
xml_element("w:trPr", {}, [
@@ -722,8 +655,7 @@ class TableTests(object):
))
- @istest
- def gridspan_is_read_as_colspan_for_table_cell(self):
+ def test_gridspan_is_read_as_colspan_for_table_cell(self):
element = xml_element("w:tbl", {}, [
xml_element("w:tr", {}, [
xml_element("w:tc", {}, [
@@ -745,8 +677,7 @@ class TableTests(object):
assert_equal(expected_result, table)
- @istest
- def vmerge_is_read_as_rowspan_for_table_cell(self):
+ def test_vmerge_is_read_as_rowspan_for_table_cell(self):
element = xml_element("w:tbl", {}, [
w_tr(w_tc()),
w_tr(w_tc(properties=[w_vmerge("restart")])),
@@ -765,8 +696,7 @@ class TableTests(object):
assert_equal(expected_result, result)
- @istest
- def vmerge_without_val_is_treated_as_continue(self):
+ def test_vmerge_without_val_is_treated_as_continue(self):
element = xml_element("w:tbl", {}, [
w_tr(w_tc(properties=[w_vmerge("restart")])),
w_tr(w_tc(properties=[w_vmerge(None)])),
@@ -779,8 +709,7 @@ class TableTests(object):
assert_equal(expected_result, result)
- @istest
- def vmerge_accounts_for_cells_spanning_columns(self):
+ def test_vmerge_accounts_for_cells_spanning_columns(self):
element = xml_element("w:tbl", {}, [
w_tr(w_tc(), w_tc(), w_tc(properties=[w_vmerge("restart")])),
w_tr(w_tc(properties=[w_gridspan("2")]), w_tc(properties=[w_vmerge("continue")])),
@@ -797,8 +726,7 @@ class TableTests(object):
assert_equal(expected_result, result)
- @istest
- def no_vertical_cell_merging_if_merged_cells_do_not_line_up(self):
+ def test_no_vertical_cell_merging_if_merged_cells_do_not_line_up(self):
element = xml_element("w:tbl", {}, [
w_tr(w_tc(properties=[w_gridspan("2")]), w_tc(properties=[w_vmerge("restart")])),
w_tr(w_tc(), w_tc(properties=[w_vmerge("continue")])),
@@ -811,42 +739,35 @@ class TableTests(object):
assert_equal(expected_result, result)
- @istest
- def warning_if_non_row_in_table(self):
+ def test_warning_if_non_row_in_table(self):
element = xml_element("w:tbl", {}, [xml_element("w:p")])
result = _read_document_xml_element(element)
expected_warning = results.warning("unexpected non-row element in table, cell merging may be incorrect")
assert_equal([expected_warning], result.messages)
- @istest
- def warning_if_non_cell_in_table_row(self):
+ def test_warning_if_non_cell_in_table_row(self):
element = xml_element("w:tbl", {}, [w_tr(xml_element("w:p"))])
result = _read_document_xml_element(element)
expected_warning = results.warning("unexpected non-cell element in table row, cell merging may be incorrect")
assert_equal([expected_warning], result.messages)
-@istest
-def children_of_w_ins_are_converted_normally():
+def test_children_of_w_ins_are_converted_normally():
_assert_children_are_converted_normally("w:ins")
-@istest
-def children_of_w_object_are_converted_normally():
+def test_children_of_w_object_are_converted_normally():
_assert_children_are_converted_normally("w:object")
-@istest
-def children_of_w_smart_tag_are_converted_normally():
+def test_children_of_w_smart_tag_are_converted_normally():
_assert_children_are_converted_normally("w:smartTag")
-@istest
-def children_of_v_group_are_converted_normally():
+def test_children_of_v_group_are_converted_normally():
_assert_children_are_converted_normally("v:group")
-@istest
-def children_of_v_rect_are_converted_normally():
+def test_children_of_v_rect_are_converted_normally():
_assert_children_are_converted_normally("v:rect")
@@ -862,10 +783,8 @@ def _assert_children_are_converted_normally(tag_name):
)
-@istest
class HyperlinkTests(object):
- @istest
- def hyperlink_is_read_as_external_hyperlink_if_it_has_a_relationship_id(self):
+ def test_hyperlink_is_read_as_external_hyperlink_if_it_has_a_relationship_id(self):
relationships = Relationships([
_hyperlink_relationship("r42", "http://example.com"),
])
@@ -876,8 +795,7 @@ class HyperlinkTests(object):
_read_and_get_document_xml_element(element, relationships=relationships)
)
- @istest
- def hyperlink_is_read_as_external_hyperlink_if_it_has_a_relationship_id_and_an_anchor(self):
+ def test_hyperlink_is_read_as_external_hyperlink_if_it_has_a_relationship_id_and_an_anchor(self):
relationships = Relationships([
_hyperlink_relationship("r42", "http://example.com/"),
])
@@ -888,8 +806,7 @@ class HyperlinkTests(object):
_read_and_get_document_xml_element(element, relationships=relationships)
)
- @istest
- def existing_fragment_is_replaced_when_anchor_is_set_on_external_link(self):
+ def test_existing_fragment_is_replaced_when_anchor_is_set_on_external_link(self):
relationships = Relationships([
_hyperlink_relationship("r42", "http://example.com/#previous"),
])
@@ -900,8 +817,7 @@ class HyperlinkTests(object):
_read_and_get_document_xml_element(element, relationships=relationships)
)
- @istest
- def hyperlink_is_read_as_internal_hyperlink_if_it_has_an_anchor_attribute(self):
+ def test_hyperlink_is_read_as_internal_hyperlink_if_it_has_an_anchor_attribute(self):
run_element = xml_element("w:r")
element = xml_element("w:hyperlink", {"w:anchor": "start"}, [run_element])
assert_equal(
@@ -909,8 +825,7 @@ class HyperlinkTests(object):
_read_and_get_document_xml_element(element)
)
- @istest
- def hyperlink_is_ignored_if_it_does_not_have_a_relationship_id_nor_anchor(self):
+ def test_hyperlink_is_ignored_if_it_does_not_have_a_relationship_id_nor_anchor(self):
run_element = xml_element("w:r")
element = xml_element("w:hyperlink", {}, [run_element])
assert_equal(
@@ -918,8 +833,7 @@ class HyperlinkTests(object):
_read_and_get_document_xml_element(element)
)
- @istest
- def target_frame_is_read(self):
+ def test_target_frame_is_read(self):
element = xml_element("w:hyperlink", {
"w:anchor": "start",
"w:tgtFrame": "_blank",
@@ -929,8 +843,7 @@ class HyperlinkTests(object):
is_hyperlink(target_frame="_blank"),
)
- @istest
- def empty_target_frame_is_ignored(self):
+ def test_empty_target_frame_is_ignored(self):
element = xml_element("w:hyperlink", {
"w:anchor": "start",
"w:tgtFrame": "",
@@ -941,15 +854,12 @@ class HyperlinkTests(object):
)
-@istest
class BookmarkTests(object):
- @istest
- def go_back_bookmark_is_ignored(self):
+ def test_go_back_bookmark_is_ignored(self):
element = xml_element("w:bookmarkStart", {"w:name": "_GoBack"})
assert_equal(None, _read_and_get_document_xml_element(element))
- @istest
- def bookmark_start_is_read_if_name_is_not_go_back(self):
+ def test_bookmark_start_is_read_if_name_is_not_go_back(self):
element = xml_element("w:bookmarkStart", {"w:name": "start"})
assert_equal(
documents.bookmark("start"),
@@ -957,34 +867,28 @@ class BookmarkTests(object):
)
-@istest
class BreakTests(object):
- @istest
- def br_without_explicit_type_is_read_as_line_break(self):
+ def test_br_without_explicit_type_is_read_as_line_break(self):
break_element = xml_element("w:br", {}, [])
result = _read_document_xml_element(break_element)
assert_equal(documents.line_break, result.value)
- @istest
- def br_with_text_wrapping_type_is_read_as_line_break(self):
+ def test_br_with_text_wrapping_type_is_read_as_line_break(self):
break_element = xml_element("w:br", {"w:type": "textWrapping"}, [])
result = _read_document_xml_element(break_element)
assert_equal(documents.line_break, result.value)
- @istest
- def br_with_page_type_is_read_as_page_break(self):
+ def test_br_with_page_type_is_read_as_page_break(self):
break_element = xml_element("w:br", {"w:type": "page"}, [])
result = _read_document_xml_element(break_element)
assert_equal(documents.page_break, result.value)
- @istest
- def br_with_column_type_is_read_as_column_break(self):
+ def test_br_with_column_type_is_read_as_column_break(self):
break_element = xml_element("w:br", {"w:type": "column"}, [])
result = _read_document_xml_element(break_element)
assert_equal(documents.column_break, result.value)
- @istest
- def warning_on_break_types_that_arent_recognised(self):
+ def test_warning_on_break_types_that_arent_recognised(self):
break_element = xml_element("w:br", {"w:type": "unknownBreakType"}, [])
result = _read_document_xml_element(break_element)
expected_warning = results.warning("Unsupported break type: unknownBreakType")
@@ -992,7 +896,6 @@ class BreakTests(object):
assert_equal(None, result.value)
-@istest
class ImageTests(object):
IMAGE_BYTES = b"Not an image at all!"
IMAGE_RELATIONSHIP_ID = "rId5"
@@ -1016,8 +919,7 @@ class ImageTests(object):
docx_file=docx_file,
)
- @istest
- def can_read_imagedata_elements_with_rid_attribute(self):
+ def test_can_read_imagedata_elements_with_rid_attribute(self):
imagedata_element = xml_element("v:imagedata", {
"r:id": self.IMAGE_RELATIONSHIP_ID,
"o:title": "It's a hat"
@@ -1031,8 +933,7 @@ class ImageTests(object):
with image.open() as image_file:
assert_equal(self.IMAGE_BYTES, image_file.read())
- @istest
- def when_imagedata_element_has_no_relationship_id_then_it_is_ignored_with_warning(self):
+ def test_when_imagedata_element_has_no_relationship_id_then_it_is_ignored_with_warning(self):
imagedata_element = xml_element("v:imagedata")
result = _read_document_xml_element(imagedata_element)
@@ -1041,8 +942,7 @@ class ImageTests(object):
assert_equal(None, result.value)
- @istest
- def can_read_inline_pictures(self):
+ def test_can_read_inline_pictures(self):
drawing_element = _create_inline_image(
blip=_embedded_blip(self.IMAGE_RELATIONSHIP_ID),
description="It's a hat",
@@ -1057,8 +957,7 @@ class ImageTests(object):
assert_equal(self.IMAGE_BYTES, image_file.read())
- @istest
- def alt_text_title_is_used_if_alt_text_description_is_missing(self):
+ def test_alt_text_title_is_used_if_alt_text_description_is_missing(self):
drawing_element = _create_inline_image(
blip=_embedded_blip(self.IMAGE_RELATIONSHIP_ID),
title="It's a hat",
@@ -1073,8 +972,7 @@ class ImageTests(object):
assert_equal(self.IMAGE_BYTES, image_file.read())
- @istest
- def alt_text_title_is_used_if_alt_text_description_is_blank(self):
+ def test_alt_text_title_is_used_if_alt_text_description_is_blank(self):
drawing_element = _create_inline_image(
blip=_embedded_blip(self.IMAGE_RELATIONSHIP_ID),
description=" ",
@@ -1090,8 +988,7 @@ class ImageTests(object):
assert_equal(self.IMAGE_BYTES, image_file.read())
- @istest
- def alt_text_description_is_preferred_to_alt_text_title(self):
+ def test_alt_text_description_is_preferred_to_alt_text_title(self):
drawing_element = _create_inline_image(
blip=_embedded_blip(self.IMAGE_RELATIONSHIP_ID),
description="It's a hat",
@@ -1106,8 +1003,7 @@ class ImageTests(object):
with image.open() as image_file:
assert_equal(self.IMAGE_BYTES, image_file.read())
- @istest
- def can_read_anchored_pictures(self):
+ def test_can_read_anchored_pictures(self):
drawing_element = _create_anchored_image(
blip=_embedded_blip(self.IMAGE_RELATIONSHIP_ID),
description="It's a hat",
@@ -1121,10 +1017,7 @@ class ImageTests(object):
with image.open() as image_file:
assert_equal(self.IMAGE_BYTES, image_file.read())
-
- @istest
- @funk.with_mocks
- def can_read_linked_pictures(self, mocks):
+ def test_can_read_linked_pictures(self, mocks):
drawing_element = _create_inline_image(
blip=_linked_blip("rId5"),
description="It's a hat",
@@ -1153,8 +1046,7 @@ class ImageTests(object):
with image.open() as image_file:
assert_equal(self.IMAGE_BYTES, image_file.read())
- @istest
- def warning_if_blip_has_no_image_file(self):
+ def test_warning_if_blip_has_no_image_file(self):
drawing = _create_inline_image(
blip=xml_element("a:blip"),
description="It's a hat",
@@ -1165,9 +1057,7 @@ class ImageTests(object):
assert_equal([results.warning("Could not find image file for a:blip element")], result.messages)
assert_equal(None, result.value)
- @istest
- @funk.with_mocks
- def warning_if_unsupported_image_type(self, mocks):
+ def test_warning_if_unsupported_image_type(self, mocks):
drawing_element = _create_inline_image(
blip=_embedded_blip("rId5"),
description="It's a hat",
@@ -1193,8 +1083,7 @@ class ImageTests(object):
expected_warning = results.warning("Image of type image/x-emf is unlikely to display in web browsers")
assert_equal([expected_warning], result.messages)
- @istest
- def no_elements_created_if_image_cannot_be_found_in_w_drawing(self):
+ def test_no_elements_created_if_image_cannot_be_found_in_w_drawing(self):
drawing = xml_element("w:drawing")
result = _read_document_xml_element(drawing)
@@ -1202,8 +1091,7 @@ class ImageTests(object):
assert_equal([], result.messages)
assert_equal(None, result.value)
- @istest
- def no_elements_created_if_image_cannot_be_found_in_wp_inline(self):
+ def test_no_elements_created_if_image_cannot_be_found_in_wp_inline(self):
drawing = xml_element("wp:inline")
result = _read_document_xml_element(drawing)
@@ -1212,47 +1100,40 @@ class ImageTests(object):
assert_equal(None, result.value)
-@istest
-def footnote_reference_has_id_read():
+def test_footnote_reference_has_id_read():
footnote_xml = xml_element("w:footnoteReference", {"w:id": "4"})
footnote = _read_and_get_document_xml_element(footnote_xml)
assert_equal("4", footnote.note_id)
-@istest
-def comment_reference_has_id_read():
+def test_comment_reference_has_id_read():
comment_reference_xml = xml_element("w:commentReference", {"w:id": "4"})
comment_reference = _read_and_get_document_xml_element(comment_reference_xml)
assert_equal(documents.CommentReference("4"), comment_reference)
-@istest
-def ignored_elements_are_ignored_without_message():
+def test_ignored_elements_are_ignored_without_message():
element = xml_element("w:bookmarkEnd")
result = _read_document_xml_element(element)
assert_equal(None, result.value)
assert_equal([], result.messages)
-@istest
-def unrecognised_elements_emit_warning():
+def test_unrecognised_elements_emit_warning():
element = xml_element("w:huh", {}, [])
result = _read_document_xml_element(element)
expected_warning = results.warning("An unrecognised element was ignored: w:huh")
assert_equal([expected_warning], result.messages)
-@istest
-def unrecognised_elements_are_ignored():
+def test_unrecognised_elements_are_ignored():
element = xml_element("w:huh", {}, [])
assert_equal(None, _read_document_xml_element(element).value)
-@istest
-def unrecognised_children_are_ignored():
+def test_unrecognised_children_are_ignored():
element = xml_element("w:r", {}, [_text_element("Hello!"), xml_element("w:huh", {}, [])])
assert_equal(
documents.run([documents.Text("Hello!")]),
_read_document_xml_element(element).value
)
-@istest
-def text_boxes_have_content_appended_after_containing_paragraph():
+def test_text_boxes_have_content_appended_after_containing_paragraph():
text_box = xml_element("w:pict", {}, [
xml_element("v:shape", {}, [
xml_element("v:textbox", {}, [
@@ -1268,8 +1149,7 @@ def text_boxes_have_content_appended_after_containing_paragraph():
result = _read_and_get_document_xml_elements(paragraph)
assert_equal(result[1].style_id, "textbox-content")
-@istest
-def alternate_content_is_read_using_fallback():
+def test_alternate_content_is_read_using_fallback():
element = xml_element("mc:AlternateContent", {}, [
xml_element("mc:Choice", {"Requires": "wps"}, [
_paragraph_with_style_id("first")
@@ -1281,8 +1161,7 @@ def alternate_content_is_read_using_fallback():
result = _read_and_get_document_xml_element(element)
assert_equal("second", result.style_id)
-@istest
-def sdt_is_read_using_sdt_content():
+def test_sdt_is_read_using_sdt_content():
element = xml_element("w:sdt", {}, [
xml_element("w:sdtContent", {}, [
xml_element("w:t", {}, [xml_text("Blackdown")]),
@@ -1291,8 +1170,7 @@ def sdt_is_read_using_sdt_content():
result = _read_and_get_document_xml_element(element)
assert_equal(documents.text("Blackdown"), result)
-@istest
-def text_nodes_are_ignored_when_reading_children():
+def test_text_nodes_are_ignored_when_reading_children():
element = xml_element("w:r", {}, [xml_text("[text]")])
assert_equal(
documents.run([]),
diff --git a/tests/docx/comments_xml_tests.py b/tests/docx/comments_xml_tests.py
index 1d5dd8d..010185f 100644
--- a/tests/docx/comments_xml_tests.py
+++ b/tests/docx/comments_xml_tests.py
@@ -1,13 +1,11 @@
-from nose.tools import istest, assert_equal
-
from mammoth import documents
from mammoth.docx.xmlparser import element as xml_element
from mammoth.docx.comments_xml import read_comments_xml_element
from mammoth.docx import body_xml
+from ..testing import assert_equal
-@istest
-def id_and_body_of_comment_is_read():
+def test_id_and_body_of_comment_is_read():
body = [xml_element("w:p")]
comments = read_comments_xml_element(xml_element("w:comments", {}, [
xml_element("w:comment", {"w:id": "1"}, body),
@@ -17,8 +15,7 @@ def id_and_body_of_comment_is_read():
assert_equal("1", comments.value[0].comment_id)
-@istest
-def when_optional_attributes_of_comment_are_missing_then_they_are_read_as_none():
+def test_when_optional_attributes_of_comment_are_missing_then_they_are_read_as_none():
comments = read_comments_xml_element(xml_element("w:comments", {}, [
xml_element("w:comment", {"w:id": "1"}, []),
]), body_reader=body_xml.reader())
@@ -27,8 +24,7 @@ def when_optional_attributes_of_comment_are_missing_then_they_are_read_as_none()
assert_equal(None, comment.author_initials)
-@istest
-def when_optional_attributes_of_comment_are_blank_then_they_are_read_as_none():
+def test_when_optional_attributes_of_comment_are_blank_then_they_are_read_as_none():
comments = read_comments_xml_element(xml_element("w:comments", {}, [
xml_element("w:comment", {"w:id": "1", "w:author": " ", "w:initials": " "}, []),
]), body_reader=body_xml.reader())
@@ -37,8 +33,7 @@ def when_optional_attributes_of_comment_are_blank_then_they_are_read_as_none():
assert_equal(None, comment.author_initials)
-@istest
-def when_optional_attributes_of_comment_are_not_blank_then_they_are_read():
+def test_when_optional_attributes_of_comment_are_not_blank_then_they_are_read():
comments = read_comments_xml_element(xml_element("w:comments", {}, [
xml_element("w:comment", {"w:id": "1", "w:author": "The Piemaker", "w:initials": "TP"}, []),
]), body_reader=body_xml.reader())
diff --git a/tests/docx/content_types_xml_tests.py b/tests/docx/content_types_xml_tests.py
index 8b104d9..14920b4 100644
--- a/tests/docx/content_types_xml_tests.py
+++ b/tests/docx/content_types_xml_tests.py
@@ -1,11 +1,9 @@
-from nose.tools import istest, assert_equal
-
from mammoth.docx.xmlparser import element as xml_element
from mammoth.docx.content_types_xml import read_content_types_xml_element
+from ..testing import assert_equal
-@istest
-def content_type_is_based_on_default_for_extension_if_there_is_no_override():
+def test_content_type_is_based_on_default_for_extension_if_there_is_no_override():
element = xml_element("content-types:Types", {}, [
xml_element("content-types:Default", {
"Extension": "png",
@@ -19,8 +17,7 @@ def content_type_is_based_on_default_for_extension_if_there_is_no_override():
)
-@istest
-def content_type_is_based_on_override_if_present():
+def test_content_type_is_based_on_override_if_present():
element = xml_element("content-types:Types", {}, [
xml_element("content-types:Default", {
"Extension": "png",
@@ -38,8 +35,7 @@ def content_type_is_based_on_override_if_present():
)
-@istest
-def fallback_content_types_have_common_image_types():
+def test_fallback_content_types_have_common_image_types():
element = xml_element("content-types:Types", {}, [])
content_types = read_content_types_xml_element(element)
assert_equal(
@@ -72,8 +68,7 @@ def fallback_content_types_have_common_image_types():
)
-@istest
-def fallback_content_types_are_case_insensitive():
+def test_fallback_content_types_are_case_insensitive():
element = xml_element("content-types:Types", {}, [])
content_types = read_content_types_xml_element(element)
assert_equal(
diff --git a/tests/docx/document_xml_tests.py b/tests/docx/document_xml_tests.py
index fa63775..e93392c 100644
--- a/tests/docx/document_xml_tests.py
+++ b/tests/docx/document_xml_tests.py
@@ -1,33 +1,29 @@
-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 import body_xml
+from ..testing import assert_equal
-@istest
class ReadXmlElementTests(object):
- @istest
- def can_read_text_within_document(self):
+ def test_can_read_text_within_document(self):
element = _document_element_with_text("Hello!")
assert_equal(
documents.document([documents.paragraph([documents.run([documents.Text("Hello!")])])]),
_read_and_get_document_xml_element(element)
)
-
- @istest
- def footnotes_of_document_are_read(self):
+
+ def test_footnotes_of_document_are_read(self):
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, notes=notes)
footnote = document.notes.find_note("footnote", "4")
assert_equal("4", footnote.note_id)
assert isinstance(footnote.body[0], documents.Paragraph)
-
+
def _read_and_get_document_xml_element(*args, **kwargs):
body_reader = body_xml.reader()
diff --git a/tests/docx/docx_tests.py b/tests/docx/docx_tests.py
index 830f334..ee6b928 100644
--- a/tests/docx/docx_tests.py
+++ b/tests/docx/docx_tests.py
@@ -2,17 +2,13 @@ import io
import textwrap
import zipfile
-from nose.tools import istest, assert_equal
-
from mammoth import docx, documents, zips
-from ..testing import assert_raises, test_path
+from ..testing import assert_equal, assert_raises, generate_test_path
-@istest
class ReadTests(object):
- @istest
- def can_read_document_with_single_paragraph_with_single_run_of_text(self):
- with open(test_path("single-paragraph.docx"), "rb") as fileobj:
+ def test_can_read_document_with_single_paragraph_with_single_run_of_text(self):
+ with open(generate_test_path("single-paragraph.docx"), "rb") as fileobj:
result = docx.read(fileobj=fileobj)
expected_document = documents.document([
documents.paragraph([
@@ -29,8 +25,7 @@ _relationship_namespaces = {
}
-@istest
-def main_document_is_found_using_package_relationships():
+def test_main_document_is_found_using_package_relationships():
fileobj = _create_zip({
"word/document2.xml": textwrap.dedent("""\
@@ -62,8 +57,7 @@ def main_document_is_found_using_package_relationships():
assert_equal(expected_document, result.value)
-@istest
-def error_is_raised_when_main_document_part_does_not_exist():
+def test_error_is_raised_when_main_document_part_does_not_exist():
fileobj = _create_zip({
"_rels/.rels": textwrap.dedent("""\
@@ -78,9 +72,8 @@ def error_is_raised_when_main_document_part_does_not_exist():
str(error),
)
-class TestPartPaths(object):
- @istest
- def main_document_part_is_found_using_package_relationships(self):
+class PartPathsTests(object):
+ def test_main_document_part_is_found_using_package_relationships(self):
fileobj = _create_zip({
"word/document2.xml": " ",
"_rels/.rels": textwrap.dedent("""\
@@ -92,55 +85,44 @@ class TestPartPaths(object):
})
part_paths = self._find_part_paths(fileobj)
assert_equal("word/document2.xml", part_paths.main_document)
-
- @istest
- def when_relationship_for_main_document_cannot_be_found_then_fallback_is_used(self):
+
+ def test_when_relationship_for_main_document_cannot_be_found_then_fallback_is_used(self):
fileobj = _create_zip({
"word/document.xml": " ",
})
part_paths = self._find_part_paths(fileobj)
assert_equal("word/document.xml", part_paths.main_document)
-
- @istest
- def comments_part_is_found_using_main_document_relationships(self):
+
+ def test_comments_part_is_found_using_main_document_relationships(self):
self._assert_path_is_found_using_main_document_relationships("comments")
-
- @istest
- def when_relationship_for_comments_cannot_be_found_then_fallback_is_used(self):
+
+ def test_when_relationship_for_comments_cannot_be_found_then_fallback_is_used(self):
self._assert_when_relationship_for_part_cannot_be_found_then_fallback_is_used("comments")
-
- @istest
- def endnotes_part_is_found_using_main_document_relationships(self):
+
+ def test_endnotes_part_is_found_using_main_document_relationships(self):
self._assert_path_is_found_using_main_document_relationships("endnotes")
-
- @istest
- def when_relationship_for_endnotes_cannot_be_found_then_fallback_is_used(self):
+
+ def test_when_relationship_for_endnotes_cannot_be_found_then_fallback_is_used(self):
self._assert_when_relationship_for_part_cannot_be_found_then_fallback_is_used("endnotes")
-
- @istest
- def footnotes_part_is_found_using_main_document_relationships(self):
+
+ def test_footnotes_part_is_found_using_main_document_relationships(self):
self._assert_path_is_found_using_main_document_relationships("footnotes")
-
- @istest
- def when_relationship_for_footnotes_cannot_be_found_then_fallback_is_used(self):
+
+ def test_when_relationship_for_footnotes_cannot_be_found_then_fallback_is_used(self):
self._assert_when_relationship_for_part_cannot_be_found_then_fallback_is_used("footnotes")
-
- @istest
- def numbering_part_is_found_using_main_document_relationships(self):
+
+ def test_numbering_part_is_found_using_main_document_relationships(self):
self._assert_path_is_found_using_main_document_relationships("numbering")
-
- @istest
- def when_relationship_for_numbering_cannot_be_found_then_fallback_is_used(self):
+
+ def test_when_relationship_for_numbering_cannot_be_found_then_fallback_is_used(self):
self._assert_when_relationship_for_part_cannot_be_found_then_fallback_is_used("numbering")
-
- @istest
- def styles_part_is_found_using_main_document_relationships(self):
+
+ def test_styles_part_is_found_using_main_document_relationships(self):
self._assert_path_is_found_using_main_document_relationships("styles")
-
- @istest
- def when_relationship_for_styles_cannot_be_found_then_fallback_is_used(self):
+
+ def test_when_relationship_for_styles_cannot_be_found_then_fallback_is_used(self):
self._assert_when_relationship_for_part_cannot_be_found_then_fallback_is_used("styles")
-
+
def _assert_path_is_found_using_main_document_relationships(self, name):
fileobj = _create_zip({
"_rels/.rels": textwrap.dedent("""\
@@ -160,7 +142,7 @@ class TestPartPaths(object):
})
part_paths = self._find_part_paths(fileobj)
assert_equal("word/target-path.xml", getattr(part_paths, name))
-
+
def _assert_when_relationship_for_part_cannot_be_found_then_fallback_is_used(self, name):
fileobj = _create_zip({
"_rels/.rels": textwrap.dedent("""\
@@ -173,21 +155,21 @@ class TestPartPaths(object):
})
part_paths = self._find_part_paths(fileobj)
assert_equal("word/{0}.xml".format(name), getattr(part_paths, name))
-
-
+
+
def _find_part_paths(self, fileobj):
return docx._find_part_paths(zips.open_zip(fileobj, "r"))
def _create_zip(files):
fileobj = io.BytesIO()
-
+
zip_file = zipfile.ZipFile(fileobj, "w")
try:
for name, contents in files.items():
zip_file.writestr(name, contents)
finally:
zip_file.close()
-
+
fileobj.seek(0)
return fileobj
diff --git a/tests/docx/files_tests.py b/tests/docx/files_tests.py
index f6c0120..6845cc2 100644
--- a/tests/docx/files_tests.py
+++ b/tests/docx/files_tests.py
@@ -1,12 +1,9 @@
-from nose.tools import istest, assert_equal
-
from mammoth.docx.files import Files, InvalidFileReferenceError
-from ..testing import test_path, assert_raises
+from ..testing import generate_test_path, assert_equal, assert_raises
-@istest
-def can_open_files_with_file_uri():
- path = test_path("tiny-picture.png")
+def test_can_open_files_with_file_uri():
+ path = generate_test_path("tiny-picture.png")
files = Files(None)
with files.open("file:///" + path) as image_file:
contents = image_file.read()
@@ -15,18 +12,16 @@ def can_open_files_with_file_uri():
assert_equal(source_file.read(), contents)
-@istest
-def can_open_files_with_relative_uri():
- files = Files(test_path(""))
+def test_can_open_files_with_relative_uri():
+ files = Files(generate_test_path(""))
with files.open("tiny-picture.png") as image_file:
contents = image_file.read()
assert_equal(bytes, type(contents))
- with open(test_path("tiny-picture.png"), "rb") as source_file:
+ with open(generate_test_path("tiny-picture.png"), "rb") as source_file:
assert_equal(source_file.read(), contents)
-@istest
-def given_base_is_not_set_when_opening_relative_uri_then_error_is_raised():
+def test_given_base_is_not_set_when_opening_relative_uri_then_error_is_raised():
files = Files(None)
error = assert_raises(InvalidFileReferenceError, lambda: files.open("not-a-real-file.png"))
expected_message = (
@@ -35,8 +30,7 @@ def given_base_is_not_set_when_opening_relative_uri_then_error_is_raised():
assert_equal(expected_message, str(error))
-@istest
-def error_is_raised_if_relative_uri_cannot_be_opened():
+def test_error_is_raised_if_relative_uri_cannot_be_opened():
files = Files("/tmp")
error = assert_raises(InvalidFileReferenceError, lambda: files.open("not-a-real-file.png"))
expected_message = (
@@ -46,8 +40,7 @@ def error_is_raised_if_relative_uri_cannot_be_opened():
assert_equal(expected_message, str(error))
-@istest
-def error_is_raised_if_file_uri_cannot_be_opened():
+def test_error_is_raised_if_file_uri_cannot_be_opened():
files = Files("/tmp")
error = assert_raises(InvalidFileReferenceError, lambda: files.open("file:///not-a-real-file.png"))
expected_message = "could not open external image: 'file:///not-a-real-file.png' (document directory: '/tmp')\n"
diff --git a/tests/docx/notes_xml_tests.py b/tests/docx/notes_xml_tests.py
index 56a7681..086e6d8 100644
--- a/tests/docx/notes_xml_tests.py
+++ b/tests/docx/notes_xml_tests.py
@@ -1,13 +1,11 @@
-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 import body_xml
+from ..testing import assert_equal
-@istest
-def id_and_body_of_footnote_are_read():
+def test_id_and_body_of_footnote_are_read():
footnote_body = [xml_element("w:p")]
footnotes = read_footnotes_xml_element(xml_element("w:footnotes", {}, [
xml_element("w:footnote", {"w:id": "1"}, footnote_body),
@@ -17,13 +15,11 @@ def id_and_body_of_footnote_are_read():
assert_equal("1", footnotes.value[0].note_id)
-@istest
-def continuation_separator_is_ignored():
+def test_continuation_separator_is_ignored():
_assert_footnote_type_is_ignored("continuationSeparator")
-@istest
-def separator_is_ignored():
+def test_separator_is_ignored():
_assert_footnote_type_is_ignored("separator")
@@ -33,4 +29,4 @@ def _assert_footnote_type_is_ignored(footnote_type):
xml_element("w:footnote", {"w:id": "1", "w:type": footnote_type}, footnote_body),
]), body_reader=None)
assert_equal(0, len(footnotes.value))
-
+
diff --git a/tests/docx/numbering_xml_tests.py b/tests/docx/numbering_xml_tests.py
index 6c1d843..b6959a6 100644
--- a/tests/docx/numbering_xml_tests.py
+++ b/tests/docx/numbering_xml_tests.py
@@ -1,12 +1,10 @@
-from nose.tools import istest, assert_equal
-
from mammoth.docx.xmlparser import element as xml_element
from mammoth.docx.numbering_xml import read_numbering_xml_element
from mammoth.docx.styles_xml import NumberingStyle, Styles
+from ..testing import assert_equal
-@istest
-def find_level_returns_none_if_num_with_id_cannot_be_found():
+def test_find_level_returns_none_if_num_with_id_cannot_be_found():
numbering = _read_numbering_xml_element(xml_element("w:numbering"))
assert_equal(None, numbering.find_level("47", "0"))
@@ -26,32 +24,27 @@ _sample_numbering_xml = xml_element("w:numbering", {}, [
])
-@istest
-def level_includes_level_index():
+def test_level_includes_level_index():
numbering = _read_numbering_xml_element(_sample_numbering_xml)
assert_equal("0", numbering.find_level("47", "0").level_index)
assert_equal("1", numbering.find_level("47", "1").level_index)
-@istest
-def list_is_not_ordered_if_formatted_as_bullet():
+def test_list_is_not_ordered_if_formatted_as_bullet():
numbering = _read_numbering_xml_element(_sample_numbering_xml)
assert_equal(False, numbering.find_level("47", "0").is_ordered)
-@istest
-def list_is_ordered_if_formatted_as_decimal():
+def test_list_is_ordered_if_formatted_as_decimal():
numbering = _read_numbering_xml_element(_sample_numbering_xml)
assert_equal(True, numbering.find_level("47", "1").is_ordered)
-@istest
-def find_level_returns_none_if_level_cannot_be_found():
+def test_find_level_returns_none_if_level_cannot_be_found():
numbering = _read_numbering_xml_element(_sample_numbering_xml)
assert_equal(None, numbering.find_level("47", "2"))
-@istest
-def num_referencing_non_existent_abstract_num_is_ignored():
+def test_num_referencing_non_existent_abstract_num_is_ignored():
element = xml_element("w:numbering", {}, [
xml_element("w:num", {"w:numId": "47"}, [
xml_element("w:abstractNumId", {"w:val": "42"})
@@ -63,8 +56,7 @@ def num_referencing_non_existent_abstract_num_is_ignored():
assert_equal(None, numbering.find_level("47", "0"))
-@istest
-def when_abstract_num_has_num_style_link_then_style_is_used_to_find_num():
+def test_when_abstract_num_has_num_style_link_then_style_is_used_to_find_num():
numbering = _read_numbering_xml_element(
xml_element("w:numbering", {}, [
xml_element("w:abstractNum", {"w:abstractNumId": "100"}, [
@@ -88,8 +80,7 @@ def when_abstract_num_has_num_style_link_then_style_is_used_to_find_num():
# See: 17.9.23 pStyle (Paragraph Style's Associated Numbering Level) in ECMA-376, 4th Edition
-@istest
-def numbering_level_can_be_found_by_paragraph_style_id():
+def test_numbering_level_can_be_found_by_paragraph_style_id():
numbering = _read_numbering_xml_element(
xml_element("w:numbering", {}, [
xml_element("w:abstractNum", {"w:abstractNumId": "42"}, [
diff --git a/tests/docx/office_xml_tests.py b/tests/docx/office_xml_tests.py
index 5b8b1e1..f87fa75 100644
--- a/tests/docx/office_xml_tests.py
+++ b/tests/docx/office_xml_tests.py
@@ -2,13 +2,11 @@ from __future__ import unicode_literals
import io
-from nose.tools import istest, assert_equal
-
from mammoth.docx import xmlparser as xml, office_xml
+from ..testing import assert_equal
-@istest
-def alternate_content_is_replaced_by_contents_of_fallback():
+def test_alternate_content_is_replaced_by_contents_of_fallback():
xml_string = (
'' +
'