From 69e2360329a6628319876691424f18c4d89a840d Mon Sep 17 00:00:00 2001 From: Robert Alonso <17463757+rgalonso@users.noreply.github.com> Date: Mon, 11 Nov 2024 20:45:26 +0000 Subject: [PATCH] test: allow multiple diff files to be consumed This sets up the ability to have one diff file create a simulated filesystem and a second to simulate an edit of an existing file --- tests/test_process_diff.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/test_process_diff.py b/tests/test_process_diff.py index 576e8c1..fe32b61 100644 --- a/tests/test_process_diff.py +++ b/tests/test_process_diff.py @@ -16,21 +16,22 @@ class IssueUrlInsertionTest(unittest.TestCase): diff_file = None parser = None - def _setUp(self, diff_file): + def _setUp(self, diff_files): # get current working directory self.orig_cwd = os.getcwd() # Create temporary directory to hold simulated filesystem. self.tempdir = tempfile.TemporaryDirectory() - # run patch against the diff file to generate the simulated filesystem - subprocess.run(['patch', '-d', self.tempdir.name, - '-i', f'{os.getcwd()}/tests/{diff_file}'], - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, - check=True) + for diff_file in diff_files: + # run patch against the diff file to generate/update the simulated filesystem + subprocess.run(['patch', '-d', self.tempdir.name, + '-i', f'{os.getcwd()}/tests/{diff_file}'], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + check=True) - self.diff_file = open(f'tests/{diff_file}', 'r') + self.diff_file = open(f'tests/{diff_files[-1]}', 'r') self.parser = TodoParser() with open('syntax.json', 'r') as syntax_json: self.parser.syntax_dict = json.load(syntax_json) @@ -54,7 +55,7 @@ class IssueUrlInsertionTest(unittest.TestCase): @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._setUp(['test_new.diff']) self._standardTest(80) # There is a known bug related to this issue, so until it's resolved @@ -62,7 +63,7 @@ class IssueUrlInsertionTest(unittest.TestCase): # See #225 and #224 @unittest.expectedFailure def test_same_title_in_same_file(self): - self._setUp('test_same_title_in_same_file.diff') + self._setUp(['test_same_title_in_same_file.diff']) self._standardTest(5) # There is a known bug related to this issue, so until it's resolved @@ -70,7 +71,7 @@ class IssueUrlInsertionTest(unittest.TestCase): # See #229 @unittest.expectedFailure def test_comment_suffix_after_source_line(self): - self._setUp('test_comment_suffix_after_source_line.diff') + self._setUp(['test_comment_suffix_after_source_line.diff']) self._standardTest(1) # get details about the issue and source file issue = self.raw_issues[0]