Refactor: Fix flake8 F841 28/68528/2
authorThanh Ha <zxiiro@gmail.com>
Fri, 13 Aug 2021 01:17:36 +0000 (21:17 -0400)
committerThanh Ha <zxiiro@gmail.com>
Fri, 13 Aug 2021 23:22:47 +0000 (19:22 -0400)
Resolves "F841 local variable ____ is assigned to but never used".

Change-Id: I4ab246dd96c96f2fdf33bae1d7d6b2d2c6fe6190
Signed-off-by: Thanh Ha <zxiiro@gmail.com>
lftools/api/endpoints/gerrit.py
lftools/cli/__init__.py
lftools/cli/jenkins/token.py
lftools/cli/ldap_cli.py
lftools/nexus/cmd.py
tests/test_deploy.py
tests/test_release_docker_hub.py

index d33d245..4060e1e 100644 (file)
@@ -110,7 +110,7 @@ class Gerrit(client.RestApi):
         # Setup
         signed_off_by = config.get_setting(fqdn, "sob")
         gerrit_project_dashed = gerrit_project.replace("/", "-")
-        gerrit_project_encoded = urllib.parse.quote(gerrit_project, safe="", encoding=None, errors=None)
+        urllib.parse.quote(gerrit_project, safe="", encoding=None, errors=None)
         filename = "{}.yaml".format(gerrit_project_dashed)
 
         if not reviewid:
index 26cc15a..458950c 100644 (file)
@@ -61,7 +61,7 @@ def cli(ctx, debug, interactive, password, username):
         else:
             try:
                 username = conf.get_setting("global", "username")
-            except (configparser.NoOptionError, configparser.NoSectionError) as e:
+            except (configparser.NoOptionError, configparser.NoSectionError):
                 username = None
 
     if password is None:
@@ -70,7 +70,7 @@ def cli(ctx, debug, interactive, password, username):
         else:
             try:
                 password = conf.get_setting("global", "password")
-            except (configparser.NoOptionError, configparser.NoSectionError) as e:
+            except (configparser.NoOptionError, configparser.NoSectionError):
                 password = None
 
     ctx.obj["username"] = username
index bc66070..3ec386e 100644 (file)
@@ -130,7 +130,7 @@ def reset(ctx, servers):
             with open(jenkins.config_file, "w") as configfile:
                 config.write(configfile)
             return token
-        except requests.exceptions.ConnectionError as e:
+        except requests.exceptions.ConnectionError:
             return None
 
     fail = 0
index 9e82153..1d6d6f4 100644 (file)
@@ -131,7 +131,7 @@ def csv(ctx, ldap_server, ldap_group_base, ldap_user_base, groups):
                     if result_type == ldap.RES_SEARCH_ENTRY:
                         result_set.append(result_data)
             return result_set
-        except ldap.LDAPError as e:
+        except ldap.LDAPError:
             sys.exit(1)
 
     def package_groups(groups):
index 950c710..f2523c9 100644 (file)
@@ -92,7 +92,7 @@ def reorder_staged_repos(settings_file):
 
     try:
         repo_id = _nexus.get_repo_group("Staging Repositories")
-    except LookupError as e:
+    except LookupError:
         log.error("Staging repository 'Staging Repositories' cannot be found")
         sys.exit(1)
 
@@ -155,7 +155,7 @@ def create_repos(config_file, settings_file, url):
         # Create target
         try:
             target_id = _nexus.get_target(name)
-        except LookupError as e:
+        except LookupError:
             target_id = _nexus.create_target(name, targets)
 
         # Create privileges
@@ -171,21 +171,21 @@ def create_repos(config_file, settings_file, url):
             try:
                 privs[priv] = _nexus.get_priv(name, priv)
                 log.info("Creating {} privileges.".format(priv))
-            except LookupError as e:
+            except LookupError:
                 privs[priv] = _nexus.create_priv(name, target_id, priv)
 
         # Create Role
         try:
             role_id = _nexus.get_role(name)
             log.info("Role {} already exists.".format(role_id))
-        except LookupError as e:
+        except LookupError:
             role_id = _nexus.create_role(name, privs)
 
         # Create user
         try:
             _nexus.get_user(name)
             log.info("User {} already exists.".format(name))
-        except LookupError as e:
+        except LookupError:
             _nexus.create_user(name, email, role_id, password, extra_privs)
 
     def build_repo(repo, repoId, config, base_groupId, global_privs, email_domain, strict=True):
index 88d2e6e..1fd1ab5 100644 (file)
@@ -285,7 +285,6 @@ def test_remove_duplicates_and_sort():
 def test_deploy_logs(cli_runner, datafiles, responses):
     """Test deploy_logs() command for expected upload cases."""
     os.chdir(str(datafiles))
