8000 feat(anta.cli): Add possibility to render multiple examples for the same test by gmuloc · Pull Request #1098 · aristanetworks/anta · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(anta.cli): Add possibility to render multiple examples for the same test #1098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions anta/cli/get/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,17 +350,18 @@ def print_test(test: type[AntaTest], *, short: bool = False) -> None:
# Need to handle the fact that we nest the routing modules in Examples.
# This is a bit fragile.
inputs = example.split("\n")
try:
test_name_line = next((i for i, input_entry in enumerate(inputs) if test.name in input_entry))
except StopIteration as e:
test_name_lines = [i for i, input_entry in enumerate(inputs) if test.name in input_entry]
if not test_name_lines:
msg = f"Could not find the name of the test '{test.name}' in the Example section in the docstring."
raise ValueError(msg) from e
# TODO: handle not found
console.print(f" {inputs[test_name_line].strip()}")
# Injecting the description
console.print(f" # {test.description}", soft_wrap=True)
if not short and len(inputs) > test_name_line + 2: # There are params
console.print(textwrap.indent(textwrap.dedent("\n".join(inputs[test_name_line + 1 : -1])), " " * 6))
raise ValueError(msg)
for list_index, line_index in enumerate(test_name_lines):
end = test_name_lines[list_index + 1] if list_index + 1 < len(test_name_lines) else -1
console.print(f" {inputs[line_index].strip()}")
# Injecting the description for the first example
if list_index == 0:
console.print(f& 8000 quot; # {test.description}", soft_wrap=True)
if not short and len(inputs) > line_index + 2: # There are params
console.print(textwrap.indent(textwrap.dedent("\n".join(inputs[line_index + 1 : end])), " " * 6))


def extract_examples(docstring: str) -> str | None:
Expand Down
4 changes: 4 additions & 0 deletions anta/tests/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ class VerifyNTPAssociations(AntaTest):
stratum: 2
- server_address: 3.3.3.3
stratum: 2
- VerifyNTPAssociations:
ntp_pool:
server_addresses: [1.1.1.1, 2.2.2.2]
preferred_stratum_range: [1,3]
```
"""

Expand Down
4 changes: 4 additions & 0 deletions examples/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,10 @@ anta.tests.system:
stratum: 2
- server_address: 3.3.3.3
stratum: 2
- VerifyNTPAssociations:
ntp_pool:
server_addresses: [1.1.1.1, 2.2.2.2]
preferred_stratum_range: [1,3]
- VerifyReloadCause:
# Verifies the last reload cause of the device.
- VerifyUptime:
Expand Down
0