Skip to content

Commit

Permalink
Fix pylint issues
Browse files Browse the repository at this point in the history
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 "_"
  • Loading branch information
allenrobel committed Apr 21, 2024
1 parent f99122c commit 1d90d65
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 21 deletions.
4 changes: 2 additions & 2 deletions plugins/module_utils/fabric/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions plugins/module_utils/fabric/fabric_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}."
Expand All @@ -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):
Expand Down Expand Up @@ -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 "
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion plugins/module_utils/fabric/verify_playbook_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ def generate_error_message(self):
# bad_params[fabric][param] = <list of bad param dict>
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")
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/modules/dcnm/dcnm_fabric/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,-,_\]\."
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/modules/dcnm/dcnm_fabric/test_fabric_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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: "
Expand Down
18 changes: 9 additions & 9 deletions tests/unit/modules/dcnm/dcnm_fabric/test_fabric_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,-,_\]\."
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

0 comments on commit 1d90d65

Please sign in to comment.