Debian Codegraph @

tests/integration/test_parse_anta_inventory_file.py

raw symbols SCIP
1 # Copyright (c) 2024-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 """Test examples/parse_anta_inventory_file.py script."""
5
6 from __future__ import annotations
7
8 import runpy
9 from pathlib import Path
10
11 import pytest
12 from yaml import safe_dump
13
14 from anta.inventory import AntaInventory
15
16 DATA = Path(__file__).parent / "data"
17 PARSE_ANTA_INVENTORY_FILE_PATH = Path(__file__).parents[2] / "examples/parse_anta_inventory_file.py"
18
19
20 @pytest.mark.parametrize("inventory", [{"count": 3}], indirect=["inventory"])
21 def test_parse_anta_inventory_file(capsys: pytest.CaptureFixture[str], inventory: AntaInventory) -> None:
22 """Test parse_anta_inventory_file script."""
23 # Create the inventory.yaml file expected by the script
24 # TODO: 2.0.0 this is horrendous - need to align how to dump things properly
25 inventory_path = Path.cwd() / "inventory.yaml"
26 yaml_data = {AntaInventory.INVENTORY_ROOT_KEY: inventory.dump().model_dump()}
27 with inventory_path.open("w") as f:
28 safe_dump(yaml_data, f)
29
30 try:
31 # Run the script
32 runpy.run_path(str(PARSE_ANTA_INVENTORY_FILE_PATH), run_name="__main__")
33 captured = capsys.readouterr()
34 assert "Device device-0 is online" in captured.out
35 assert "Device device-1 is online" in captured.out
36 assert "Device device-2 is online" in captured.out
37
38 finally:
39 # Cleanup
40 inventory_path.unlink()