From 9c97c677584abc83078ed2a2f4b1c15e42ef486f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 10 Jan 2025 04:46:22 +0000 Subject: [PATCH 1/4] chore: update ruff requirement from <0.9.0,>=0.5.4 to >=0.5.4,<0.10.0 Updates the requirements on [ruff](https://github.com/astral-sh/ruff) to permit the latest version. - [Release notes](https://github.com/astral-sh/ruff/releases) - [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md) - [Commits](https://github.com/astral-sh/ruff/compare/0.5.4...0.9.0) --- updated-dependencies: - dependency-name: ruff dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 1e85b01f0..eda9c87d7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -75,7 +75,7 @@ dev = [ "pytest-metadata>=3.0.0", "pytest>=7.4.0", "respx>=0.22.0", - "ruff>=0.5.4,<0.9.0", + "ruff>=0.5.4,<0.10.0", "tox>=4.10.0,<5.0.0", "types-PyYAML", "types-pyOpenSSL", From e5e2935c3bfcf701904d1736947d4b8dfdb2dd8c Mon Sep 17 00:00:00 2001 From: Guillaume Mulocher Date: Fri, 10 Jan 2025 08:06:01 +0000 Subject: [PATCH 2/4] Update pre-commit as well --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f12dda006..1961ec0c4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -46,7 +46,7 @@ repos: - '' - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.8.6 + rev: v0.9.0 hooks: - id: ruff name: Run Ruff linter From afc5a0b1fb28289b810733c87be3d0b8939ab37e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 10 Jan 2025 08:12:19 +0000 Subject: [PATCH 3/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- anta/catalog.py | 8 +++----- anta/runner.py | 5 ++--- anta/tests/system.py | 2 +- tests/benchmark/test_anta.py | 2 +- tests/units/test_runner.py | 2 +- 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/anta/catalog.py b/anta/catalog.py index 65031cedc..ca0eeb176 100644 --- a/anta/catalog.py +++ b/anta/catalog.py @@ -182,7 +182,7 @@ def flatten_modules(data: dict[str, Any], package: str | None = None) -> dict[Mo except Exception as e: # A test module is potentially user-defined code. # We need to catch everything if we want to have meaningful logs - module_str = f"{module_name[1:] if module_name.startswith('.') else module_name}{f' from package {package}' if package else ''}" + module_str = f"{module_name.removeprefix('.')}{f' from package {package}' if package else ''}" message = f"Module named {module_str} cannot be imported. Verify that the module exists and there is no Python syntax issues." anta_log_exception(e, message, logger) raise ValueError(message) from e @@ -223,16 +223,14 @@ def check_tests(cls: type[AntaCatalogFile], data: Any) -> Any: # noqa: ANN401 raise ValueError(msg) # noqa: TRY004 pydantic catches ValueError or AssertionError, no TypeError if len(test_definition) != 1: msg = ( - f"Syntax error when parsing: {test_definition}\n" - "It must be a dictionary with a single entry. Check the indentation in the test catalog." + f"Syntax error when parsing: {test_definition}\nIt must be a dictionary with a single entry. Check the indentation in the test catalog." ) raise ValueError(msg) for test_name, test_inputs in test_definition.copy().items(): test: type[AntaTest] | None = getattr(module, test_name, None) if test is None: msg = ( - f"{test_name} is not defined in Python module {module.__name__}" - f"{f' (from {module.__file__})' if module.__file__ is not None else ''}" + f"{test_name} is not defined in Python module {module.__name__}{f' (from {module.__file__})' if module.__file__ is not None else ''}" ) raise ValueError(msg) test_definitions.append(AntaTestDefinition(test=test, inputs=test_inputs)) diff --git a/anta/runner.py b/anta/runner.py index 93c433722..2b3c8b70e 100644 --- a/anta/runner.py +++ b/anta/runner.py @@ -115,7 +115,7 @@ async def setup_inventory(inventory: AntaInventory, tags: set[str] | None, devic # If there are no devices in the inventory after filtering, exit if not selected_inventory.devices: - msg = f'No reachable device {f"matching the tags {tags} " if tags else ""}was found.{f" Selected devices: {devices} " if devices is not None else ""}' + msg = f"No reachable device {f'matching the tags {tags} ' if tags else ''}was found.{f' Selected devices: {devices} ' if devices is not None else ''}" logger.warning(msg) return None @@ -170,8 +170,7 @@ def prepare_tests( if total_test_count == 0: msg = ( - f"There are no tests{f' matching the tags {tags} ' if tags else ' '}to run in the current " - "test catalog and device inventory, please verify your inputs." + f"There are no tests{f' matching the tags {tags} ' if tags else ' '}to run in the current test catalog and device inventory, please verify your inputs." ) logger.warning(msg) return None diff --git a/anta/tests/system.py b/anta/tests/system.py index 85235f2fc..11cf8398c 100644 --- a/anta/tests/system.py +++ b/anta/tests/system.py @@ -224,7 +224,7 @@ def test(self) -> None: if memory_usage > MEMORY_THRESHOLD: self.result.is_success() else: - self.result.is_failure(f"Device has reported a high memory usage: {(1 - memory_usage)*100:.2f}%") + self.result.is_failure(f"Device has reported a high memory usage: {(1 - memory_usage) * 100:.2f}%") class VerifyFileSystemUtilization(AntaTest): diff --git a/tests/benchmark/test_anta.py b/tests/benchmark/test_anta.py index 91d3b3ff2..1daf7f369 100644 --- a/tests/benchmark/test_anta.py +++ b/tests/benchmark/test_anta.py @@ -47,7 +47,7 @@ def _() -> None: if len(results.results) != len(inventory) * len(catalog.tests): pytest.fail(f"Expected {len(inventory) * len(catalog.tests)} tests but got {len(results.results)}", pytrace=False) - bench_info = "\n--- ANTA NRFU Dry-Run Benchmark Information ---\n" f"Test count: {len(results.results)}\n" "-----------------------------------------------" + bench_info = f"\n--- ANTA NRFU Dry-Run Benchmark Information ---\nTest count: {len(results.results)}\n-----------------------------------------------" logger.info(bench_info) diff --git a/tests/units/test_runner.py b/tests/units/test_runner.py index b3ac1b56a..1b9c40c88 100644 --- a/tests/units/test_runner.py +++ b/tests/units/test_runner.py @@ -67,7 +67,7 @@ async def test_no_selected_device(caplog: pytest.LogCaptureFixture, inventory: A caplog.set_level(logging.WARNING) manager = ResultManager() await main(manager, inventory, FAKE_CATALOG, tags=tags, devices=devices) - msg = f'No reachable device {f"matching the tags {tags} " if tags else ""}was found.{f" Selected devices: {devices} " if devices is not None else ""}' + msg = f"No reachable device {f'matching the tags {tags} ' if tags else ''}was found.{f' Selected devices: {devices} ' if devices is not None else ''}" assert msg in caplog.messages From 6750f4ca4b8306d1cd1d286cd7d1b99c15b2c043 Mon Sep 17 00:00:00 2001 From: gmuloc Date: Fri, 10 Jan 2025 09:20:37 +0100 Subject: [PATCH 4/4] ci: Ignore shadowing logging module with anta.tests.logging --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index eda9c87d7..09fee8c3e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -428,6 +428,9 @@ runtime-evaluated-base-classes = ["pydantic.BaseModel", "anta.models.AntaTest.In "C901", # TODO: test function is too complex, needs a refactor "PLR0912" # Too many branches (15/12) (too-many-branches), needs a refactor ] +"anta/tests/logging.py" = [ + "A005", # TODO: Module `logging` shadows a Python standard-library module +] "anta/decorators.py" = [ "ANN401", # Ok to use Any type hint in our decorators ]