summaryrefslogtreecommitdiffstats
path: root/tests/units/inventory/test_inventory.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units/inventory/test_inventory.py')
-rw-r--r--tests/units/inventory/test_inventory.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/tests/units/inventory/test_inventory.py b/tests/units/inventory/test_inventory.py
index 7c62b5c..430ca21 100644
--- a/tests/units/inventory/test_inventory.py
+++ b/tests/units/inventory/test_inventory.py
@@ -2,23 +2,25 @@
# Use of this source code is governed by the Apache License 2.0
# that can be found in the LICENSE file.
"""ANTA Inventory unit tests."""
+
from __future__ import annotations
-import logging
-from pathlib import Path
-from typing import Any
+from typing import TYPE_CHECKING, Any
import pytest
import yaml
from pydantic import ValidationError
from anta.inventory import AntaInventory
-from anta.inventory.exceptions import InventoryIncorrectSchema, InventoryRootKeyError
+from anta.inventory.exceptions import InventoryIncorrectSchemaError, InventoryRootKeyError
from tests.data.json_data import ANTA_INVENTORY_TESTS_INVALID, ANTA_INVENTORY_TESTS_VALID
from tests.lib.utils import generate_test_ids_dict
+if TYPE_CHECKING:
+ from pathlib import Path
+
-class Test_AntaInventory:
+class TestAntaInventory:
"""Test AntaInventory class."""
def create_inventory(self, content: str, tmp_path: Path) -> str:
@@ -31,7 +33,7 @@ class Test_AntaInventory:
def check_parameter(self, parameter: str, test_definition: dict[Any, Any]) -> bool:
"""Check if parameter is configured in testbed."""
- return "parameters" in test_definition and parameter in test_definition["parameters"].keys()
+ return "parameters" in test_definition and parameter in test_definition["parameters"]
@pytest.mark.parametrize("test_definition", ANTA_INVENTORY_TESTS_VALID, ids=generate_test_ids_dict)
def test_init_valid(self, test_definition: dict[str, Any], tmp_path: Path) -> None:
@@ -55,8 +57,7 @@ class Test_AntaInventory:
try:
AntaInventory.parse(filename=inventory_file, username="arista", password="arista123")
except ValidationError as exc:
- logging.error("Exceptions is: %s", str(exc))
- assert False
+ raise AssertionError from exc
@pytest.mark.parametrize("test_definition", ANTA_INVENTORY_TESTS_INVALID, ids=generate_test_ids_dict)
def test_init_invalid(self, test_definition: dict[str, Any], tmp_path: Path) -> None:
@@ -77,5 +78,5 @@ class Test_AntaInventory:
"""
inventory_file = self.create_inventory(content=test_definition["input"], tmp_path=tmp_path)
- with pytest.raises((InventoryIncorrectSchema, InventoryRootKeyError, ValidationError)):
+ with pytest.raises((InventoryIncorrectSchemaError, InventoryRootKeyError, ValidationError)):
AntaInventory.parse(filename=inventory_file, username="arista", password="arista123")