From a34b7936f68568996e6d3803d94fdcfd4e068d71 Mon Sep 17 00:00:00 2001 From: shatakshiiii Date: Thu, 30 May 2024 20:28:45 +0530 Subject: [PATCH 1/4] Address ruff PIE810 --- pyproject.toml | 1 - src/ansible_navigator/actions/run.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7f39f310b..46a9af86f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -291,7 +291,6 @@ ignore = [ 'N817', # CamelCase `Constants` imported as acronym `C` 'PERF203', # `try`-`except` within a loop incurs performance overhead 'PGH003', # Use specific rule codes when ignoring type issues - 'PIE810', # [*] Call `startswith` once with a `tuple` 'PD011', # https://github.com/astral-sh/ruff/issues/2229 'PLR0911', # Too many return statements (8 > 6) 'PLR0912', # Too many branches (13 > 12) diff --git a/src/ansible_navigator/actions/run.py b/src/ansible_navigator/actions/run.py index a0abd2901..f6345a9a6 100644 --- a/src/ansible_navigator/actions/run.py +++ b/src/ansible_navigator/actions/run.py @@ -431,7 +431,7 @@ def _init_replay(self) -> bool: return False version = data.get("version", "") - if version.startswith("1.") or version.startswith("2."): + if version.startswith(("1.", "2.")): try: stdout = data["stdout"] if self.mode == "interactive": From 9055b7a91247e1754cf280cbbf298c7c35fe2ff3 Mon Sep 17 00:00:00 2001 From: shatakshiiii Date: Mon, 3 Jun 2024 11:06:51 +0530 Subject: [PATCH 2/4] Address ruff N802 --- pyproject.toml | 1 - src/ansible_navigator/logger.py | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 46a9af86f..67229f116 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -284,7 +284,6 @@ ignore = [ 'FBT001', # Boolean positional arg in function definition 'FBT002', # Boolean default value in function definition 'FBT003', # Boolean positional value in function call - 'N802', # Function name `formatTime` should be lowercase 'N806', # Variable `FType` in function should be lowercase 'N812', # Lowercase `__version_collection_doc_cache__` imported as non-lowercase `VERSION_CDC` 'N813', # Camelcase `Action` imported as lowercase `stdout_action` diff --git a/src/ansible_navigator/logger.py b/src/ansible_navigator/logger.py index b5a26af35..1b76cd4aa 100644 --- a/src/ansible_navigator/logger.py +++ b/src/ansible_navigator/logger.py @@ -33,7 +33,11 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: self._time_zone = kwargs.pop("time_zone") super().__init__(*args, **kwargs) - def formatTime(self, record: logging.LogRecord, _datefmt: str | None = None) -> str: + def formatTime( # noqa: N802 + self, + record: logging.LogRecord, + _datefmt: str | None = None, + ) -> str: """Format the log timestamp. :param record: The log record From 4e38ed7fa3fbe752bfa11686870221451a64cf1e Mon Sep 17 00:00:00 2001 From: shatakshiiii Date: Mon, 3 Jun 2024 11:27:51 +0530 Subject: [PATCH 3/4] N806: Variable in function should be lowercase --- tests/defaults.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/defaults.py b/tests/defaults.py index ddfb42aeb..bb5d48f1c 100644 --- a/tests/defaults.py +++ b/tests/defaults.py @@ -27,7 +27,7 @@ def id_func(param: Any) -> str: :return: Returns a string. """ result = "" - _AUTO_ID_COUNTER = 0 + auto_id_counter = 0 if isinstance(param, str): result = param elif hasattr(param, "value") and isinstance(param.value, str): # covers for Enums too @@ -49,7 +49,7 @@ def id_func(param: Any) -> str: args.append(str(part)) result = "-".join(args) else: - result = str(_AUTO_ID_COUNTER) - _AUTO_ID_COUNTER += 1 + result = str(auto_id_counter) + auto_id_counter += 1 result = result.lower().replace(" ", "-") return result From b86ccf9496a92458c1d74e09eca349a53e5987fe Mon Sep 17 00:00:00 2001 From: shatakshiiii Date: Mon, 3 Jun 2024 11:38:43 +0530 Subject: [PATCH 4/4] More of N806 --- pyproject.toml | 1 - tests/unit/actions/run/test_runner_async.py | 8 +++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 67229f116..0b06e6316 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -284,7 +284,6 @@ ignore = [ 'FBT001', # Boolean positional arg in function definition 'FBT002', # Boolean default value in function definition 'FBT003', # Boolean positional value in function call - 'N806', # Variable `FType` in function should be lowercase 'N812', # Lowercase `__version_collection_doc_cache__` imported as non-lowercase `VERSION_CDC` 'N813', # Camelcase `Action` imported as lowercase `stdout_action` 'N817', # CamelCase `Constants` imported as acronym `C` diff --git a/tests/unit/actions/run/test_runner_async.py b/tests/unit/actions/run/test_runner_async.py index 16f01d3c1..ee0c652b6 100644 --- a/tests/unit/actions/run/test_runner_async.py +++ b/tests/unit/actions/run/test_runner_async.py @@ -132,15 +132,17 @@ def test_runner_args(mocker: MockerFixture, data: Scenario) -> None: args.entry("ansible_runner_timeout").value.current = data.timeout args.entry("ansible_runner_write_job_events").value.current = data.write_job_events - TestRunnerException = Exception + class TestRunnerError(Exception): + """Test runner exception.""" + command_async = mocker.patch( "ansible_navigator.actions.run.CommandAsync", - side_effect=TestRunnerException, + side_effect=TestRunnerError, ) run = action(args=args) run._queue = TEST_QUEUE # pylint: disable=protected-access - with pytest.raises(TestRunnerException): + with pytest.raises(TestRunnerError): run._run_runner() # pylint: disable=protected-access command_async.assert_called_once_with(**data.expected)