From 4570981c1bc0ecffe541151b4f2be4bcb52c6686 Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Thu, 24 Sep 2020 03:52:21 +0000 Subject: [PATCH] Don't test candidate files if they're removed The routine to determine which files to check for candidacies, when used to analyze files being changed with --HEAD, should only test those files if they are being kept by the change. If they're being deleted, then there is no reason to test them. Further, testing files which are slated for removal makes it basically impossible to revert a previously merged candidacy which has since been invalidated (for example, by resigning OSF Individual Membership). Mock os.path.exists in test_find_modified_candidate_files_all_good to just return True, since we aren't actually creating the file in that test. Change-Id: I4d5d9b1d55379adfd1c7d7765324306abf40cdb7 --- openstack_election/cmds/ci_check_all_candidate_files.py | 3 ++- openstack_election/tests/cmds/test_ci_checks.py | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/openstack_election/cmds/ci_check_all_candidate_files.py b/openstack_election/cmds/ci_check_all_candidate_files.py index 18159795..deab27b8 100755 --- a/openstack_election/cmds/ci_check_all_candidate_files.py +++ b/openstack_election/cmds/ci_check_all_candidate_files.py @@ -76,7 +76,7 @@ def check_for_changes(projects, filepath, limit, verbose=0): def find_modified_candidate_files(): - "Return a list of files modified by the most recent commit." + "Return a list of non-removed files modified by the most recent commit." results = subprocess.check_output( ['git', 'diff', '--name-only', '--pretty=format:', 'HEAD^'] ).decode('utf-8') @@ -84,6 +84,7 @@ def find_modified_candidate_files(): li.strip() for li in results.splitlines() if (li.startswith(utils.CANDIDATE_PATH + '/') and + os.path.exists(li) and not li.endswith('.placeholder')) ] return filenames diff --git a/openstack_election/tests/cmds/test_ci_checks.py b/openstack_election/tests/cmds/test_ci_checks.py index ade0d22c..a46e196b 100644 --- a/openstack_election/tests/cmds/test_ci_checks.py +++ b/openstack_election/tests/cmds/test_ci_checks.py @@ -37,8 +37,10 @@ class TestFindModifiedCandidateFiles(base.ElectionTestCase): ci_check_all_candidate_files.find_modified_candidate_files() self.assertEqual(expected_filenames, filenames) + @mock.patch('os.path.exists', return_value=True) @mock.patch('subprocess.check_output') - def test_find_modified_candidate_files_all_good(self, mock_check_output): + def test_find_modified_candidate_files_all_good( + self, mock_check_output, mock_path_exists): check_output = (('configuration.yaml\n' 'openstack_election/__init__py\n' '%(path)s/candidate\n'