-
Notifications
You must be signed in to change notification settings - Fork 218
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
Adding SomeOf validator #314
Conversation
voluptuous/validators.py
Outdated
class SomeOf(object): | ||
"""Value must pass at least some validations, determined by the given parameter | ||
|
||
The output of each validator is passed as input to the next. |
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.
description will be improved in the next update of this PR (I'm sure there will be so I'm waiting with pushing it 😄 )
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.
Haha.. Let's not rely on it.
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.
Will push it asap
Is this repository not active anymore? |
Hey @guyarad I was busy over the weekends. Will review it and get back to you. Before my review, please fix the failing tests. Thanks. |
@tusharmakkar08 no rush - just wanted to know how active we are 😊 the failing tests aren't mine. they seem to exist after the last commit to master. |
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.
Please look into the comments.
voluptuous/validators.py
Outdated
""" | ||
|
||
def __init__(self, min_valid, validators, max_valid=None, **kwargs): | ||
self.min_valid = min_valid or 0 |
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 min_valid
is not a default keyword argument while max_valid
is?
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.
Originally I only needed "minimum valid schemas" and just added "max valid" for completeness. So for me, min_valid was always needed. We can put them both as optional, and assert that either of them has a value (otherwise, what's the point of this validator).
Sounds good?
.python-version
Outdated
3.6.3 | ||
3.3.6 | ||
3.4.7 | ||
3.5.2 |
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.
this file was accidentally added because I was working with pyenv
which proved to be very useful for testing locally with multiple python versions.
I was going to remove it, but then thought it would be a good to have such convention as repository users, to use pyenv. your call.
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.
@alecthomas What do you think about adding this to the package?
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 remove this for now and create an issue where we will continue this discussion.
voluptuous/tests/tests.py
Outdated
validator('3A34SDEF5') | ||
|
||
|
||
def test_SomeOf_max_validation(): |
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 add a test for checking the assert statement too using AssertionError
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.
Done
.python-version
Outdated
3.6.3 | ||
3.3.6 | ||
3.4.7 | ||
3.5.2 |
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.
@alecthomas What do you think about adding this to the package?
The SomeOf validator can verify that some of validators are met, or optionally at most number of validators.