| 1 |
|
| 2 |
|
| 3 |
|
| 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 |
|
| 24 |
|
| 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 |
|
| 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 |
|
| 40 |
inventory_path.unlink() |