From 1fd6a618b60d7168fd8f37585d5d39d22d775afd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 28 Mar 2024 07:11:39 +0100 Subject: Adding upstream version 0.13.0. Signed-off-by: Daniel Baumann --- tests/lib/utils.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/lib/utils.py (limited to 'tests/lib/utils.py') diff --git a/tests/lib/utils.py b/tests/lib/utils.py new file mode 100644 index 0000000..460e014 --- /dev/null +++ b/tests/lib/utils.py @@ -0,0 +1,49 @@ +# 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. +""" +tests.lib.utils +""" +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: + """ + generate_test_ids Helper to generate test ID for parametrize + """ + return val.get(key, "unamed_test") + + +def generate_test_ids_list(val: list[dict[str, Any]], key: str = "name") -> list[str]: + """ + generate_test_ids Helper to generate test ID for parametrize + """ + return [entry[key] if key in entry.keys() else "unamed_test" for entry in val] + + +def generate_test_ids(data: list[dict[str, Any]]) -> list[str]: + """ + build id for a unit test of an AntaTest subclass + + { + "name": "meaniful test name", + "test": , + ... + } + """ + return [f"{val['test'].__module__}.{val['test'].__name__}-{val['name']}" for val in data] + + +def default_anta_env() -> dict[str, str | None]: + """ + Return a default_anta_environement which can be passed to a cliRunner.invoke method + """ + 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"), + } -- cgit v1.2.3