From 1d90d6580c093d430d7909cf8c6cc1facb86acdb Mon Sep 17 00:00:00 2001 From: Allen Robel Date: Sat, 20 Apr 2024 15:20:53 -1000 Subject: [PATCH] Fix pylint issues Fixed below pylint issues. ERROR: Found 9 pylint issue(s) which need to be resolved: ERROR: plugins/module_utils/fabric/fabric_summary.py:176:19: f-string-without-interpolation: Using an f-string that does not have any interpolated variables ERROR: plugins/module_utils/fabric/fabric_summary.py:187:19: f-string-without-interpolation: Using an f-string that does not have any interpolated variables ERROR: plugins/module_utils/fabric/verify_playbook_params.py:810:16: disallowed-name: Disallowed name "_" ERROR: tests/unit/modules/dcnm/dcnm_fabric/test_fabric_summary.py:601:8: disallowed-name: Disallowed name "_" ERROR: tests/unit/modules/dcnm/dcnm_fabric/test_fabric_summary.py:634:8: disallowed-name: Disallowed name "_" ERROR: tests/unit/modules/dcnm/dcnm_fabric/test_fabric_summary.py:667:8: disallowed-name: Disallowed name "_" ERROR: tests/unit/modules/dcnm/dcnm_fabric/test_fabric_summary.py:700:8: disallowed-name: Disallowed name "_" ERROR: tests/unit/modules/dcnm/dcnm_fabric/test_fabric_summary.py:795:8: disallowed-name: Disallowed name "_" ERROR: tests/unit/modules/dcnm/dcnm_fabric/test_fabric_summary.py:828:8: disallowed-name: Disallowed name "_" --- plugins/module_utils/fabric/endpoints.py | 4 ++-- plugins/module_utils/fabric/fabric_summary.py | 7 +++---- .../fabric/verify_playbook_params.py | 2 +- .../modules/dcnm/dcnm_fabric/test_endpoints.py | 6 +++--- .../dcnm/dcnm_fabric/test_fabric_delete.py | 4 ++-- .../dcnm/dcnm_fabric/test_fabric_summary.py | 18 +++++++++--------- 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/plugins/module_utils/fabric/endpoints.py b/plugins/module_utils/fabric/endpoints.py index accea12f2..70f4e4ff5 100644 --- a/plugins/module_utils/fabric/endpoints.py +++ b/plugins/module_utils/fabric/endpoints.py @@ -71,7 +71,7 @@ def _init_properties(self): self.properties["fabric_name"] = None self.properties["template_name"] = None - def _validate_fabric_name(self, value): + def validate_fabric_name(self, value): """ - Validate the fabric name meets the requirements of the controller. - Raise ``TypeError`` if value is not a string. @@ -267,7 +267,7 @@ def fabric_name(self): @fabric_name.setter def fabric_name(self, value): - self._validate_fabric_name(value) + self.validate_fabric_name(value) self.properties["fabric_name"] = value @property diff --git a/plugins/module_utils/fabric/fabric_summary.py b/plugins/module_utils/fabric/fabric_summary.py index ae693f04e..a4284730b 100644 --- a/plugins/module_utils/fabric/fabric_summary.py +++ b/plugins/module_utils/fabric/fabric_summary.py @@ -173,7 +173,7 @@ def _verify_controller_response(self): controller_message = self.rest_send.response_current.get("MESSAGE", None) if controller_return_code != 200: msg = f"{self.class_name}.{method_name}: " - msg += f"Failed to retrieve fabric_summary for fabric_name " + msg += "Failed to retrieve fabric_summary for fabric_name " msg += f"{self.fabric_name}. " msg += f"RETURN_CODE: {controller_return_code}. " msg += f"MESSAGE: {controller_message}." @@ -184,7 +184,7 @@ def _verify_controller_response(self): # does not contain a DATA key. if len(self.data) == 0: msg = f"{self.class_name}.{method_name}: " - msg += f"Controller responded with missing or empty DATA." + msg += "Controller responded with missing or empty DATA." raise ControllerResponseError(msg) def refresh(self): @@ -250,7 +250,6 @@ def verify_refresh_has_been_called(self, attempted_method_name): """ - raise ``ValueError`` if ``refresh()`` has not been called. """ - method_name = inspect.stack()[0][3] if self.refreshed is True: return msg = f"{self.class_name}.refresh() must be called before accessing " @@ -325,7 +324,7 @@ def fabric_name(self) -> str: @fabric_name.setter def fabric_name(self, value: str): try: - self.endpoints._validate_fabric_name(value) + self.endpoints.validate_fabric_name(value) except ValueError as error: raise ValueError(error) from error self._properties["fabric_name"] = value diff --git a/plugins/module_utils/fabric/verify_playbook_params.py b/plugins/module_utils/fabric/verify_playbook_params.py index 2f352914c..6ecedcac2 100644 --- a/plugins/module_utils/fabric/verify_playbook_params.py +++ b/plugins/module_utils/fabric/verify_playbook_params.py @@ -807,7 +807,7 @@ def generate_error_message(self): # bad_params[fabric][param] = for fabric_name, fabric_dict in self.bad_params.items(): msg += f"Fabric: {fabric_name}, " - for _, bad_param_list in fabric_dict.items(): + for bad_param_list in fabric_dict.values(): for bad_param in bad_param_list: boolean_operator = bad_param.get("boolean_operator") config_param = bad_param.get("config_param") diff --git a/tests/unit/modules/dcnm/dcnm_fabric/test_endpoints.py b/tests/unit/modules/dcnm/dcnm_fabric/test_endpoints.py index 28d3aa5a0..e2316e6ef 100644 --- a/tests/unit/modules/dcnm/dcnm_fabric/test_endpoints.py +++ b/tests/unit/modules/dcnm/dcnm_fabric/test_endpoints.py @@ -75,11 +75,11 @@ def test_endpoints_00010() -> None: assert instance.properties["template_name"] is None -MATCH_00020a = r"ApiEndpoints\._validate_fabric_name: " +MATCH_00020a = r"ApiEndpoints\.validate_fabric_name: " MATCH_00020a = r"Invalid fabric name\. " MATCH_00020a += r"Expected string\. Got.*\." -MATCH_00020b = r"ApiEndpoints\._validate_fabric_name: " +MATCH_00020b = r"ApiEndpoints\.validate_fabric_name: " MATCH_00020b = r"Invalid fabric name:.*\. " MATCH_00020b += "Fabric name must start with a letter A-Z or a-z and " MATCH_00020b += r"contain only the characters in: \[A-Z,a-z,0-9,-,_\]\." @@ -109,7 +109,7 @@ def test_endpoints_00020(fabric_name, expected, does_raise) -> None: - ApiEndpoints - __init__() - fabric_name.setter - - _validate_fabric_name() + - validate_fabric_name() Summary - Verify ``TypeError`` is raised for non-string fabric_name. diff --git a/tests/unit/modules/dcnm/dcnm_fabric/test_fabric_delete.py b/tests/unit/modules/dcnm/dcnm_fabric/test_fabric_delete.py index 7fb51b359..8473cedfe 100644 --- a/tests/unit/modules/dcnm/dcnm_fabric/test_fabric_delete.py +++ b/tests/unit/modules/dcnm/dcnm_fabric/test_fabric_delete.py @@ -140,7 +140,7 @@ def test_fabric_delete_00022(fabric_delete, fabric_name) -> None: - Verify ApiEndpoints raises ``TypeError`` because ``fabric_name`` argument passed to _set_fabric_delete_endpoint() is not a string. """ - match = r"ApiEndpoints\._validate_fabric_name: " + match = r"ApiEndpoints\.validate_fabric_name: " match += "Invalid fabric name. Expected string. Got" with does_not_raise(): @@ -166,7 +166,7 @@ def test_fabric_delete_00023(fabric_delete, fabric_name) -> None: argument passed to _set_fabric_delete_endpoint() is an invalid string. """ - match = r"ApiEndpoints\._validate_fabric_name: " + match = r"ApiEndpoints\.validate_fabric_name: " match += rf"Invalid fabric name: {fabric_name}\. " match += "Fabric name must start with a letter A-Z " match += "or a-z and contain only the characters in: " diff --git a/tests/unit/modules/dcnm/dcnm_fabric/test_fabric_summary.py b/tests/unit/modules/dcnm/dcnm_fabric/test_fabric_summary.py index 0c98d586c..d461b5e4f 100644 --- a/tests/unit/modules/dcnm/dcnm_fabric/test_fabric_summary.py +++ b/tests/unit/modules/dcnm/dcnm_fabric/test_fabric_summary.py @@ -167,7 +167,7 @@ class MockApiEndpoints: # pylint: disable=too-few-public-methods Mock the ApiEndpoints.fabric_summary getter property to raise ``ValueError``. """ - def _validate_fabric_name(self, value="MyFabric"): + def validate_fabric_name(self, value="MyFabric"): """ Mocked method required for test, but not relevant to test result. """ @@ -598,7 +598,7 @@ def test_fabric_summary_00040(fabric_summary) -> None: match = r"FabricSummary\.refresh\(\) must be called before " match += r"accessing FabricSummary\.all_data\." with pytest.raises(ValueError, match=match): - _ = instance.all_data + instance.all_data # pylint: disable=pointless-statement def test_fabric_summary_00050(fabric_summary) -> None: @@ -631,7 +631,7 @@ def test_fabric_summary_00050(fabric_summary) -> None: match = r"FabricSummary\.refresh\(\) must be called before " match += r"accessing FabricSummary\.border_gateway_count\." with pytest.raises(ValueError, match=match): - _ = instance.border_gateway_count + instance.border_gateway_count # pylint: disable=pointless-statement def test_fabric_summary_00060(fabric_summary) -> None: @@ -664,7 +664,7 @@ def test_fabric_summary_00060(fabric_summary) -> None: match = r"FabricSummary\.refresh\(\) must be called before " match += r"accessing FabricSummary\.device_count\." with pytest.raises(ValueError, match=match): - _ = instance.device_count + instance.device_count # pylint: disable=pointless-statement def test_fabric_summary_00070(fabric_summary) -> None: @@ -697,14 +697,14 @@ def test_fabric_summary_00070(fabric_summary) -> None: match = r"FabricSummary\.refresh\(\) must be called before " match += r"accessing FabricSummary\.fabric_is_empty\." with pytest.raises(ValueError, match=match): - _ = instance.fabric_is_empty + instance.fabric_is_empty # pylint: disable=pointless-statement -MATCH_00080a = r"ApiEndpoints\._validate_fabric_name: " +MATCH_00080a = r"ApiEndpoints\.validate_fabric_name: " MATCH_00080a = r"Invalid fabric name\. " MATCH_00080a += r"Expected string\. Got.*\." -MATCH_00080b = r"ApiEndpoints\._validate_fabric_name: " +MATCH_00080b = r"ApiEndpoints\.validate_fabric_name: " MATCH_00080b = r"Invalid fabric name:.*\. " MATCH_00080b += "Fabric name must start with a letter A-Z or a-z and " MATCH_00080b += r"contain only the characters in: \[A-Z,a-z,0-9,-,_\]\." @@ -792,7 +792,7 @@ def test_fabric_summary_00090(fabric_summary) -> None: match = r"FabricSummary\.refresh\(\) must be called before " match += r"accessing FabricSummary\.leaf_count\." with pytest.raises(ValueError, match=match): - _ = instance.leaf_count + instance.leaf_count # pylint: disable=pointless-statement def test_fabric_summary_00100(fabric_summary) -> None: @@ -825,4 +825,4 @@ def test_fabric_summary_00100(fabric_summary) -> None: match = r"FabricSummary\.refresh\(\) must be called before " match += r"accessing FabricSummary\.spine_count\." with pytest.raises(ValueError, match=match): - _ = instance.spine_count + instance.spine_count # pylint: disable=pointless-statement