Adding upstream version 1.4.0.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-05-15 09:34:27 +02:00
parent dc7df702ea
commit 7996c81031
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
166 changed files with 13787 additions and 11959 deletions

View file

@ -7,6 +7,9 @@ from __future__ import annotations
from typing import TYPE_CHECKING, Any
import pytest
from anta._runner import AntaRunContext, AntaRunFilters, AntaRunner
from anta.result_manager import ResultManager
from anta.runner import get_coroutines, prepare_tests
@ -22,6 +25,8 @@ if TYPE_CHECKING:
from anta.result_manager.models import TestResult
# TODO: Remove this in ANTA v2.0.0
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
def test_prepare_tests(benchmark: BenchmarkFixture, catalog: AntaCatalog, inventory: AntaInventory) -> None:
"""Benchmark `anta.runner.prepare_tests`."""
@ -36,6 +41,8 @@ def test_prepare_tests(benchmark: BenchmarkFixture, catalog: AntaCatalog, invent
assert sum(len(tests) for tests in selected_tests.values()) == len(inventory) * len(catalog.tests)
# TODO: Remove this in ANTA v2.0.0
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
def test_get_coroutines(benchmark: BenchmarkFixture, catalog: AntaCatalog, inventory: AntaInventory) -> None:
"""Benchmark `anta.runner.get_coroutines`."""
selected_tests = prepare_tests(inventory=inventory, catalog=catalog, tests=None, tags=None)
@ -52,3 +59,38 @@ def test_get_coroutines(benchmark: BenchmarkFixture, catalog: AntaCatalog, inven
count = sum(len(tests) for tests in selected_tests.values())
assert count == len(coroutines)
def test__setup_tests(benchmark: BenchmarkFixture, catalog: AntaCatalog, inventory: AntaInventory) -> None:
"""Benchmark `anta._runner.AntaRunner._setup_tests`."""
runner = AntaRunner()
ctx = AntaRunContext(inventory=inventory, catalog=catalog, manager=ResultManager(), filters=AntaRunFilters(), selected_inventory=inventory)
def bench() -> None:
catalog.clear_indexes()
runner._setup_tests(ctx)
benchmark(bench)
assert ctx.total_tests_scheduled != 0
assert ctx.total_devices_selected_for_testing == len(inventory)
assert ctx.total_tests_scheduled == len(inventory) * len(catalog.tests)
def test__get_test_coroutines(benchmark: BenchmarkFixture, catalog: AntaCatalog, inventory: AntaInventory) -> None:
"""Benchmark `anta._runner.AntaRunner._get_test_coroutines`."""
runner = AntaRunner()
ctx = AntaRunContext(inventory=inventory, catalog=catalog, manager=ResultManager(), filters=AntaRunFilters(), selected_inventory=inventory)
runner._setup_tests(ctx)
assert ctx.selected_tests is not None
def bench() -> list[Coroutine[Any, Any, TestResult]]:
coros = runner._get_test_coroutines(ctx)
for c in coros:
c.close()
return coros
coroutines = benchmark(bench)
assert ctx.total_tests_scheduled == len(coroutines)