| 1 |
|
| 2 |
|
| 3 |
|
| 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 |
|
| 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 |
|
| 28 |
runpy.run_path(str(MERGE_CATALOGS_PATH), run_name="__main__") |
| 29 |
|
| 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 |
|
| 38 |
output_catalog.unlink() |
| 39 |
intended_catalogs_path.unlink() |
| 40 |
intended_path.rmdir() |