Test Catalog
AntaCatalog ¶
AntaCatalog(
tests: list[AntaTestDefinition] | None = None,
filename: str | Path | None = None,
)
Class representing an ANTA Catalog.
It can be instantiated using its constructor or one of the static methods: parse()
, from_list()
or from_dict()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tests |
list[AntaTestDefinition] | None
|
A list of AntaTestDefinition instances. |
None
|
filename |
str | Path | None
|
The path from which the catalog is loaded. |
None
|
Source code in anta/catalog.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
|
filename
property
¶
filename: Path | None
Path of the file used to create this AntaCatalog instance.
tests
property
writable
¶
tests: list[AntaTestDefinition]
List of AntaTestDefinition in this catalog.
build_indexes ¶
build_indexes(
filtered_tests: set[str] | None = None,
) -> None
Indexes tests by their tags for quick access during filtering operations.
If a filtered_tests
set is provided, only the tests in this set will be indexed.
This method populates the tag_to_tests attribute, which is a dictionary mapping tags to sets of tests.
Once the indexes are built, the indexes_built
attribute is set to True.
Source code in anta/catalog.py
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
|
clear_indexes ¶
clear_indexes() -> None
Clear this AntaCatalog instance indexes.
Source code in anta/catalog.py
505 506 507 |
|
dump ¶
dump() -> AntaCatalogFile
Return an AntaCatalogFile instance from this AntaCatalog instance.
Returns:
Type | Description |
---|---|
AntaCatalogFile
|
An AntaCatalogFile instance containing tests of this AntaCatalog instance. |
Source code in anta/catalog.py
468 469 470 471 472 473 474 475 476 477 478 479 480 |
|
from_dict
staticmethod
¶
from_dict(
data: RawCatalogInput,
filename: str | Path | None = None,
) -> AntaCatalog
Create an AntaCatalog instance from a dictionary data structure.
See RawCatalogInput type alias for details.
It is the data structure returned by yaml.load()
function of a valid
YAML Test Catalog file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
RawCatalogInput
|
Python dictionary used to instantiate the AntaCatalog instance. |
required |
filename |
str | Path | None
|
value to be set as AntaCatalog instance attribute |
None
|
Returns:
Type | Description |
---|---|
AntaCatalog
|
An AntaCatalog populated with the ‘data’ dictionary content. |
Source code in anta/catalog.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
|
from_list
staticmethod
¶
from_list(data: ListAntaTestTuples) -> AntaCatalog
Create an AntaCatalog instance from a list data structure.
See ListAntaTestTuples type alias for details.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
ListAntaTestTuples
|
Python list used to instantiate the AntaCatalog instance. |
required |
Returns:
Type | Description |
---|---|
AntaCatalog
|
An AntaCatalog populated with the ‘data’ list content. |
Source code in anta/catalog.py
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
|
get_tests_by_tags ¶
get_tests_by_tags(
tags: set[str], *, strict: bool = False
) -> set[AntaTestDefinition]
Return all tests that match a given set of tags, according to the specified strictness.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tags |
set[str]
|
The tags to filter tests by. If empty, return all tests without tags. |
required |
strict |
bool
|
If True, returns only tests that contain all specified tags (intersection). If False, returns tests that contain any of the specified tags (union). |
False
|
Returns:
Type | Description |
---|---|
set[AntaTestDefinition]
|
A set of tests that match the given tags. |
Raises:
Type | Description |
---|---|
ValueError
|
If the indexes have not been built prior to method call. |
Source code in anta/catalog.py
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 |
|
merge ¶
merge(catalog: AntaCatalog) -> AntaCatalog
Merge two AntaCatalog instances.
Warning
This method is deprecated and will be removed in ANTA v2.0. Use AntaCatalog.merge_catalogs()
instead.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
catalog |
AntaCatalog
|
AntaCatalog instance to merge to this instance. |
required |
Returns:
Type | Description |
---|---|
AntaCatalog
|
A new AntaCatalog instance containing the tests of the two instances. |
Source code in anta/catalog.py
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
|
merge_catalogs
classmethod
¶
merge_catalogs(catalogs: list[AntaCatalog]) -> AntaCatalog
Merge multiple AntaCatalog instances.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
catalogs |
list[AntaCatalog]
|
A list of AntaCatalog instances to merge. |
required |
Returns:
Type | Description |
---|---|
AntaCatalog
|
A new AntaCatalog instance containing the tests of all the input catalogs. |
Source code in anta/catalog.py
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 |
|
parse
staticmethod
¶
parse(
filename: str | Path,
file_format: Literal["yaml", "json"] = "yaml",
) -> AntaCatalog
Create an AntaCatalog instance from a test catalog file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str | Path
|
Path to test catalog YAML or JSON file. |
required |
file_format |
Literal['yaml', 'json']
|
Format of the file, either ‘yaml’ or ‘json’. |
'yaml'
|
Returns:
Type | Description |
---|---|
AntaCatalog
|
An AntaCatalog populated with the file content. |
Source code in anta/catalog.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
|
AntaTestDefinition ¶
AntaTestDefinition(
**data: (
type[AntaTest]
| AntaTest.Input
| dict[str, Any]
| None
)
)
Bases: BaseModel
Define a test with its associated inputs.
Attributes:
Name | Type | Description |
---|---|---|
test |
type[AntaTest]
|
An AntaTest concrete subclass. |
inputs |
Input
|
The associated AntaTest.Input subclass instance. |
Source code in anta/catalog.py
78 79 80 81 82 83 84 85 86 87 88 |
|
check_inputs ¶
check_inputs() -> Self
Check the inputs
field typing.
The inputs
class attribute needs to be an instance of the AntaTest.Input subclass defined in the class test
.
Source code in anta/catalog.py
131 132 133 134 135 136 137 138 139 140 |
|
instantiate_inputs
classmethod
¶
instantiate_inputs(
data: AntaTest.Input | dict[str, Any] | None,
info: ValidationInfo,
) -> AntaTest.Input
Ensure the test inputs can be instantiated and thus are valid.
If the test has no inputs, allow the user to omit providing the inputs
field.
If the test has inputs, allow the user to provide a valid dictionary of the input fields.
This model validator will instantiate an Input class from the test
class field.
Source code in anta/catalog.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
serialize_model ¶
serialize_model() -> dict[str, AntaTest.Input]
Serialize the AntaTestDefinition model.
The dictionary representing the model will be look like:
<AntaTest subclass name>:
<AntaTest.Input compliant dictionary>
Returns:
Type | Description |
---|---|
dict
|
A dictionary representing the model. |
Source code in anta/catalog.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
AntaCatalogFile ¶
Bases: RootModel[dict[ImportString[Any], list[AntaTestDefinition]]]
Represents an ANTA Test Catalog File.
Example
A valid test catalog file must have the following structure:
<Python module>:
- <AntaTest subclass>:
<AntaTest.Input compliant dictionary>
check_tests
classmethod
¶
check_tests(data: Any) -> Any
Allow the user to provide a Python data structure that only has string values.
This validator will try to flatten and import Python modules, check if the tests classes are actually defined in their respective Python module and instantiate Input instances with provided value to validate test inputs.
Source code in anta/catalog.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
|
flatten_modules
staticmethod
¶
flatten_modules(
data: dict[str, Any], package: str | None = None
) -> dict[ModuleType, list[Any]]
Allow the user to provide a data structure with nested Python modules.
Example
anta.tests.routing:
generic:
- <AntaTestDefinition>
bgp:
- <AntaTestDefinition>
anta.tests.routing.generic
and anta.tests.routing.bgp
are importable Python modules.
Source code in anta/catalog.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
|
to_json ¶
to_json() -> str
Return a JSON representation string of this model.
Returns:
Type | Description |
---|---|
str
|
The JSON representation string of this model. |
Source code in anta/catalog.py
257 258 259 260 261 262 263 264 265 |
|
yaml ¶
yaml() -> str
Return a YAML representation string of this model.
Returns:
Type | Description |
---|---|
str
|
The YAML representation string of this model. |
Source code in anta/catalog.py
243 244 245 246 247 248 249 250 251 252 253 254 255 |
|