From 8d867ec2a5d2d781afd6d426fc67498f2969a0da Mon Sep 17 00:00:00 2001 From: Vassilii Khachaturov Date: Sun, 8 Sep 2013 19:35:15 +0000 Subject: [PATCH] refactor test svn: r23059 --- gramps/gen/lib/test/date_test.py | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/gramps/gen/lib/test/date_test.py b/gramps/gen/lib/test/date_test.py index 7cc92ea77..8cfe9c1ee 100644 --- a/gramps/gen/lib/test/date_test.py +++ b/gramps/gen/lib/test/date_test.py @@ -476,32 +476,26 @@ class Test_set2(BaseDateTest): self.assertEqual(start, (1000, 10, 10)) self.assertEqual(stop, (1000, 10, 10)) - def test_set2_ymd_raises_error_unless_compound(self): + def _test_set2_function_raises_error_unless_compound(self, function): for mod in (Date.MOD_NONE, Date.MOD_BEFORE, Date.MOD_AFTER, Date.MOD_ABOUT, Date.MOD_TEXTONLY): self.date.set_modifier(mod) try: - self.date.set2_yr_mon_day(2013, 2, 2) + function(self.date) self.assertTrue(False, "Modifier: {}, dateval: {} - exception expected!".format( mod, self.date.dateval)) except DateError: pass + def test_set2_ymd_raises_error_unless_compound(self): + self._test_set2_function_raises_error_unless_compound( + lambda date: date.set2_yr_mon_day(2013, 2, 2)) + def test_set2_ymd_offset_raises_error_unless_compound(self): - for mod in (Date.MOD_NONE, Date.MOD_BEFORE, Date.MOD_AFTER, - Date.MOD_ABOUT, - Date.MOD_TEXTONLY): - self.date.set_modifier(mod) - try: - self.date.set2_yr_mon_day_offset(year=-1) - self.assertTrue(False, - "Modifier: {}, dateval: {} - exception expected!".format( - mod, self.date.dateval)) - except DateError: - pass - + self._test_set2_function_raises_error_unless_compound( + lambda date: date.set2_yr_mon_day_offset(year=-1)) if __name__ == "__main__": unittest.main()