diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-10-04 21:57:35 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-10-04 21:57:35 +0100 |
| commit | 1a71c66575ccc752b8feecdcf7187387a03155cb (patch) | |
| tree | d81a95bd7a509673315657d74ed11287927f808d /tests | |
| parent | 4e4d6bb11f417e28485b265510e554fc814c86ac (diff) | |
Parameterise tests for run Boolean properties
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/docx/body_xml_tests.py | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/tests/docx/body_xml_tests.py b/tests/docx/body_xml_tests.py index b09aba7..3024bde 100644 --- a/tests/docx/body_xml_tests.py +++ b/tests/docx/body_xml_tests.py @@ -1,6 +1,7 @@ import io from nose.tools import istest, assert_equal +from nose_parameterized import parameterized, param import funk from mammoth import documents, results @@ -174,21 +175,28 @@ class ReadXmlElementTests(object): def 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_not_struckthrough_if_strikethrough_element_is_present_and_false(self): - run = self._read_run_with_properties([xml_element("w:strike", {"w:val": "false"})]) - assert_equal(False, run.is_strikethrough) @istest def 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_struckthrough_if_strikethrough_element_is_present_and_true(self): - run = self._read_run_with_properties([xml_element("w:strike", {"w:val": "true"})]) - assert_equal(True, run.is_strikethrough) + + 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"), + ])(istest(func)) + + @run_boolean_property_test + def 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_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)) @istest def run_has_baseline_vertical_alignment_if_vertical_alignment_element_is_not_present(self): |
