-
Notifications
You must be signed in to change notification settings - Fork 23
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)!: Introduce AntaTest.Input and AntaTest.render() #315
Conversation
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.
on the principle it looks very good to me :) - would be nice to see the rendered documentaiton and if we can do something for the test inputs in mkdocs to make them nicely presented!
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
4924742
to
12f0b22
Compare
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. |
1d9477c
to
5a01d50
Compare
Conflicts have been resolved. A maintainer will review the pull request shortly. |
Seems a is missing in the PR Error reproduced in both:
Error message
Repository structure |
4a03bd5
to
5e86c02
Compare
Conflicts have been resolved. A maintainer will review the pull request shortly. |
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.
let's ship it !
Goal
a) Define test inputs in a single place (template parameters should not be exposed to test users)
b) Provide better documentation for inputs
AntaTest.Input
model)Anta.Test.render()
user codeAnta.Test.collect()
AntaTest.test()
user codeChanges
AntaTest.Input
class.BaseModel
to define test inputs.AntaTest
methods using the instance attributeself.inputs
.AntaTest.render(template: AntaTemplate) -> list[AntaCommand]
methodAntaTest.template
class attribute.AntaTemplate
instance inAntaTest.commands
class attribute,AntaTest.render()
will be called.How to test
VerifyBGPIPv4UnicastCount
andVerifyReachability
has been implemented to support the newAntaTest
definition.Use the following test catalog:
Design notes/ideas
AntaTest.instance_commands
is a flatten list. This has the advantage to be a simple data structure but test developers need to deal with indexes instead of keys.["test_class", "inputs", "eos_data", "expected_result", "expected_messages"]
ValidationError
ofAntaTest.Input
models by usingValidationError.errors()
instead ofValidationError.__str__()
. Related question: is it necessary to test inputs validation as this is already implemented/tested in pydantic ?render()
in the constructor and more generally skip the instanciation ofinstance_commands
attribute. However, the user can still call other methods of AntaTest likecollect()
or get some properties from the AntaTest object even if it does not make sense. We should implement an Exception for those cases.Caveats
# mypy: disable-error-code=attr-defined
is required in the user test file definition because mypy does not manage to get theAntaTest.Input
implementation inAntaTest
subclasses:AntaTest.Input
is an abstract class and can be implemented inAntaTest
subclasses.self.inputs
is an instance attribute allocated in theAntaTest
constructor. When usingself.inputs
inAntaTest
subclasses, mypy thinksAntaTest.Input
typing is defined inAntaTest
and not its subclasses.TypedDict
as a pydantic type, there are caveats with Python 3.8: https://docs.pydantic.dev/2.0/usage/types/dicts_mapping/#typeddictTODO
anta.tests
AntaTest
behaviour