-
Notifications
You must be signed in to change notification settings - Fork 28
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
feat(anta.cli): Add anta get tests #843
base: main
Are you sure you want to change the base?
Conversation
for more information, see https://pre-commit.ci
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Conflicts have been resolved. A maintainer will review the pull request shortly. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Conflicts have been resolved. A maintainer will review the pull request shortly. |
CodSpeed Performance ReportMerging #843 will not alter performanceComparing Summary
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
@click.option("--test", help="Test name to retrieve the example for. If module is set, lookup only in given module.", required=False) | ||
@click.option("--short", help="Print test names only and not the inputs", required=False, is_flag=True, default=False) | ||
@click.command | ||
def tests(module: str | None, test: str | None, *, short: bool) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also add anta get tests --count
and display something like: Total tests available in ANTA: 154
or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can - you think it is useful or is it just for us? :p
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for us :)
@click.command | ||
def tests(module: str | None, test: str | None, *, short: bool) -> None: | ||
"""Show all builtin ANTA tests with an example output retrieved from each test documentation.""" | ||
filterwarnings("ignore", message="Unknown section Expected Results") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment about why we can safely ignore that warning.
anta/cli/get/commands.py
Outdated
if module: | ||
explore_package(module, test_name=test, short=short) | ||
else: | ||
explore_package("anta.tests", test_name=test, short=short) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if module: | |
explore_package(module, test_name=test, short=short) | |
else: | |
explore_package("anta.tests", test_name=test, short=short) | |
module = module or "anta.tests" | |
explore_package(module, test_name=test, short=short) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, are we ok with empty strings? If we do anta get tests --module ""
or anta get tests --test ""
we basically get everything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can be nice to the user and say "Hey your filter is empty" or something.
@@ -352,6 +352,7 @@ class VerifyAcctConsoleMethods(AntaTest): | |||
``` | |||
""" | |||
|
|||
description = "Verifies the AAA accounting console method lists for different accounting types (system, exec, commands, dot1x)." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this if it's the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm something with wrap I think - need to investigate again
regex_patterns: | ||
- "^enable password.*$" | ||
- "bla bla" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the script still work if the indentation is not ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's bad no? That means a dev can create a new test with wrong indentation, pre-commit will not add it, we will forget and the world is sad.
prev = os.environ.get("TERM", "") | ||
os.environ["TERM"] = "dumb" | ||
# imported after TERM is set to act upon rich console. | ||
from anta.cli.get.commands import tests # noqa: E402 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we ok with using click functions in scripts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I would say yes - people developing should have click installed - thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should have a generic function called get_tests
or something that we can use here and in the tests
click function.
def print_tests_examples(qname: str, level: int, test_name: str | None, *, short: bool = False) -> None: | ||
"""Print tests in qname if matching test_name (or all if test_name is None. | ||
|
||
TODO: Allow to give a package argument to import_module. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unclear what that means?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The TODO. Is there a scenario where we could give a package argument for this use case? If not then TODO is not necessary.
Co-authored-by: Carl Baillargeon <[email protected]>
Co-authored-by: Carl Baillargeon <[email protected]>
Co-authored-by: Carl Baillargeon <[email protected]>
Co-authored-by: Carl Baillargeon <[email protected]>
for more information, see https://pre-commit.ci
Quality Gate passedIssues Measures |
Description
Fixes #326
Checklist:
pre-commit run
)tox -e testenv
)