Skip to content

Commit

Permalink
Add NotBetween, IsNot, IsNotTrue, IsNotFalse, and IsNotNone.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgilland committed May 12, 2015
1 parent 72db257 commit 1b56c1a
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Expand Up @@ -6,6 +6,11 @@ Changelog

- Add ``NotEqual``.
- Add ``NotMatch``.
- Add ``NotBetween``.
- Add ``IsNot``.
- Add ``IsNotTrue``.
- Add ``IsNotFalse``.
- Add ``IsNotNone``.
- Add ``NotAll``.
- Add ``NotAny``.
- Add ``NotIn``.
Expand Down
5 changes: 5 additions & 0 deletions docs/api.rst
Expand Up @@ -140,6 +140,11 @@ Below are the various assertion classes that can be used for validation.
.. autoclass:: verify.StrictlyDecreasing
.. autoclass:: verify.NotEqual
.. autoclass:: verify.NotMatch
.. autoclass:: verify.NotBetween
.. autoclass:: verify.IsNot
.. autoclass:: verify.IsNotTrue
.. autoclass:: verify.IsNotFalse
.. autoclass:: verify.IsNotNone
.. autoclass:: verify.NotAll
.. autoclass:: verify.NotAny
.. autoclass:: verify.NotIn
Expand Down
33 changes: 33 additions & 0 deletions tests/test_verify.py
Expand Up @@ -185,6 +185,23 @@ def test_expect_predicates_raises(value, predicates):
(v.NotMatch, '###', Arg(r'\w+')),
(v.NotMatch, '###', Arg(re.compile(r'\w+'))),
(v.NotMatch, 1, Arg(r'\w+')),
(v.NotBetween, 5, Arg(4)),
(v.NotBetween, 5, Arg((1, 4))),
(v.NotBetween, 5, Arg(min=1, max=4)),
(v.IsNot, 1, Arg(2)),
(v.IsNot, 1, Arg(True)),
(v.IsNot, 0, Arg(False)),
(v.IsNot, 'a', Arg('b')),
(v.IsNotTrue, False, Arg()),
(v.IsNotTrue, None, Arg()),
(v.IsNotTrue, 0, Arg()),
(v.IsNotTrue, '', Arg()),
(v.IsNotFalse, True, Arg()),
(v.IsNotFalse, 1, Arg()),
(v.IsNotFalse, 'verify', Arg()),
(v.IsNotNone, True, Arg()),
(v.IsNotNone, 1, Arg()),
(v.IsNotNone, 'verify', Arg()),
(v.NotAll, True, Arg([pydash.is_boolean, pydash.is_number])),
(v.NotAny, True, Arg([pydash.is_none, pydash.is_number])),
(v.NotIn, 1, Arg([0, 0, 2])),
Expand Down Expand Up @@ -373,6 +390,22 @@ def test_assert_method(meth, value, arg):
(v.NotEqual, 'abc', Arg('abc')),
(v.NotMatch, 'abc', Arg(r'\w+')),
(v.NotMatch, 'abc', Arg(re.compile(r'\w+'))),
(v.NotBetween, 5, Arg((4, 5))),
(v.NotBetween, 5, Arg((None, 5))),
(v.NotBetween, 5, Arg((5, None))),
(v.NotBetween, 5, Arg((5, 5))),
(v.NotBetween, 5, Arg(6)),
(v.NotBetween, 5, Arg(min=4, max=6)),
(v.NotBetween, 5, Arg(min=4)),
(v.NotBetween, 5, Arg(max=6)),
(v.IsNot, True, Arg(True)),
(v.IsNot, False, Arg(False)),
(v.IsNot, None, Arg(None)),
(v.IsNot, 1, Arg(1)),
(v.IsNot, 'a', Arg('a')),
(v.IsNotTrue, True, Arg()),
(v.IsNotFalse, False, Arg()),
(v.IsNotNone, None, Arg()),
(v.NotAll, True, Arg([pydash.is_boolean, pydash.is_nan])),
(v.NotAny, True, Arg([pydash.is_boolean, pydash.is_number])),
(v.NotIn, 1, Arg([0, 1, 2])),
Expand Down
80 changes: 80 additions & 0 deletions verify/__init__.py
Expand Up @@ -68,6 +68,11 @@
'StrictlyDecreasing',
'NotEqual',
'NotMatch',
'NotBetween',
'IsNot',
'IsNotTrue',
'IsNotFalse',
'IsNotNone',
'NotAll',
'NotAny',
'NotIn',
Expand Down Expand Up @@ -1164,6 +1169,81 @@ class NotMatch(Negate, Match):
reason = '{0} matches the regular expression {comparable}'


class NotBetween(Negate, Between):
"""Asserts that `value` is not between `min` and `max` inclusively.
Returns:
bool: ``True`` if comparison passes, otherwise, an ``AssertionError``
is raised.
Raises:
AssertionError: If comparison returns ``False``.
.. versionadded:: 0.5.0
"""
reason = '{0} is between {min} and {max}'


class IsNot(Negate, Is):
"""Asserts that `value` is not `comparable`.
Returns:
bool: ``True`` if comparison passes, otherwise, an ``AssertionError``
is raised.
Raises:
AssertionError: If comparison returns ``False``.
.. versionadded:: 0.5.0
"""
reason = '{0} is {comparable}'


class IsNotTrue(Negate, IsTrue):
"""Asserts that `value` is not ``True``.
Returns:
bool: ``True`` if comparison passes, otherwise, an ``AssertionError``
is raised.
Raises:
AssertionError: If comparison returns ``False``.
.. versionadded:: 0.5.0
"""
reason = '{0} is True'


class IsNotFalse(Negate, IsFalse):
"""Asserts that `value` is not ``False``.
Returns:
bool: ``True`` if comparison passes, otherwise, an ``AssertionError``
is raised.
Raises:
AssertionError: If comparison returns ``False``.
.. versionadded:: 0.5.0
"""
reason = '{0} is False'


class IsNotNone(Negate, IsNone):
"""Asserts that `value` is not ``None``.
Returns:
bool: ``True`` if comparison passes, otherwise, an ``AssertionError``
is raised.
Raises:
AssertionError: If comparison returns ``False``.
.. versionadded:: 0.5.0
"""
reason = '{0} is None'


class NotAll(Negate, All):
"""Asserts that `value` evaluates as falsy for **all** predicates in
`comparable`.
Expand Down

0 comments on commit 1b56c1a

Please sign in to comment.