From 30b3d43deca199f89c8d3c0f9209c02c901be46d Mon Sep 17 00:00:00 2001 From: Robert Alonso <17463757+rgalonso@users.noreply.github.com> Date: Sat, 9 Nov 2024 19:56:03 +0000 Subject: [PATCH] refactor: consolidate test classes I initially thought it a good idea to split these up, but it led to a lot of unnnecessary code redundancy. This is a better approach. --- tests/test_process_diff.py | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/tests/test_process_diff.py b/tests/test_process_diff.py index 9dbd7a4..58e1831 100644 --- a/tests/test_process_diff.py +++ b/tests/test_process_diff.py @@ -9,7 +9,7 @@ from TodoParser import TodoParser from main import process_diff -class ProcessDiffTestBase(unittest.TestCase): +class IssueUrlInsertionTest(unittest.TestCase): orig_cwd = None tempdir = None diff_file = None @@ -47,37 +47,24 @@ class ProcessDiffTestBase(unittest.TestCase): expected_count, msg='\nProcessing log\n--------------\n'+output.getvalue()) - def _tearDown(self): - # return to original working directory to ensure we don't mess up other tests - os.chdir(self.orig_cwd) - - # explicitly cleanup to avoid warning being printed about implicit cleanup - self.tempdir.cleanup() - self.tempdir = None - - -class IssueUrlInsertionTest(ProcessDiffTestBase): - def setUp(self): - return super()._setUp('test_new.diff') - # this test can take a while and, as far as TodoParser is concerned, # redundant with the tests of test_todo_parser, so enable the means # to skip it if desired @unittest.skipIf(os.getenv('SKIP_PROCESS_DIFF_TEST', 'false') == 'true', "Skipping because 'SKIP_PROCESS_DIFF_TEST' is 'true'") def test_url_insertion(self): + self._setUp('test_new.diff') self._standardTest(80) - def tearDown(self): - return super()._tearDown() - -class IdenticalTodoTest(ProcessDiffTestBase): - def setUp(self): - return super()._setUp('test_same_title_in_same_file.diff') - @unittest.expectedFailure def test_same_title_in_same_file(self): + self._setUp('test_same_title_in_same_file.diff') self._standardTest(5) def tearDown(self): - return super()._tearDown() + # return to original working directory to ensure we don't mess up other tests + os.chdir(self.orig_cwd) + + # explicitly cleanup to avoid warning being printed about implicit cleanup + self.tempdir.cleanup() + self.tempdir = None