69 lines
2.7 KiB
Python
69 lines
2.7 KiB
Python
"""Robot Framework keyword library for the public validate_dict() API.
|
|
|
|
Contains keywords extracted from CleverActorsLib.py to keep that file
|
|
under the 500-line limit (CONTRIBUTING.md §General Principles).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
import cleveractors
|
|
from cleveractors import validate_dict
|
|
from cleveractors.core.exceptions import ConfigurationError
|
|
|
|
|
|
class ValidateDictLib: # pragma: no cover - integration test library
|
|
"""Keyword library for validate_dict Robot Framework integration tests."""
|
|
|
|
ROBOT_LIBRARY_SCOPE = "TEST SUITE"
|
|
|
|
def validate_dict_succeeds(
|
|
self, config_dict: dict[str, Any], platform_limits: dict[str, Any]
|
|
) -> dict[str, Any]:
|
|
"""Call validate_dict and return the result; raises on any error."""
|
|
return validate_dict(config_dict, platform_limits)
|
|
|
|
def validate_dict_raises_configuration_error(
|
|
self, config_dict: dict[str, Any], platform_limits: dict[str, Any]
|
|
) -> None:
|
|
"""Assert that validate_dict raises ConfigurationError."""
|
|
try:
|
|
validate_dict(config_dict, platform_limits)
|
|
except ConfigurationError:
|
|
return
|
|
raise AssertionError(
|
|
"Expected ConfigurationError but validate_dict returned without error"
|
|
)
|
|
|
|
def validate_dict_returns_same_object(self, config_dict: dict[str, Any]) -> None:
|
|
"""Assert that validate_dict returns the same dict object (identity)."""
|
|
result = validate_dict(config_dict, {})
|
|
if result is not config_dict:
|
|
raise AssertionError(
|
|
"validate_dict must return the same dict object as the input, "
|
|
"but returned a different object."
|
|
)
|
|
|
|
def validate_dict_is_exported(self) -> None:
|
|
"""Assert that validate_dict is in cleveractors.__all__."""
|
|
if "validate_dict" not in cleveractors.__all__:
|
|
raise AssertionError(
|
|
f"'validate_dict' not found in cleveractors.__all__: {cleveractors.__all__}"
|
|
)
|
|
|
|
def configuration_error_importable_from_top_level_package(self) -> None:
|
|
"""Assert that ConfigurationError is importable from cleveractors."""
|
|
if not hasattr(cleveractors, "ConfigurationError"):
|
|
raise AssertionError(
|
|
"ConfigurationError is not importable from cleveractors"
|
|
)
|
|
|
|
def configuration_error_listed_in_all(self) -> None:
|
|
"""Assert that ConfigurationError is listed in cleveractors.__all__."""
|
|
if "ConfigurationError" not in cleveractors.__all__:
|
|
raise AssertionError(
|
|
f"'ConfigurationError' not found in cleveractors.__all__: "
|
|
f"{cleveractors.__all__}"
|
|
)
|