-    workspace_dir = os.path.join(str(datafiles), "workspace")
 
     # Test successful upload
     build_url = "https://jenkins.example.org/job/builder-check-poms/204"
@@ -464,44 +463,43 @@ def test__request_post_file(responses, mocker):
     """Test _request_post_file."""
 
     zip_file = "zip-test-files/test.zip"
-    resp = {}
     test_url = "http://connection.error.test"
     exception = requests.exceptions.ConnectionError(test_url)
     responses.add(responses.POST, test_url, body=exception)
     with pytest.raises(requests.HTTPError) as excinfo:
-        resp = deploy_sys._request_post_file(test_url, zip_file)
+        deploy_sys._request_post_file(test_url, zip_file)
     assert "Could not connect to URL" in str(excinfo.value)
 
     test_url = "http://invalid.url.test:8081"
     exception = requests.exceptions.InvalidURL(test_url)
     responses.add(responses.POST, test_url, body=exception)
     with pytest.raises(requests.HTTPError) as excinfo:
-        resp = deploy_sys._request_post_file(test_url, zip_file)
+        deploy_sys._request_post_file(test_url, zip_file)
     assert "Invalid URL" in str(excinfo.value)
 
     test_url = "http://missing.schema.test:8081"
     exception = requests.exceptions.MissingSchema(test_url)
     responses.add(responses.POST, test_url, body=exception)
     with pytest.raises(requests.HTTPError) as excinfo:
-        resp = deploy_sys._request_post_file(test_url, zip_file)
+        deploy_sys._request_post_file(test_url, zip_file)
     assert "Not valid URL" in str(excinfo.value)
 
     test_url = "http://repository.read.only:8081"
     responses.add(responses.POST, test_url, body=None, status=400)
     with pytest.raises(requests.HTTPError) as excinfo:
-        resp = deploy_sys._request_post_file(test_url, zip_file)
+        deploy_sys._request_post_file(test_url, zip_file)
     assert "Repository is read only" in str(excinfo.value)
 
     test_url = "http://repository.not.found:8081"
     responses.add(responses.POST, test_url, body=None, status=404)
     with pytest.raises(requests.HTTPError) as excinfo:
-        resp = deploy_sys._request_post_file(test_url, zip_file)
+        deploy_sys._request_post_file(test_url, zip_file)
     assert "Did not find repository" in str(excinfo.value)
 
     test_url = "http://other.upload.error:8081"
     responses.add(responses.POST, test_url, body=None, status=500)
     with pytest.raises(requests.HTTPError) as excinfo:
-        resp = deploy_sys._request_post_file(test_url, zip_file)
+        deploy_sys._request_post_file(test_url, zip_file)
     assert "Failed to upload to Nexus with status code" in str(excinfo.value)
 
 
@@ -510,44 +508,43 @@ def test__request_post_file_data(responses, mocker):
 
     param = {"r": (None, "testing")}
     zip_file = "zip-test-files/test.zip"
-    resp = {}
     test_url = "http://connection.error.test"
     exception = requests.exceptions.ConnectionError(test_url)
     responses.add(responses.POST, test_url, body=exception)
     with pytest.raises(requests.HTTPError) as excinfo:
-        resp = deploy_sys._request_post_file(test_url, zip_file, param)
+        deploy_sys._request_post_file(test_url, zip_file, param)
     assert "Could not connect to URL" in str(excinfo.value)
 
     test_url = "http://invalid.url.test:8081"
     exception = requests.exceptions.InvalidURL(test_url)
     responses.add(responses.POST, test_url, body=exception)
     with pytest.raises(requests.HTTPError) as excinfo:
-        resp = deploy_sys._request_post_file(test_url, zip_file, param)
+        deploy_sys._request_post_file(test_url, zip_file, param)
     assert "Invalid URL" in str(excinfo.value)
 
     test_url = "http://missing.schema.test:8081"
     exception = requests.exceptions.MissingSchema(test_url)
     responses.add(responses.POST, test_url, body=exception)
     with pytest.raises(requests.HTTPError) as excinfo:
-        resp = deploy_sys._request_post_file(test_url, zip_file, param)
+        deploy_sys._request_post_file(test_url, zip_file, param)
     assert "Not valid URL" in str(excinfo.value)
 
     test_url = "http://repository.read.only:8081"
     responses.add(responses.POST, test_url, body=None, status=400)
     with pytest.raises(requests.HTTPError) as excinfo:
-        resp = deploy_sys._request_post_file(test_url, zip_file, param)
+        deploy_sys._request_post_file(test_url, zip_file, param)
     assert "Repository is read only" in str(excinfo.value)
 
     test_url = "http://repository.not.found:8081"
     responses.add(responses.POST, test_url, body=None, status=404)
     with pytest.raises(requests.HTTPError) as excinfo:
