Debian Codegraph @

tests/integration/test_merge_catalogs.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/merge_catalogs.py script."""
5
6 from __future__ import annotations
7
8 import runpy
9 from pathlib import Path
10
11 from anta.catalog import AntaCatalog
12
13 DATA = Path(__file__).parent / "data"
14 MERGE_CATALOGS_PATH = Path(__file__).parents[2] / "examples/merge_catalogs.py"
15
16
17 def test_merge_catalogs() -> None:
18 """Test merge_catalogs script."""
19 # Adding symlink to match the script data
20 intended_path = Path.cwd() / "intended"
21 intended_path.mkdir(exist_ok=True)
22 intended_catalogs_path = intended_path / "test_catalogs/"
23 intended_catalogs_path.symlink_to(DATA, target_is_directory=True)
24 output_catalog = Path("anta-catalog.yml")
25
26 try:
27 # Run the script
28 runpy.run_path(str(MERGE_CATALOGS_PATH), run_name="__main__")
29 # Assert that the created file exist and is a combination of the inputs
30 assert output_catalog.exists()
31
32 total_tests = sum(len(AntaCatalog.parse(catalog_file).tests) for catalog_file in DATA.rglob("*-catalog.yml"))
33
34 assert total_tests == len(AntaCatalog.parse(output_catalog).tests)
35
36 finally:
37 # Cleanup
38 output_catalog.unlink()
39 intended_catalogs_path.unlink()
40 intended_path.rmdir()