From c9ee3fe69ba2dd1e72f4bb7ab201afb3dedd1fbe Mon Sep 17 00:00:00 2001 From: Thanh Ha Date: Fri, 30 Jul 2021 23:53:40 -0400 Subject: [PATCH] Refactor: Fix E713 form should be "not in" Tests for membership should use the form x not in the_list rather than not x in the_list. The former example is simply more readable. Ref: https://www.flake8rules.com/rules/E713.html Signed-off-by: Thanh Ha Change-Id: I3ab1811c2a6b7e6135397e694b4ec4a1ab980c93 --- lftools/license.py | 2 +- lftools/nexus/cmd.py | 8 ++++---- lftools/nexus/release_docker_hub.py | 2 +- lftools/shell/dco.py | 2 +- tests/test_release_docker_hub.py | 12 ++++++------ 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lftools/license.py b/lftools/license.py index 5b6e1cae..1366d317 100644 --- a/lftools/license.py +++ b/lftools/license.py @@ -56,7 +56,7 @@ def check_license(license_file, code_file): license_header = get_header_text(license_file) code_header = get_header_text(code_file) - if not license_header in code_header: + if license_header not in code_header: log.error("{} is missing or has incorrect license header.".format(code_file)) return 1 diff --git a/lftools/nexus/cmd.py b/lftools/nexus/cmd.py index a3264e4d..950c7107 100644 --- a/lftools/nexus/cmd.py +++ b/lftools/nexus/cmd.py @@ -84,7 +84,7 @@ def reorder_staged_repos(settings_file): settings = yaml.safe_load(f) for setting in ["nexus", "user", "password"]: - if not setting in settings: + if setting not in settings: log.error("{} needs to be defined".format(setting)) sys.exit(1) @@ -136,13 +136,13 @@ def create_repos(config_file, settings_file, url): settings = yaml.safe_load(f) for setting in ["email_domain", "base_groupId", "repositories"]: - if not setting in config: + if setting not in config: log.error("{} needs to be defined in {}".format(setting, config_file)) sys.exit(1) if settings_file: for setting in ["nexus", "user", "password"]: - if not setting in settings: + if setting not in settings: log.error("{} needs to be defined in {}".format(setting, settings_file)) sys.exit(1) @@ -193,7 +193,7 @@ def create_repos(config_file, settings_file, url): groupId = "{}.{}".format(base_groupId, repo) target = util.create_repo_target_regex(groupId, strict) - if not global_privs and not "extra_privs" in config: + if not global_privs and "extra_privs" not in config: extra_privs = [] elif global_privs: extra_privs = global_privs diff --git a/lftools/nexus/release_docker_hub.py b/lftools/nexus/release_docker_hub.py index 00dfb0bb..6515d3e6 100644 --- a/lftools/nexus/release_docker_hub.py +++ b/lftools/nexus/release_docker_hub.py @@ -400,7 +400,7 @@ class ProjectClass: if len(self.nexus_tags.valid) > 0: for nexustag in self.nexus_tags.valid: - if not nexustag in self.docker_tags.valid: + if nexustag not in self.docker_tags.valid: log.debug("Need to copy tag {} from {}".format(nexustag, self.nexus_repo_name)) self.tags_2_copy.add_tag(nexustag) diff --git a/lftools/shell/dco.py b/lftools/shell/dco.py index ca026220..33ee5859 100644 --- a/lftools/shell/dco.py +++ b/lftools/shell/dco.py @@ -119,7 +119,7 @@ def match(path=getcwd(), signoffs_dir="dco_signoffs"): sob_email_regex = r"(?=Signed\-off\-by: ).*[\<](.*)[\>]" sob_results = re.findall(sob_email_regex, commit_log_message) - if not commit_author_email in sob_results and os.path.isdir(signoffs_dir): + if commit_author_email not in sob_results and os.path.isdir(signoffs_dir): dco_file = subprocess.run( ["grep", "-Rli", commit_author_email, signoffs_dir], capture_output=True ).stdout diff --git a/tests/test_release_docker_hub.py b/tests/test_release_docker_hub.py index a7d68321..a616d3dd 100644 --- a/tests/test_release_docker_hub.py +++ b/tests/test_release_docker_hub.py @@ -270,7 +270,7 @@ class TestProjectClass: def mocked_docker_pull(self, nexus_image_str, count, tag, retry_text="", progbar=False): """Mocking Pull an image from Nexus.""" - if not nexus_image_str in self._expected_nexus_image_str: + if nexus_image_str not in self._expected_nexus_image_str: raise ValueError("Wrong nexus project in pull") image = self.mock_image(self._test_image_long_id, self._test_image_short_id) self.counter.pull = self.counter.pull + 1 @@ -283,7 +283,7 @@ class TestProjectClass: """Mocking Tag the image with proper docker name and version.""" if not image.id == self._test_image_long_id: raise ValueError("Wrong image id in remove") - if not tag in ["1.4.0", "1.4.1"]: + if tag not in ["1.4.0", "1.4.1"]: raise ValueError("Wrong tag in docker_tag") self.counter.tag = self.counter.tag + 1 if self.counter.tag <= self.nbr_exc.tag: @@ -293,7 +293,7 @@ class TestProjectClass: """Mocking Tag the image with proper docker name and version.""" if not image.id == self._test_image_long_id: raise ValueError("Wrong image id in remove") - if not tag in ["1.4.0", "1.4.1"]: + if tag not in ["1.4.0", "1.4.1"]: raise ValueError("Wrong tag in push") self.counter.push = self.counter.push + 1 if self.counter.push <= self.nbr_exc.push: @@ -589,7 +589,7 @@ class TestFetchAllTagsAndUpdate: def mocked_docker_pull(self, nexus_image_str, count, tag, retry_text="", progbar=False): """Mocking Pull an image from Nexus.""" - if not nexus_image_str in self._expected_nexus_image_str: + if nexus_image_str not in self._expected_nexus_image_str: print("IMAGESTR {}".format(nexus_image_str)) raise ValueError("Wrong nexus project in pull") image = self.mock_image(self._test_image_long_id, self._test_image_short_id) @@ -603,7 +603,7 @@ class TestFetchAllTagsAndUpdate: """Mocking Tag the image with proper docker name and version.""" if not image.id == self._test_image_long_id: raise ValueError("Wrong image id in remove") - if not tag in ["1.4.0", "1.3.1", "1.3.2"]: + if tag not in ["1.4.0", "1.3.1", "1.3.2"]: raise ValueError("Wrong tag in docker_tag") self.counter.tag = self.counter.tag + 1 if self.counter.tag <= self.nbr_exc.tag: @@ -613,7 +613,7 @@ class TestFetchAllTagsAndUpdate: """Mocking Tag the image with proper docker name and version.""" if not image.id == self._test_image_long_id: raise ValueError("Wrong image id in remove") - if not tag in ["1.4.0", "1.3.1", "1.3.2"]: + if tag not in ["1.4.0", "1.3.1", "1.3.2"]: raise ValueError("Wrong tag in push") self.counter.push = self.counter.push + 1 if self.counter.push <= self.nbr_exc.push: -- 2.16.6