2025-02-05 11:32:35 +01:00
|
|
|
# Copyright (c) 2023-2024 Arista Networks, Inc.
|
|
|
|
# Use of this source code is governed by the Apache License 2.0
|
|
|
|
# that can be found in the LICENSE file.
|
2025-02-05 11:39:09 +01:00
|
|
|
"""tests.lib.utils."""
|
|
|
|
|
2025-02-05 11:32:35 +01:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from pathlib import Path
|
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
|
|
|
|
def generate_test_ids_dict(val: dict[str, Any], key: str = "name") -> str:
|
2025-02-05 11:39:09 +01:00
|
|
|
"""generate_test_ids Helper to generate test ID for parametrize."""
|
2025-02-05 11:32:35 +01:00
|
|
|
return val.get(key, "unamed_test")
|
|
|
|
|
|
|
|
|
|
|
|
def generate_test_ids_list(val: list[dict[str, Any]], key: str = "name") -> list[str]:
|
2025-02-05 11:39:09 +01:00
|
|
|
"""generate_test_ids Helper to generate test ID for parametrize."""
|
|
|
|
return [entry.get(key, "unamed_test") for entry in val]
|
2025-02-05 11:32:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
def generate_test_ids(data: list[dict[str, Any]]) -> list[str]:
|
2025-02-05 11:39:09 +01:00
|
|
|
"""Build id for a unit test of an AntaTest subclass.
|
2025-02-05 11:32:35 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
"name": "meaniful test name",
|
|
|
|
"test": <AntaTest instance>,
|
|
|
|
...
|
|
|
|
}
|
|
|
|
"""
|
2025-02-05 11:39:50 +01:00
|
|
|
return [f"{val['test'].module}.{val['test'].__name__}-{val['name']}" for val in data]
|
2025-02-05 11:32:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
def default_anta_env() -> dict[str, str | None]:
|
2025-02-05 11:39:09 +01:00
|
|
|
"""Return a default_anta_environement which can be passed to a cliRunner.invoke method."""
|
2025-02-05 11:32:35 +01:00
|
|
|
return {
|
|
|
|
"ANTA_USERNAME": "anta",
|
|
|
|
"ANTA_PASSWORD": "formica",
|
|
|
|
"ANTA_INVENTORY": str(Path(__file__).parent.parent / "data" / "test_inventory.yml"),
|
|
|
|
"ANTA_CATALOG": str(Path(__file__).parent.parent / "data" / "test_catalog.yml"),
|
|
|
|
}
|