Merging upstream version 1.4.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
a6f5a146cb
commit
3254dea030
166 changed files with 13787 additions and 11959 deletions
|
@ -29,9 +29,22 @@ $ pip install -e .[dev,cli]
|
|||
$ pip list -e
|
||||
Package Version Editable project location
|
||||
------- ------- -------------------------
|
||||
anta 1.3.0 /mnt/lab/projects/anta
|
||||
anta 1.4.0 /mnt/lab/projects/anta
|
||||
```
|
||||
|
||||
!!! info "Installation Note"
|
||||
1. If you are using a terminal such as zsh, ensure that commands involving shell expansions within editable installs (like specifying development dependencies) are enclosed in double quotes. For example: `pip install -e ."[dev]"`
|
||||
2. If you do not see any output when running the verification command (`pip list -e`), it is likely because the command needs to be executed from within the inner `anta` directory. Navigate to this directory and then verify the installation:
|
||||
|
||||
```
|
||||
$ cd anta/anta
|
||||
# Verify installation
|
||||
$ pip list -e
|
||||
Package Version Editable project location
|
||||
------- ------- --------------------------
|
||||
anta 1.4.0 /mnt/lab/projects/anta
|
||||
```
|
||||
|
||||
Then, [`tox`](https://tox.wiki/) is configured with few environments to run CI locally:
|
||||
|
||||
```bash
|
||||
|
@ -103,14 +116,19 @@ The `pytest_generate_tests` function will parametrize the generic test function
|
|||
|
||||
See https://docs.pytest.org/en/7.3.x/how-to/parametrize.html#basic-pytest-generate-tests-example
|
||||
|
||||
The `DATA` structure is a list of dictionaries used to parametrize the test. The list elements have the following keys:
|
||||
The `DATA` structure is a dictionary where:
|
||||
|
||||
- Each key is a tuple of size 2 containing:
|
||||
- An AntaTest subclass imported in the test module as first element - e.g. VerifyUptime.
|
||||
- A string used as name displayed by pytest as second element.
|
||||
- Each value is an instance of AntaUnitTest, which is a Python TypedDict.
|
||||
|
||||
And AntaUnitTest have the following keys:
|
||||
|
||||
- `name` (str): Test name as displayed by Pytest.
|
||||
- `test` (AntaTest): An AntaTest subclass imported in the test module - e.g. VerifyUptime.
|
||||
- `eos_data` (list[dict]): List of data mocking EOS returned data to be passed to the test.
|
||||
- `inputs` (dict): Dictionary to instantiate the `test` inputs as defined in the class from `test`.
|
||||
- `expected` (dict): Expected test result structure, a dictionary containing a key
|
||||
`result` containing one of the allowed status (`Literal['success', 'failure', 'unset', 'skipped', 'error']`) and optionally a key `messages` which is a list(str) and each message is expected to be a substring of one of the actual messages in the TestResult object.
|
||||
`result` containing one of the allowed status (`Literal[AntaTestStatus.SUCCESS, AntaTestStatus.FAILURE, AntaTestStatus.SKIPPED]`) and optionally a key `messages` which is a list(str) and each message is expected to be a substring of one of the actual messages in the TestResult object.
|
||||
|
||||
In order for your unit tests to be correctly collected, you need to import the generic test function even if not used in the Python module.
|
||||
|
||||
|
@ -124,29 +142,24 @@ from tests.units.anta_tests import test
|
|||
from anta.tests.system import VerifyUptime
|
||||
|
||||
# Define test parameters
|
||||
DATA: list[dict[str, Any]] = [
|
||||
{
|
||||
# Arbitrary test name
|
||||
"name": "success",
|
||||
# Must be an AntaTest definition
|
||||
"test": VerifyUptime,
|
||||
# Data returned by EOS on which the AntaTest is tested
|
||||
"eos_data": [{"upTime": 1186689.15, "loadAvg": [0.13, 0.12, 0.09], "users": 1, "currentTime": 1683186659.139859}],
|
||||
# Dictionary to instantiate VerifyUptime.Input
|
||||
"inputs": {"minimum": 666},
|
||||
# Expected test result
|
||||
"expected": {"result": "success"},
|
||||
},
|
||||
{
|
||||
"name": "failure",
|
||||
"test": VerifyUptime,
|
||||
"eos_data": [{"upTime": 665.15, "loadAvg": [0.13, 0.12, 0.09], "users": 1, "currentTime": 1683186659.139859}],
|
||||
"inputs": {"minimum": 666},
|
||||
# If the test returns messages, it needs to be expected otherwise test will fail.
|
||||
# NB: expected messages only needs to be included in messages returned by the test. Exact match is not required.
|
||||
"expected": {"result": "failure", "messages": ["Device uptime is 665.15 seconds"]},
|
||||
},
|
||||
]
|
||||
DATA: dict[tuple[type[AntaTest], str], AntaUnitTest] = {
|
||||
(VerifyUptime, "success"): {
|
||||
# Data returned by EOS on which the AntaTest is tested
|
||||
"eos_data": [{"upTime": 1186689.15, "loadAvg": [0.13, 0.12, 0.09], "users": 1, "currentTime": 1683186659.139859}],
|
||||
# Dictionary to instantiate VerifyUptime.Input
|
||||
"inputs": {"minimum": 666},
|
||||
# Expected test result
|
||||
"expected": {"result": AntaTestStatus.SUCCESS},
|
||||
},
|
||||
(VerifyUptime, "failure"): {
|
||||
# Data returned by EOS on which the AntaTest is tested
|
||||
"eos_data": [{"upTime": 665.15, "loadAvg": [0.13, 0.12, 0.09], "users": 1, "currentTime": 1683186659.139859}],
|
||||
"inputs": {"minimum": 666},
|
||||
# If the test returns messages, it needs to be expected otherwise test will fail.
|
||||
# NB: expected messages only needs to be included in messages returned by the test. Exact match is not required.
|
||||
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["Device uptime is 665.15 seconds"]},
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Git Pre-commit hook
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue