Debian Codegraph @

tests/units/cli/check/test_commands.py

raw symbols SCIP
1 # Copyright (c) 2023-2026 Arista Networks, Inc.
2 # Use of this source code is governed by the Apache License 2.0
3 # that can be found in the LICENSE file.
4 """Tests for anta.cli.check.commands."""
5
6 from __future__ import annotations
7
8 from pathlib import Path
9 from typing import TYPE_CHECKING
10
11 import pytest
12
13 from anta.cli import anta
14 from anta.cli.utils import ExitCode
15
16 if TYPE_CHECKING:
17 from click.testing import CliRunner
18
19 DATA_DIR: Path = Path(__file__).parents[3].resolve() / "data"
20
21
22 @pytest.mark.parametrize(
23 ("catalog_path", "expected_exit", "expected_output"),
24 [
25 pytest.param("ghost_catalog.yml", ExitCode.USAGE_ERROR, "Error: Invalid value for '--catalog'", id="catalog does not exist"),
26 pytest.param("test_catalog_with_undefined_module.yml", ExitCode.USAGE_ERROR, "Test catalog is invalid!", id="catalog is not valid"),
27 pytest.param("test_catalog.yml", ExitCode.OK, "Catalog is valid", id="catalog valid"),
28 ],
29 )
30 def test_catalog(click_runner: CliRunner, catalog_path: Path, expected_exit: int, expected_output: str) -> None:
31 """Test `anta check catalog -c catalog."""
32 result = click_runner.invoke(anta, ["check", "catalog", "-c", str(DATA_DIR / catalog_path)])
33 assert result.exit_code == expected_exit
34 assert expected_output in result.output