******
verify
******
|version| |travis| |coveralls| |license|
Verify is a painless assertion library for Python.
Links
=====
- Project: https://github.com/dgilland/verify
- Documentation: http://verify.readthedocs.org
- PyPI: https://pypi.python.org/pypi/verify/
- TravisCI: https://travis-ci.org/dgilland/verify
Quickstart
==========
Install using pip:
::
pip install verify
Verify some value using multiple assertions:
.. code-block:: python
from verify import expect, Not, Truthy, Falsy, Less, Greater
expect(5 * 5,
Truthy(),
Not(Falsy),
Greater(15),
Less(30))
Verify using your own assert functions:
.. code-block:: python
def is_just_right(value):
assert value == 'just right', 'Not just right!'
# Passes
expect('just right', is_just_right)
# Fails
try:
expect('too cold', is_just_right)
except AssertionError:
raise
**NOTE:** The assert function should return a truthy value, otherwise, ``expect`` will treat the falsy return from the function as an indication that it failed and subsequently raise it's own ``AssertionError``.
Verify using your own predicate functions:
.. code-block:: python
def is_awesome(value):
return 'awesome' in value
def is_more_awesome(value):
return value > 'awesome'
expect('so awesome', is_awesome, is_more_awesome)
Verify using chaining syntax:
.. code-block:: python
expect(1).Truthy().Number().NotBoolean().Not(is_awesome)
Verify without ``expect`` since the ``verify`` assertions can be used on their own:
.. code-block:: python
import verify
# These would pass.
verify.Truthy(1)
verify.Equal(2, 2)
verify.Greater(3, 2)
# These would fail with an AssertionError
verify.Truthy(0)
verify.Equal(2, 3)
verify.Greater(2, 3)
If you'd prefer to see ``assert`` being used, all ``verify`` assertions will return ``True`` if no ``AssertionError`` is raised:
.. code-block:: python
assert Truthy(1)
assert expect(1, Truthy(), Number())
Multiple Syntax Styles
======================
There are several syntax styles available to help construct more natural sounding assertion chains.
Expect...To Be
--------------
Use ``expect`` with the ``to_be`` aliases. All Pascal case assertions have ``to_be_*`` and ``to_not_be_*`` prefixes (with a few expections).
.. code-block:: python
expect(something).to_be_int().to_be_less_or_equal(5).to_be_greater_or_equal(1)
expect(something_else).to_not_be_float().to_be_number()
Ensure...Is
-----------
Use ``ensure`` with ``is`` aliases. All Pascal case assertions have ``is_*`` and ``is_not_*`` prefixes (with a few expections).
.. code-block:: python
ensure(something).is_int().is_less_or_equal(5).is_greater_or_equal(1)
ensure(something_else).is_not_float().is_number()
Classical
---------
Use ``expect`` or ``ensure`` with the Pascal case assertions.
.. code-block:: python
ensure(something).Int().LessOrEqual(5).GreaterOrEqual(1)
expect(something_else).Float().Number()
**NOTE:** While it's suggested to not mix styles, each of the assertion syntaxes are available with both ``expect`` and ``ensure``. So you can call ``expect(..).is_int()`` as well as ``ensure(..).to_be_int()``.
Naming Convention Exceptions
----------------------------
As mentioned above, there are some assertions that have nonstandard aliases:
- ``Not``: ``not_``, ``does_not``, ``to_fail``, and ``fails``
- ``Predicate``: ``does``, ``to_pass``, and ``passes``
- ``All``: ``all_``, ``does_all``, and ``passes_all``
- ``NotAll``: ``not_all``, ``does_not_all``, and ``fails_all``
- ``Any``: ``any_``, ``does_any``, and ``passes_any``
- ``NotAny``: ``not_any``, ``does_not_any``, and ``fails_any``
- ``Match``: ``to_match``, ``is_match`` and ``matches``
- ``NotMatch``: ``to_not_match``, ``is_not_match`` and ``does_not_match``
- ``Is``: ``to_be`` and ``is_``
- ``Contains``: ``to_contain`` and ``contains``
- ``NotContains``: ``to_not_contain`` and ``does_not_contain``
- ``ContainsOnly``: ``to_contain_only`` and ``contains_only``
- ``NotContainsOnly``: ``to_not_contain_only`` and ``does_not_contain_only``
- ``Length``: ``to_have_length`` and ``has_length``
- ``NotLength``: ``to_not_have_length`` and ``does_not_have_length``
Validators
==========
All of the validators in ``verify`` are callables that can be used in two contexts:
1. By themselves as in ``Equal(a, b)`` which will raise an ``AssertionError`` if false.
2. In combination with ``expect`` as in ``expect(a, Equal(b))`` which could also raise an ``AssertionError``.
The available validators are:
=================================== ===========
Validator Description
=================================== ===========
``Truthy`` Assert that ``bool(a)``.
``Falsy`` Assert that ``not bool(a)``.
``Not`` Assert that a callable doesn't raise an ``AssertionError``.
``Predicate`` Assert that ``predicate(a)``.
``All`` Assert that all of the list of predicates evaluate ``a`` as truthy.
``NotAll`` Assert ``not All``.
``Any`` Assert that any of the list of predicates evaluate ``a`` as truthy.
``NotAny`` Assert ``not Any``.
``Equal`` Assert that ``a == b``.
``NotEqual`` Assert ``not Equal``.
``Match`` Assert that ``a`` matches regular expression ``b``.
``NotMatch`` Assert ``not Match``.
``Is`` Assert that ``a is b``.
``IsNot`` Assert ``not Is``.
``IsTrue`` Assert that ``a is True``.
``IsNotTrue`` Assert ``not IsTrue``.
``IsFalse`` Assert that ``a is False``.
``IsNotFalse`` Assert ``not IsFalse``.
``IsNone`` Assert that ``a is None``.
``IsNotNone`` Assert ``not IsNone``.
``Type`` Assert that ``isinstance(a, b)``.
``NotType`` Assert ``not Type``.
``Boolean`` Assert that ``isinstance(a, bool)``.
``NotBoolean`` Assert ``not Boolean``.
``String`` Assert that ``isinstance(a, (str, unicode))``.
``NotString`` Assert ``not String``.
``Dict`` Assert that ``isinstance(a, dict)``.
``NotDict`` Assert ``not Dict``.
``List`` Assert that ``isinstance(a, list)``.
``NotList`` Assert ``not List``.
``Tuple`` Assert that ``isinstance(a, tuple)``.
``NotTuple`` Assert ``not Tuple``.
``Date`` Assert that ``isinstance(a, datetime.date)``.
``NotDate`` Assert ``not Date``.
``DateString`` Assert that ``a`` matches the datetime format string ``b``.
``NotDateString`` Assert ``not DateString``.
``Int`` Assert that ``isinstance(a, int)``.
``NotInt`` Assert ``not Int``.
``Float`` Assert that ``isinstance(a, float)``.
``NotFloat`` Assert ``not Float``.
``Number`` Assert that ``isinstance(a, (int, float, Decimal, long))``.
``NotNumber`` Assert ``not Number``.
``In`` Assert that ``a in b``.
``NotIn`` Assert ``not In``.
``Contains`` Assert that ``b in a``.
``NotContains`` Assert ``not Contains``.
``ContainsOnly`` Assert that values from ``b`` are the only ones contained in ``a``.
``NotContainsOnly`` Assert ``not ContainsOnly``.
``Subset`` Assert that ``a`` is a subset of ``b``.
``NotSubset`` Assert ``not Subset``.
``Superset`` Assert that ``a`` is a superset of ``b``.
``NotSuperset`` Assert ``not Superset``.
``Unique`` Assert that ``a`` contains unique items.
``NotUnique`` Assert ``not Unique``.
``Length`` Assert that ``b <= len(a) <= c``.
``NotLength`` Assert that ``not Length``.
``Greater``/``GreaterThan`` Assert that ``a > b``.
``GreaterEqual``/``GreaterOrEqual`` Assert that ``a >= b``.
``Less``/``LessThan`` Assert that ``a < b``.
``LessEqual``/``LessOrEqual`` Assert that ``a <= b``.
``Between`` Assert that ``b <= a <= c``.
``NotBetween`` Assert ``not Between``.
``Positive`` Assert that ``a > 0``.
``Negative`` Assert that ``a < 0``.
``Even`` Assert that ``a % 2 == 0``.
``Odd`` Assert that ``a % 2 != 1``.
``Monotone`` Assert that ``a`` is monotonic with respect to ``b()``.
``Increasing`` Assert that ``a`` is monotonically increasing.
``StrictlyIncreasing`` Assert that ``a`` is strictly increasing.
``Decreasing`` Assert that ``a`` is monotonically decreasing.
``StrictlyDecreasing`` Assert that ``a`` is strictly decreasing.
=================================== ===========
For more details, please see the full documentation at http://verify.readthedocs.org.
.. |version| image:: https://img.shields.io/pypi/v/verify.svg?style=flat-square
:target: https://pypi.python.org/pypi/verify/
.. |travis| image:: https://img.shields.io/travis/dgilland/verify/master.svg?style=flat-square
:target: https://travis-ci.org/dgilland/verify
.. |coveralls| image:: https://img.shields.io/coveralls/dgilland/verify/master.svg?style=flat-square
:target: https://coveralls.io/r/dgilland/verify
.. |license| image:: https://img.shields.io/pypi/l/verify.svg?style=flat-square
:target: https://pypi.python.org/pypi/verify/
Raw data
{
"_id": null,
"home_page": "https://github.com/dgilland/verify",
"name": "verify",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "test testing assert assertion validation unittest",
"author": "Derrick Gilland",
"author_email": "dgilland@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/e0/eb/67f0d115dec1cba8e1371eb5d13d87e7cf277572b90a9b9fdaa2682ea706/verify-1.1.1.tar.gz",
"platform": "UNKNOWN",
"description": "******\nverify\n******\n\n|version| |travis| |coveralls| |license|\n\nVerify is a painless assertion library for Python.\n\n\nLinks\n=====\n\n- Project: https://github.com/dgilland/verify\n- Documentation: http://verify.readthedocs.org\n- PyPI: https://pypi.python.org/pypi/verify/\n- TravisCI: https://travis-ci.org/dgilland/verify\n\n\nQuickstart\n==========\n\nInstall using pip:\n\n\n::\n\n pip install verify\n\n\nVerify some value using multiple assertions:\n\n\n.. code-block:: python\n\n from verify import expect, Not, Truthy, Falsy, Less, Greater\n\n expect(5 * 5,\n Truthy(),\n Not(Falsy),\n Greater(15),\n Less(30))\n\n\nVerify using your own assert functions:\n\n\n.. code-block:: python\n\n def is_just_right(value):\n assert value == 'just right', 'Not just right!'\n\n # Passes\n expect('just right', is_just_right)\n\n # Fails\n try:\n expect('too cold', is_just_right)\n except AssertionError:\n raise\n\n**NOTE:** The assert function should return a truthy value, otherwise, ``expect`` will treat the falsy return from the function as an indication that it failed and subsequently raise it's own ``AssertionError``.\n\n\nVerify using your own predicate functions:\n\n\n.. code-block:: python\n\n def is_awesome(value):\n return 'awesome' in value\n\n def is_more_awesome(value):\n return value > 'awesome'\n\n expect('so awesome', is_awesome, is_more_awesome)\n\n\nVerify using chaining syntax:\n\n\n.. code-block:: python\n\n expect(1).Truthy().Number().NotBoolean().Not(is_awesome)\n\n\nVerify without ``expect`` since the ``verify`` assertions can be used on their own:\n\n\n.. code-block:: python\n\n import verify\n\n # These would pass.\n verify.Truthy(1)\n verify.Equal(2, 2)\n verify.Greater(3, 2)\n\n # These would fail with an AssertionError\n verify.Truthy(0)\n verify.Equal(2, 3)\n verify.Greater(2, 3)\n\n\nIf you'd prefer to see ``assert`` being used, all ``verify`` assertions will return ``True`` if no ``AssertionError`` is raised:\n\n\n.. code-block:: python\n\n assert Truthy(1)\n assert expect(1, Truthy(), Number())\n\n\nMultiple Syntax Styles\n======================\n\nThere are several syntax styles available to help construct more natural sounding assertion chains.\n\n\nExpect...To Be\n--------------\n\nUse ``expect`` with the ``to_be`` aliases. All Pascal case assertions have ``to_be_*`` and ``to_not_be_*`` prefixes (with a few expections).\n\n.. code-block:: python\n\n expect(something).to_be_int().to_be_less_or_equal(5).to_be_greater_or_equal(1)\n expect(something_else).to_not_be_float().to_be_number()\n\n\nEnsure...Is\n-----------\n\nUse ``ensure`` with ``is`` aliases. All Pascal case assertions have ``is_*`` and ``is_not_*`` prefixes (with a few expections).\n\n\n.. code-block:: python\n\n ensure(something).is_int().is_less_or_equal(5).is_greater_or_equal(1)\n ensure(something_else).is_not_float().is_number()\n\n\nClassical\n---------\n\nUse ``expect`` or ``ensure`` with the Pascal case assertions.\n\n.. code-block:: python\n\n ensure(something).Int().LessOrEqual(5).GreaterOrEqual(1)\n expect(something_else).Float().Number()\n\n\n**NOTE:** While it's suggested to not mix styles, each of the assertion syntaxes are available with both ``expect`` and ``ensure``. So you can call ``expect(..).is_int()`` as well as ``ensure(..).to_be_int()``.\n\n\nNaming Convention Exceptions\n----------------------------\n\nAs mentioned above, there are some assertions that have nonstandard aliases:\n\n- ``Not``: ``not_``, ``does_not``, ``to_fail``, and ``fails``\n- ``Predicate``: ``does``, ``to_pass``, and ``passes``\n- ``All``: ``all_``, ``does_all``, and ``passes_all``\n- ``NotAll``: ``not_all``, ``does_not_all``, and ``fails_all``\n- ``Any``: ``any_``, ``does_any``, and ``passes_any``\n- ``NotAny``: ``not_any``, ``does_not_any``, and ``fails_any``\n- ``Match``: ``to_match``, ``is_match`` and ``matches``\n- ``NotMatch``: ``to_not_match``, ``is_not_match`` and ``does_not_match``\n- ``Is``: ``to_be`` and ``is_``\n- ``Contains``: ``to_contain`` and ``contains``\n- ``NotContains``: ``to_not_contain`` and ``does_not_contain``\n- ``ContainsOnly``: ``to_contain_only`` and ``contains_only``\n- ``NotContainsOnly``: ``to_not_contain_only`` and ``does_not_contain_only``\n- ``Length``: ``to_have_length`` and ``has_length``\n- ``NotLength``: ``to_not_have_length`` and ``does_not_have_length``\n\n\nValidators\n==========\n\nAll of the validators in ``verify`` are callables that can be used in two contexts:\n\n1. By themselves as in ``Equal(a, b)`` which will raise an ``AssertionError`` if false.\n2. In combination with ``expect`` as in ``expect(a, Equal(b))`` which could also raise an ``AssertionError``.\n\nThe available validators are:\n\n=================================== ===========\nValidator Description\n=================================== ===========\n``Truthy`` Assert that ``bool(a)``.\n``Falsy`` Assert that ``not bool(a)``.\n``Not`` Assert that a callable doesn't raise an ``AssertionError``.\n``Predicate`` Assert that ``predicate(a)``.\n``All`` Assert that all of the list of predicates evaluate ``a`` as truthy.\n``NotAll`` Assert ``not All``.\n``Any`` Assert that any of the list of predicates evaluate ``a`` as truthy.\n``NotAny`` Assert ``not Any``.\n``Equal`` Assert that ``a == b``.\n``NotEqual`` Assert ``not Equal``.\n``Match`` Assert that ``a`` matches regular expression ``b``.\n``NotMatch`` Assert ``not Match``.\n``Is`` Assert that ``a is b``.\n``IsNot`` Assert ``not Is``.\n``IsTrue`` Assert that ``a is True``.\n``IsNotTrue`` Assert ``not IsTrue``.\n``IsFalse`` Assert that ``a is False``.\n``IsNotFalse`` Assert ``not IsFalse``.\n``IsNone`` Assert that ``a is None``.\n``IsNotNone`` Assert ``not IsNone``.\n``Type`` Assert that ``isinstance(a, b)``.\n``NotType`` Assert ``not Type``.\n``Boolean`` Assert that ``isinstance(a, bool)``.\n``NotBoolean`` Assert ``not Boolean``.\n``String`` Assert that ``isinstance(a, (str, unicode))``.\n``NotString`` Assert ``not String``.\n``Dict`` Assert that ``isinstance(a, dict)``.\n``NotDict`` Assert ``not Dict``.\n``List`` Assert that ``isinstance(a, list)``.\n``NotList`` Assert ``not List``.\n``Tuple`` Assert that ``isinstance(a, tuple)``.\n``NotTuple`` Assert ``not Tuple``.\n``Date`` Assert that ``isinstance(a, datetime.date)``.\n``NotDate`` Assert ``not Date``.\n``DateString`` Assert that ``a`` matches the datetime format string ``b``.\n``NotDateString`` Assert ``not DateString``.\n``Int`` Assert that ``isinstance(a, int)``.\n``NotInt`` Assert ``not Int``.\n``Float`` Assert that ``isinstance(a, float)``.\n``NotFloat`` Assert ``not Float``.\n``Number`` Assert that ``isinstance(a, (int, float, Decimal, long))``.\n``NotNumber`` Assert ``not Number``.\n``In`` Assert that ``a in b``.\n``NotIn`` Assert ``not In``.\n``Contains`` Assert that ``b in a``.\n``NotContains`` Assert ``not Contains``.\n``ContainsOnly`` Assert that values from ``b`` are the only ones contained in ``a``.\n``NotContainsOnly`` Assert ``not ContainsOnly``.\n``Subset`` Assert that ``a`` is a subset of ``b``.\n``NotSubset`` Assert ``not Subset``.\n``Superset`` Assert that ``a`` is a superset of ``b``.\n``NotSuperset`` Assert ``not Superset``.\n``Unique`` Assert that ``a`` contains unique items.\n``NotUnique`` Assert ``not Unique``.\n``Length`` Assert that ``b <= len(a) <= c``.\n``NotLength`` Assert that ``not Length``.\n``Greater``/``GreaterThan`` Assert that ``a > b``.\n``GreaterEqual``/``GreaterOrEqual`` Assert that ``a >= b``.\n``Less``/``LessThan`` Assert that ``a < b``.\n``LessEqual``/``LessOrEqual`` Assert that ``a <= b``.\n``Between`` Assert that ``b <= a <= c``.\n``NotBetween`` Assert ``not Between``.\n``Positive`` Assert that ``a > 0``.\n``Negative`` Assert that ``a < 0``.\n``Even`` Assert that ``a % 2 == 0``.\n``Odd`` Assert that ``a % 2 != 1``.\n``Monotone`` Assert that ``a`` is monotonic with respect to ``b()``.\n``Increasing`` Assert that ``a`` is monotonically increasing.\n``StrictlyIncreasing`` Assert that ``a`` is strictly increasing.\n``Decreasing`` Assert that ``a`` is monotonically decreasing.\n``StrictlyDecreasing`` Assert that ``a`` is strictly decreasing.\n=================================== ===========\n\n\nFor more details, please see the full documentation at http://verify.readthedocs.org.\n\n\n.. |version| image:: https://img.shields.io/pypi/v/verify.svg?style=flat-square\n :target: https://pypi.python.org/pypi/verify/\n\n.. |travis| image:: https://img.shields.io/travis/dgilland/verify/master.svg?style=flat-square\n :target: https://travis-ci.org/dgilland/verify\n\n.. |coveralls| image:: https://img.shields.io/coveralls/dgilland/verify/master.svg?style=flat-square\n :target: https://coveralls.io/r/dgilland/verify\n\n.. |license| image:: https://img.shields.io/pypi/l/verify.svg?style=flat-square\n :target: https://pypi.python.org/pypi/verify/",
"bugtrack_url": null,
"license": "MIT License",
"summary": "A painless assertion and validation library for Python.",
"version": "1.1.1",
"split_keywords": [
"test",
"testing",
"assert",
"assertion",
"validation",
"unittest"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "ac966f3956cafdb0ae4659adef580905",
"sha256": "87b8ea7db88ae8006db3aff27cff6159301168aea99fc7ca73938249fe12e3bb"
},
"downloads": -1,
"filename": "verify-1.1.1-py2-none-any.whl",
"has_sig": false,
"md5_digest": "ac966f3956cafdb0ae4659adef580905",
"packagetype": "bdist_wheel",
"python_version": "py2",
"requires_python": null,
"size": 20898,
"upload_time": "2017-05-09T15:30:54",
"upload_time_iso_8601": "2017-05-09T15:30:54.742516Z",
"url": "https://files.pythonhosted.org/packages/08/96/06d3be3705f43e4c30261ae8bf9577b4594163d8ff53f77f46be9d497a29/verify-1.1.1-py2-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "18dbf41b66ee20eb0ea7c4a1339a962e",
"sha256": "a64b55d6a51c9395defdaa4a9a5efa917241bd944c7a8f63500775820b72ca75"
},
"downloads": -1,
"filename": "verify-1.1.1.tar.gz",
"has_sig": false,
"md5_digest": "18dbf41b66ee20eb0ea7c4a1339a962e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 17617,
"upload_time": "2017-05-09T15:30:56",
"upload_time_iso_8601": "2017-05-09T15:30:56.749977Z",
"url": "https://files.pythonhosted.org/packages/e0/eb/67f0d115dec1cba8e1371eb5d13d87e7cf277572b90a9b9fdaa2682ea706/verify-1.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2017-05-09 15:30:56",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "dgilland",
"github_project": "verify",
"travis_ci": true,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "astroid",
"specs": [
[
"==",
"1.3.6"
]
]
},
{
"name": "pep8",
"specs": [
[
"==",
"1.6.2"
]
]
},
{
"name": "pip-tools",
"specs": [
[
"==",
"0.3.6"
]
]
},
{
"name": "pydash",
"specs": [
[
">=",
"4.0.3"
]
]
},
{
"name": "pylint",
"specs": [
[
"==",
"1.4.3"
]
]
},
{
"name": "pytest-cov",
"specs": [
[
"==",
"1.8.1"
]
]
},
{
"name": "pytest",
"specs": [
[
"==",
"2.7.0"
]
]
},
{
"name": "Sphinx",
"specs": [
[
"==",
"1.3.1"
]
]
},
{
"name": "tox",
"specs": [
[
"==",
"1.9.2"
]
]
},
{
"name": "twine",
"specs": [
[
"==",
"1.5.0"
]
]
},
{
"name": "wheel",
"specs": [
[
"==",
"0.24.0"
]
]
}
],
"tox": true,
"lcname": "verify"
}