From 1a71c66575ccc752b8feecdcf7187387a03155cb Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 4 Oct 2016 21:57:35 +0100 Subject: Parameterise tests for run Boolean properties --- test-requirements.txt | 1 + tests/docx/body_xml_tests.py | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/test-requirements.txt b/test-requirements.txt index 145f16b..7eb8e83 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -3,3 +3,4 @@ funk>=0.4,<0.5 spur.local>=0.3.7,<0.4 tempman>=0.1.2,<0.2 pyflakes>=0.8.1,<0.9 +nose-parameterized==0.5.0 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): -- cgit v1.2.3