Skip to content

Commit

Permalink
Fix validators __all__ (#517)
Browse files Browse the repository at this point in the history
* add new validators from #425 to validators.__all__

* add test for each validator, verifying that it is in validators.__all__

* add changelog entry for #517

* apply autolinting

* Make module path absolute
  • Loading branch information
mattsb42-aws authored and hynek committed Mar 13, 2019
1 parent 4fe2896 commit 957b198
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/517.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated ``attr.validators.__all__`` to include new validators added in `#425 <https:/python-attrs/attrs/pull/425>`_.
11 changes: 10 additions & 1 deletion src/attr/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@
from ._make import _AndValidator, and_, attrib, attrs


__all__ = ["and_", "in_", "instance_of", "optional", "provides"]
__all__ = [
"and_",
"deep_iterable",
"deep_mapping",
"in_",
"instance_of",
"is_callable",
"optional",
"provides",
]


@attrs(repr=False, slots=True, hash=True)
Expand Down
48 changes: 48 additions & 0 deletions tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ class TestInstanceOf(object):
Tests for `instance_of`.
"""

def test_in_all(self):
"""
Verify that this validator is in ``__all__``.
"""
assert instance_of.__name__ in validator_module.__all__

def test_success(self):
"""
Nothing happens if types match.
Expand Down Expand Up @@ -86,6 +92,12 @@ def always_fail(_, __, ___):


class TestAnd(object):
def test_in_all(self):
"""
Verify that this validator is in ``__all__``.
"""
assert and_.__name__ in validator_module.__all__

def test_success(self):
"""
Succeeds if all wrapped validators succeed.
Expand Down Expand Up @@ -132,6 +144,12 @@ class TestProvides(object):
Tests for `provides`.
"""

def test_in_all(self):
"""
Verify that this validator is in ``__all__``.
"""
assert provides.__name__ in validator_module.__all__

def test_success(self):
"""
Nothing happens if value provides requested interface.
Expand Down Expand Up @@ -184,6 +202,12 @@ class TestOptional(object):
Tests for `optional`.
"""

def test_in_all(self, validator):
"""
Verify that this validator is in ``__all__``.
"""
assert optional.__name__ in validator_module.__all__

def test_success(self, validator):
"""
Nothing happens if validator succeeds.
Expand Down Expand Up @@ -239,6 +263,12 @@ class TestIn_(object):
Tests for `in_`.
"""

def test_in_all(self):
"""
Verify that this validator is in ``__all__``.
"""
assert in_.__name__ in validator_module.__all__

def test_success_with_value(self):
"""
If the value is in our options, nothing happens.
Expand Down Expand Up @@ -281,6 +311,12 @@ class TestDeepIterable(object):
Tests for `deep_iterable`.
"""

def test_in_all(self):
"""
Verify that this validator is in ``__all__``.
"""
assert deep_iterable.__name__ in validator_module.__all__

def test_success_member_only(self):
"""
If the member validator succeeds and the iterable validator is not set,
Expand Down Expand Up @@ -395,6 +431,12 @@ class TestDeepMapping(object):
Tests for `deep_mapping`.
"""

def test_in_all(self):
"""
Verify that this validator is in ``__all__``.
"""
assert deep_mapping.__name__ in validator_module.__all__

def test_success(self):
"""
If both the key and value validators succeed, nothing happens.
Expand Down Expand Up @@ -485,6 +527,12 @@ class TestIsCallable(object):
Tests for `is_callable`.
"""

def test_in_all(self):
"""
Verify that this validator is in ``__all__``.
"""
assert is_callable.__name__ in validator_module.__all__

def test_success(self):
"""
If the value is callable, nothing happens.
Expand Down

0 comments on commit 957b198

Please sign in to comment.