-        resp = deploy_sys._request_post_file(test_url, zip_file, param)
+        deploy_sys._request_post_file(test_url, zip_file, param)
     assert "Did not find repository" in str(excinfo.value)
 
     test_url = "http://other.upload.error:8081"
     responses.add(responses.POST, test_url, body=None, status=500)
     with pytest.raises(requests.HTTPError) as excinfo:
-        resp = deploy_sys._request_post_file(test_url, zip_file, param)
+        deploy_sys._request_post_file(test_url, zip_file, param)
     assert "Failed to upload to Nexus with status code" in str(excinfo.value)
 
 
@@ -729,15 +726,10 @@ def test__upload_maven_file_to_nexus(responses, mocker):
     artifact_id = "ArtId2"
     version = "1.2.7"
     packaging = "tar.xz"
-    classified = None
-
-    resp = {}
 
     test_url = "http://all.ok.upload:8081"
     responses.add(responses.POST, "{}/{}".format(test_url, common_urlpart), body=None, status=201)
-    resp = deploy_sys.upload_maven_file_to_nexus(
-        test_url, nexus_repo_id, group_id, artifact_id, version, packaging, zip_file
-    )
+    deploy_sys.upload_maven_file_to_nexus(test_url, nexus_repo_id, group_id, artifact_id, version, packaging, zip_file)
 
     xml_other_error = """
         <nexus-error><errors><error>
@@ -748,7 +740,7 @@ def test__upload_maven_file_to_nexus(responses, mocker):
     test_url = "http://something.went.wrong:8081"
     responses.add(responses.POST, "{}/{}".format(test_url, common_urlpart), body=xml_other_error, status=405)
     with pytest.raises(requests.HTTPError) as excinfo:
-        resp = deploy_sys.upload_maven_file_to_nexus(
+        deploy_sys.upload_maven_file_to_nexus(
             test_url, nexus_repo_id, group_id, artifact_id, version, packaging, zip_file
         )
     assert "Something went wrong" in str(excinfo.value)
index b7547d0..63dcae3 100644 (file)
@@ -212,7 +212,6 @@ class TestTagsRegExpClass:
     def test_tag_class_manual_version_regexp_str_from_file_valid(self, datafiles):
         org = "onap"
         test_regexp_from_file = os.path.join(str(datafiles), "releasedockerhub_good_regexp")
-        repo_from_file = False
         rdh.initialize(org, test_regexp_from_file)
         assert rdh.validate_regexp() == True
         assert rdh.VERSION_REGEXP == "^\d+.\d+"
@@ -220,7 +219,6 @@ class TestTagsRegExpClass:
     def test_tag_class_manual_version_regexp_str_from_file_invalid(self, datafiles):
         org = "onap"
         test_regexp_from_file = os.path.join(str(datafiles), "releasedockerhub_bad_regexp")
-        repo_from_file = False
         rdh.initialize(org, test_regexp_from_file)
         assert rdh.validate_regexp() == False
         assert rdh.VERSION_REGEXP == "["
@@ -458,25 +456,25 @@ class TestProjectClass:
 
         # Verify that 90 timeout's on any stage failes.
         self.nbr_exc.pull = 90
-        with pytest.raises(requests.HTTPError) as excinfo:
+        with pytest.raises(requests.HTTPError):
             test_proj.docker_pull_tag_push()
 
         self.counter.pull = self.counter.tag = self.counter.push = self.counter.cleanup = 0
         self.nbr_exc.pull = 0
         self.nbr_exc.tag = 90
-        with pytest.raises(requests.HTTPError) as excinfo:
+        with pytest.raises(requests.HTTPError):
             test_proj.docker_pull_tag_push()
 
         self.counter.pull = self.counter.tag = self.counter.push = self.counter.cleanup = 0
         self.nbr_exc.pull = self.nbr_exc.tag = 0
         self.nbr_exc.push = 90
-        with pytest.raises(requests.HTTPError) as excinfo:
+        with pytest.raises(requests.HTTPError):
             test_proj.docker_pull_tag_push()
 
         self.counter.pull = self.counter.tag = self.counter.push = self.counter.cleanup = 0
         self.nbr_exc.pull = self.nbr_exc.tag = self.nbr_exc.push = 0
         self.nbr_exc.cleanup = 90
-        with pytest.raises(requests.HTTPError) as excinfo:
+        with pytest.raises(requests.HTTPError):
             test_proj.docker_pull_tag_push()
 
         # Verify 89 timeouts and the 90 is ok per stage