Skip to content

Commit

Permalink
Address ruff PLR5501 exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
shatakshiiii committed May 22, 2024
1 parent 031938a commit de03aae
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 64 deletions.
15 changes: 7 additions & 8 deletions docs/_ext/regenerate_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,14 @@ def _params_row_for_entry(entry: SettingsEntry) -> tuple[str, ...]:
"""
if entry.cli_parameters is None:
cli_parameters = "positional"
else:
if entry.cli_parameters.short:
if entry.cli_parameters.long_override:
long = entry.cli_parameters.long_override
else:
long = f"--{entry.name_dashed}"
cli_parameters = f"``{entry.cli_parameters.short}`` or ``{long}``"
elif entry.cli_parameters.short:
if entry.cli_parameters.long_override:
long = entry.cli_parameters.long_override
else:
cli_parameters = "positional"
long = f"--{entry.name_dashed}"
cli_parameters = f"``{entry.cli_parameters.short}`` or ``{long}``"
else:
cli_parameters = "positional"

path = entry.settings_file_path("ansible-navigator")
indent = 4
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ ignore = [
'PLR0913', # Too many arguments to function call (7 > 5)
'PLR0915', # Too many statements (58 > 50)
'PLR2004', # Magic value used in comparison, consider replacing 2 with a constant variable
'PLR5501', # Consider using `elif` instead of `else` then `if` to remove one indentation level
'PLW0603', # Using the global statement to update `DIAGNOSTIC_FAILURES` is discouraged
'PT005', # Fixture `_settings_samples` returns a value, remove leading underscore
'PT019', # Fixture `_mocked_func` without value is injected as parameter, use `@pytest.mark.usefixtures` instead
Expand Down
19 changes: 9 additions & 10 deletions src/ansible_navigator/actions/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,17 @@ def _generate_command(
else:
pass_through_args = []

elif exec_command_is_default and isinstance(extra_args, list):
command, pass_through_args = extra_args[0], extra_args[1:]

Check warning on line 55 in src/ansible_navigator/actions/exec.py

View check run for this annotation

Codecov / codecov/patch

src/ansible_navigator/actions/exec.py#L55

Added line #L55 was not covered by tests
else:
if exec_command_is_default and isinstance(extra_args, list):
command, pass_through_args = extra_args[0], extra_args[1:]
parts = shlex.split(exec_command)
command = parts[0]
if len(parts) == 1 and isinstance(extra_args, list):
# Use the extra arguments
pass_through_args = extra_args

Check warning on line 61 in src/ansible_navigator/actions/exec.py

View check run for this annotation

Codecov / codecov/patch

src/ansible_navigator/actions/exec.py#L61

Added line #L61 was not covered by tests
else:
parts = shlex.split(exec_command)
command = parts[0]
if len(parts) == 1 and isinstance(extra_args, list):
# Use the extra arguments
pass_through_args = extra_args
else:
# Use the leftovers or an empty list
pass_through_args = parts[1:]
# Use the leftovers or an empty list
pass_through_args = parts[1:]
logger.debug("runner command: %s", command)
logger.debug("runner passthrough: %s", pass_through_args)
return (command, pass_through_args)
Expand Down
11 changes: 5 additions & 6 deletions src/ansible_navigator/actions/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,13 +860,12 @@ def _get_status(self) -> tuple[str, int]:
status_color = 9
else:
status_color = self._msg_from_plays[1] or 10
elif self._msg_from_plays[0] is not None and self._msg_from_plays[1] is not None:
status = self._msg_from_plays[0]
status_color = self._msg_from_plays[1]

Check warning on line 865 in src/ansible_navigator/actions/run.py

View check run for this annotation

Codecov / codecov/patch

src/ansible_navigator/actions/run.py#L863-L865

Added lines #L863 - L865 were not covered by tests
else:
if self._msg_from_plays[0] is not None and self._msg_from_plays[1] is not None:
status = self._msg_from_plays[0]
status_color = self._msg_from_plays[1]
else:
status = self.runner.status
status_color = 10
status = self.runner.status
status_color = 10

Check warning on line 868 in src/ansible_navigator/actions/run.py

View check run for this annotation

Codecov / codecov/patch

src/ansible_navigator/actions/run.py#L867-L868

Added lines #L867 - L868 were not covered by tests
return status, status_color

def _set_status(self) -> None:
Expand Down
11 changes: 5 additions & 6 deletions src/ansible_navigator/actions/write_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,12 @@ def run(self, interaction: Interaction, app: AppPublic) -> None:

if isinstance(obj, str):
write_as = ".txt"
elif re.match(r"^.*\.y(?:a)?ml$", filename):
write_as = ".yaml"
elif filename.endswith(".json"):
write_as = ".json"

Check warning on line 80 in src/ansible_navigator/actions/write_file.py

View check run for this annotation

Codecov / codecov/patch

src/ansible_navigator/actions/write_file.py#L77-L80

Added lines #L77 - L80 were not covered by tests
else:
if re.match(r"^.*\.y(?:a)?ml$", filename):
write_as = ".yaml"
elif filename.endswith(".json"):
write_as = ".json"
else:
write_as = interaction.ui.content_format().value.file_extension
write_as = interaction.ui.content_format().value.file_extension

Check warning on line 82 in src/ansible_navigator/actions/write_file.py

View check run for this annotation

Codecov / codecov/patch

src/ansible_navigator/actions/write_file.py#L82

Added line #L82 was not covered by tests

if write_as == ".txt":
file = Path(os.path.abspath(filename))
Expand Down
11 changes: 5 additions & 6 deletions src/ansible_navigator/ui_framework/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,13 @@ def present(self) -> Form:
if form_field.pressed:
break
idx += 1
elif char == curses_ascii.TAB:
form_field.conditional_validation(response)
idx += 1

Check warning on line 424 in src/ansible_navigator/ui_framework/form.py

View check run for this annotation

Codecov / codecov/patch

src/ansible_navigator/ui_framework/form.py#L422-L424

Added lines #L422 - L424 were not covered by tests
else:
if char == curses_ascii.TAB:
form_field.conditional_validation(response)
form_field.validate(response)
if form_field.valid is True:

Check warning on line 427 in src/ansible_navigator/ui_framework/form.py

View check run for this annotation

Codecov / codecov/patch

src/ansible_navigator/ui_framework/form.py#L426-L427

Added lines #L426 - L427 were not covered by tests
idx += 1
else:
form_field.validate(response)
if form_field.valid is True:
idx += 1

return self._form

Expand Down
15 changes: 7 additions & 8 deletions src/ansible_navigator/utils/dot_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,14 @@ def place_at_path(
else:
msg = "No behavior specified for LIST_LIST"
raise ValueError(msg)
elif MergeBehaviors.LIST_APPEND in behaviors:
nested[part].append(value)
elif MergeBehaviors.LIST_REPLACE in behaviors:
nested[part] = value
continue
else:
if MergeBehaviors.LIST_APPEND in behaviors:
nested[part].append(value)
elif MergeBehaviors.LIST_REPLACE in behaviors:
nested[part] = value
continue
else:
msg = "No behavior specified for LIST_*"
raise ValueError(msg)
msg = "No behavior specified for LIST_*"
raise ValueError(msg)

if MergeBehaviors.LIST_UNIQUE in behaviors:
nested[part] = list(dict.fromkeys(nested[part]))
Expand Down
36 changes: 17 additions & 19 deletions tests/unit/configuration_subsystem/test_precedence.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,15 @@ def test_all_entries_reflect_cli_given_settings(
if entry.name in expected_dict:
assert entry.value.current == expected_dict[entry.name], entry.name
assert entry.value.source is C.USER_CLI, entry.name
else:
if settings_file_type == "empty":
if entry.value.default is C.NOT_SET:
assert entry.value.source is C.NOT_SET, entry.name
elif entry.value.default == "auto":
assert entry.value.source is C.AUTO, entry.name
else:
assert entry.value.source is C.DEFAULT_CFG, entry.name
elif settings_file_type == "full":
assert entry.value.source is C.USER_CFG, entry.name
elif settings_file_type == "empty":
if entry.value.default is C.NOT_SET:
assert entry.value.source is C.NOT_SET, entry.name
elif entry.value.default == "auto":
assert entry.value.source is C.AUTO, entry.name
else:
assert entry.value.source is C.DEFAULT_CFG, entry.name
elif settings_file_type == "full":
assert entry.value.source is C.USER_CFG, entry.name


@pytest.mark.usefixtures("_ansible_version")
Expand Down Expand Up @@ -244,16 +243,15 @@ def test_all_entries_reflect_default(
configured_entry = response.application_configuration.entry(entry.name)
if configured_entry.value.default is C.NOT_SET:
assert configured_entry.value.source is C.NOT_SET, configured_entry
elif configured_entry.name == "playbook_save_as":
assert configured_entry.value.source is C.DEFAULT_CFG, configured_entry
assert configured_entry.value.current.endswith(entry.value.default), configured_entry
elif configured_entry.name == "container_engine":
assert configured_entry.value.source is C.AUTO, configured_entry
assert configured_entry.value.current == "podman"
else:
if configured_entry.name == "playbook_save_as":
assert configured_entry.value.source is C.DEFAULT_CFG, configured_entry
assert configured_entry.value.current.endswith(entry.value.default), configured_entry
elif configured_entry.name == "container_engine":
assert configured_entry.value.source is C.AUTO, configured_entry
assert configured_entry.value.current == "podman"
else:
assert configured_entry.value.source is C.DEFAULT_CFG, configured_entry
assert configured_entry.value.current == entry.value.default, configured_entry
assert configured_entry.value.source is C.DEFAULT_CFG, configured_entry
assert configured_entry.value.current == entry.value.default, configured_entry


@pytest.mark.usefixtures("_ansible_version")
Expand Down

0 comments on commit de03aae

Please sign in to comment.