diff options
| author | Michael Williamson <mike@zwobble.org> | 2022-11-25 22:50:05 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2022-11-25 22:58:16 +0000 |
| commit | 5093d72b9fece1a7c3d7a3d19e4161387ee6475a (patch) | |
| tree | c4122b0f72c7864897d78333e75328ac8c22685b /tests/docx/body_xml_tests.py | |
| parent | 20e3e61530bef546058124c3015ae240733cc974 (diff) | |
Use pytest instead of nose
Diffstat (limited to 'tests/docx/body_xml_tests.py')
| -rw-r--r-- | tests/docx/body_xml_tests.py | 382 |
1 files changed, 130 insertions, 252 deletions
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([]), |
