| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
"""Generates examples/tests.py.""" |
| 6 |
|
| 7 |
import os |
| 8 |
from contextlib import redirect_stdout |
| 9 |
from pathlib import Path |
| 10 |
from sys import path |
| 11 |
|
| 12 |
from yaml import YAMLError |
| 13 |
|
| 14 |
|
| 15 |
path.insert(0, str(Path(__file__).parents[2])) |
| 16 |
|
| 17 |
from anta.catalog import AntaCatalog |
| 18 |
|
| 19 |
examples_tests_path = Path(__file__).parents[2] / "examples" / "tests.yaml" |
| 20 |
|
| 21 |
|
| 22 |
prev = os.environ.get("TERM", "") |
| 23 |
os.environ["TERM"] = "dumb" |
| 24 |
|
| 25 |
from anta.cli.get.commands import tests |
| 26 |
|
| 27 |
try: |
| 28 |
with examples_tests_path.open("w") as f: |
| 29 |
f.write("---\n") |
| 30 |
with redirect_stdout(f): |
| 31 |
|
| 32 |
tests() |
| 33 |
except SystemExit: |
| 34 |
pass |
| 35 |
|
| 36 |
os.environ["TERM"] = prev |
| 37 |
|
| 38 |
try: |
| 39 |
_ = AntaCatalog.parse(examples_tests_path) |
| 40 |
except (TypeError, ValueError, YAMLError, OSError) as e: |
| 41 |
msg = f"Failed to parse catalog: {e}" |
| 42 |
raise ValueError(msg) from None |