From 02d175b10b9d8ac9a1570d0f143f7ea3df14093f Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Fri, 7 Mar 2014 01:09:23 +0000 Subject: [PATCH 1/4] Tests - Include task stdout/err if exit code != 0 --- test/basetest/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/basetest/__init__.py b/test/basetest/__init__.py index b6cd4e0c3..4240e3314 100644 --- a/test/basetest/__init__.py +++ b/test/basetest/__init__.py @@ -137,7 +137,7 @@ class BaseTestCase(unittest.TestCase): out = self.callTask(args, input, merge_streams) self.assertEqual(out[0], 0, "Task finished with non-zero ({0}) exit " - "code".format(out[0])) + "code\nOUTPUT: {1}".format(out[0], out[1])) return out def callTaskError(self, args, input=None, merge_streams=True): From be59e526f1f730ee955bc73b181f543dd55b32f8 Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Sun, 13 Apr 2014 19:51:00 +0100 Subject: [PATCH 2/4] Rename method to match the current testing API --- test/bug.1254.t | 2 +- test/bug.360.t | 2 +- test/tw-1300.t | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/bug.1254.t b/test/bug.1254.t index 787154df6..63dceadc8 100755 --- a/test/bug.1254.t +++ b/test/bug.1254.t @@ -51,7 +51,7 @@ class BaseTestBug1254(BaseTestCase): os.remove(file) @classmethod - def cleanup(cls): + def finish(cls): os.remove("bug.rc") diff --git a/test/bug.360.t b/test/bug.360.t index 9f268e357..293043b15 100755 --- a/test/bug.360.t +++ b/test/bug.360.t @@ -59,7 +59,7 @@ class BaseTestBug360(BaseTestCase): os.remove(file) @classmethod - def cleanup(cls): + def finish(cls): os.remove("bug.rc") diff --git a/test/tw-1300.t b/test/tw-1300.t index 2fa288243..696d7c611 100755 --- a/test/tw-1300.t +++ b/test/tw-1300.t @@ -51,7 +51,7 @@ class BaseTestBug1300(BaseTestCase): os.remove(file) @classmethod - def cleanup(cls): + def finish(cls): os.remove("bug.rc") From 2e64231886dffc6ae2b41158f199ada2602ca544 Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Sun, 13 Apr 2014 20:10:47 +0100 Subject: [PATCH 3/4] Refactor testing framework to allow using callTask* methods inside @classmethods --- test/basetest/__init__.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/test/basetest/__init__.py b/test/basetest/__init__.py index 4240e3314..7665f467c 100644 --- a/test/basetest/__init__.py +++ b/test/basetest/__init__.py @@ -83,7 +83,8 @@ class BaseTestCase(unittest.TestCase): """ pass - def callTask(self, args, input=None, merge_streams=True): + @classmethod + def callTask(cls, args, input=None, merge_streams=True): """Invoke src/task with the given arguments Use callTaskSuccess or callTaskError if you want exit_code to be tested @@ -122,7 +123,8 @@ class BaseTestCase(unittest.TestCase): return p.returncode, out, err - def callTaskSuccess(self, args, input=None, merge_streams=True): + @classmethod + def callTaskSuccess(cls, args, input=None, merge_streams=True): """Invoke src/task with the given arguments and expect a zero exit code. Causes test to fail if exit_code != 0 @@ -134,13 +136,14 @@ class BaseTestCase(unittest.TestCase): Returns (exit_code, stdout, stderr) """ - out = self.callTask(args, input, merge_streams) + out = cls.callTask(args, input, merge_streams) - self.assertEqual(out[0], 0, "Task finished with non-zero ({0}) exit " - "code\nOUTPUT: {1}".format(out[0], out[1])) + assert out[0] == 0, ("Task finished with non-zero ({0}) exit code\n" + "OUTPUT: {1}".format(out[0], out[1])) return out - def callTaskError(self, args, input=None, merge_streams=True): + @classmethod + def callTaskError(cls, args, input=None, merge_streams=True): """Invoke src/task with the given arguments and expect a non-zero exit code. Causes test to fail if exit_code == 0 @@ -152,9 +155,9 @@ class BaseTestCase(unittest.TestCase): Returns (exit_code, stdout, stderr) """ - out = self.callTask(args, input, merge_streams) + out = cls.callTask(args, input, merge_streams) - self.assertNotEqual(out[0], 0, "Task finished with zero exit (0) code") + assert out[0] != 0, "Task finished with zero exit (0) code" return out From 13d79618136a3aa1c5e97c19af2d20100a31415e Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Sun, 13 Apr 2014 20:12:55 +0100 Subject: [PATCH 4/4] Refactor some tests to avoid redoing setUp/tearDown once per test --- test/tw-1300.t | 8 ++------ test/tw-285.t | 27 +++++++++------------------ 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/test/tw-1300.t b/test/tw-1300.t index 696d7c611..aed8b8285 100755 --- a/test/tw-1300.t +++ b/test/tw-1300.t @@ -43,15 +43,11 @@ class BaseTestBug1300(BaseTestCase): fh.write("data.location=.\n" "confirmation=no\n") - def tearDown(self): - """Needed after each test or setUp will cause duplicated data at start - of the next test. - """ + @classmethod + def finish(cls): for file in glob("*.data"): os.remove(file) - @classmethod - def finish(cls): os.remove("bug.rc") diff --git a/test/tw-285.t b/test/tw-285.t index bec498c59..79fa86818 100755 --- a/test/tw-285.t +++ b/test/tw-285.t @@ -44,9 +44,6 @@ class BaseTest285(BaseTestCase): "verbose=nothing\n" "confirmation=no\n") - def setUp(self): - """Executed before each test in the class""" - # OVERDUE YESTERDAY DUE TODAY TOMORROW WEEK MONTH YEAR # due:-1week Y - - - - ? ? ? # due:-1day Y Y - - - ? ? ? @@ -56,27 +53,21 @@ class BaseTest285(BaseTestCase): # due:1month - - - - - - - ? # due:1year - - - - - - - - - self.callTaskSuccess(['rc:bug.rc', 'add', 'due_last_week', 'due:-1week']) - self.callTaskSuccess(['rc:bug.rc', 'add', 'due_yesterday', 'due:-1day']) - self.callTaskSuccess(['rc:bug.rc', 'add', 'due_earlier_today', 'due:today']) - self.callTaskSuccess(['rc:bug.rc', 'add', 'due_later_today', 'due:tomorrow']) - self.callTaskSuccess(['rc:bug.rc', 'add', 'due_three_days', 'due:3days']) - self.callTaskSuccess(['rc:bug.rc', 'add', 'due_next_month', 'due:1month']) - self.callTaskSuccess(['rc:bug.rc', 'add', 'due_next_year', 'due:1year']) - - def tearDown(self): - """Needed after each test or setUp will cause duplicated data at start - of the next test. - """ - for file in glob("*.data"): - os.remove(file) + cls.callTaskSuccess(['rc:bug.rc', 'add', 'due_last_week', 'due:-1week']) + cls.callTaskSuccess(['rc:bug.rc', 'add', 'due_yesterday', 'due:-1day']) + cls.callTaskSuccess(['rc:bug.rc', 'add', 'due_earlier_today', 'due:today']) + cls.callTaskSuccess(['rc:bug.rc', 'add', 'due_later_today', 'due:tomorrow']) + cls.callTaskSuccess(['rc:bug.rc', 'add', 'due_three_days', 'due:3days']) + cls.callTaskSuccess(['rc:bug.rc', 'add', 'due_next_month', 'due:1month']) + cls.callTaskSuccess(['rc:bug.rc', 'add', 'due_next_year', 'due:1year']) @classmethod def finish(cls): - os.remove("bug.rc") for file in glob("*.data"): os.remove(file) + os.remove("bug.rc") + class Test285(BaseTest285): def test_overdue(self):