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()
Args:
tests: A list of AntaTestDefinition instances.
filename: The path from which the catalog is loaded.
Source code in anta/catalog.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
|
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.
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.
Args:
data: Python dictionary used to instantiate the AntaCatalog instance
filename: value to be set as AntaCatalog instance attribute
Source code in anta/catalog.py
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 302 303 304 305 306 307 308 309 310 |
|
from_list
staticmethod
¶
from_list(data: ListAntaTestTuples) -> AntaCatalog
Create an AntaCatalog instance from a list data structure.
See ListAntaTestTuples type alias for details.
Args:
data: Python list used to instantiate the AntaCatalog instance
Source code in anta/catalog.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
|
get_tests_by_names ¶
get_tests_by_names(names: set[str]) -> list[AntaTestDefinition]
Return all the tests that have matching a list of tests names.
Args:
names: Names of the tests to get.
Returns:
Type | Description |
---|---|
List of AntaTestDefinition that match the names
|
|
Source code in anta/catalog.py
356 357 358 359 360 361 362 363 364 365 366 367 |
|
get_tests_by_tags ¶
get_tests_by_tags(tags: set[str], *, strict: bool = False) -> list[AntaTestDefinition]
Return all the tests that have matching tags in their input filters.
If strict=True, return only tests that match all the tags provided as input. If strict=False, return all the tests that match at least one tag provided as input.
Args:
tags: Tags of the tests to get.
strict: Specify if the returned tests must match all the tags provided.
Returns:
Type | Description |
---|---|
List of AntaTestDefinition that match the tags
|
|
Source code in anta/catalog.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
|
parse
staticmethod
¶
parse(filename: str | Path) -> AntaCatalog
Create an AntaCatalog instance from a test catalog file.
Args:
filename: Path to test catalog YAML file
Source code in anta/catalog.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
|
AntaTestDefinition ¶
AntaTestDefinition(**data: type[AntaTest] | AntaTest.Input | dict[str, Any] | None)
Bases: BaseModel
Define a test with its associated inputs.
test: An AntaTest concrete subclass inputs: The associated AntaTest.Input subclass instance
Source code in anta/catalog.py
46 47 48 49 50 51 52 53 54 55 56 |
|
check_inputs ¶
check_inputs() -> AntaTestDefinition
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
99 100 101 102 103 104 105 106 107 108 |
|
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
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
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
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 199 200 201 202 203 |
|
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
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|