Refactor: Fix E713 form should be "not in" 89/68389/1
authorThanh Ha <zxiiro@gmail.com>
Sat, 31 Jul 2021 03:53:40 +0000 (23:53 -0400)
committerThanh Ha <zxiiro@gmail.com>
Sat, 31 Jul 2021 03:54:45 +0000 (23:54 -0400)
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 <zxiiro@gmail.com>
Change-Id: I3ab1811c2a6b7e6135397e694b4ec4a1ab980c93

lftools/license.py
lftools/nexus/cmd.py
lftools/nexus/release_docker_hub.py
lftools/shell/dco.py
tests/test_release_docker_hub.py

index 5b6e1ca..1366d31 100644 (file)
@@ -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
 
index a3264e4..950c710 100644 (file)
@@ -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
index 00dfb0b..6515d3e 100644 (file)
@@ -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)
 
index ca02622..33ee585 100644 (file)
@@ -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
index a7d6832..a616d3d 100644 (file)
@@ -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: