Skip to main content

A painless assertion and validation library for Python.

Project description

version travis coveralls license

Verify is a painless assertion library for Python.

Quickstart

Install using pip:

pip install verify

Verify some value using multiple assertions:

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:

def is_just_right(value):
    assert value != 'too cold' and value != 'too hot', 'Not just right!'

# Passes
expect(25, is_just_right)

# Fails
try:
    expect(31, is_just_right)
expect AssertionError:
    raise

Or your own predicate functions:

def is_awesome(value):
    return 'awesome' in value

def is_more_awesome(value):
    return value > 'awesome'

expect('so awesome', is_awesome, is_more_awesome)

But you don’t have to use expect since the verify assertions can be used on their own:

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)

And if you’d prefer to see assert being used, all verify assertions will return True if no AssertionError is raised:

assert Truthy(1)
assert Expect(1, Truthy(), Number())

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

Not

Assert that a callable doesn’t raise an AssertionError.

Predicate

Assert that predicate(a) (predicate() should return a boolean).

Equal

Assert that a == b.

Match

Assert that a matches regular expression b.

Greater

Assert that a > b.

GreaterEqual

Assert that a >= b.

Less

Assert that a < b.

LessEqual

Assert that a <= b.

Between

Assert that b <= a <= c.

Length

Assert that b <= len(a) <= c.

Is

Assert that a is b.

IsTrue

Assert that a is True.

IsFalse

Assert that a is False.

IsNone

Assert that a is None.

All

Assert that all of the list of predicates evaluate a as truthy.

Any

Assert that any of the list of predicates evaluate a as truthy.

In

Assert that a in b.

Contains

Assert that b in a.

ContainsOnly

Assert that values from b are the only ones contained in a.

Subset

Assert that a is a subset of b.

Superset

Assert that a is a superset of b.

Unique

Assert that a contains unique items.

InstanceOf

Assert that isinstance(a, b).

Truthy

Assert that bool(a).

Falsy

Assert that not bool(a).

Boolean

Assert that isinstance(a, bool).

String

Assert that isinstance(a, (str, unicode)).

Dict

Assert that isinstance(a, dict).

List

Assert that isinstance(a, list).

Tuple

Assert that isinstance(a, tuple).

Int

Assert that isinstance(a, int).

Float

Assert that isinstance(a, float).

Number

Assert that isinstance(a, (int, float, Decimal, long)).

NotNumber

Assert that not isinstance(a, (int, float, Decimal, long)).

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.

Date

Assert that isinstance(a, datetime.date).

DateString

Assert that a matches the datetime format string b.

NotEqual

Assert not Equal.

NotMatch

Assert not Match.

NotBetween

Assert not Between.

IsNot

Assert not Is.

IsNotTrue

Assert not Istrue.

IsNotFalse

Assert not IsFalse.

IsNotNone

Assert not IsNone.

NotAll

Assert not All.

NotAny

Assert not Any.

NotIn

Assert not In.

NotContains

Assert not Contains.

NotContainsOnly

Assert not ContainsOnly.

NotSubset

Assert not Subset.

NotSuperset

Assert not Superset.

NotUnique

Assert not Unique.

NotInstanceOf

Assert not InstanceOf.

NotBoolean

Assert not Boolean.

NotString

Assert not String.

NotDict

Assert not Dict.

NotList

Assert not List.

NotTuple

Assert not Tuple.

NotDate

Assert not Date.

NotDateString

Assert not DateString.

NotInt

Assert not Int.

NotFloat

Assert not Float.

NotNumber

Assert not Number.

For more details, please see the full documentation at http://verify.readthedocs.org.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

verify-0.5.0.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

verify-0.5.0-py2.py3-none-any.whl (11.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file verify-0.5.0.tar.gz.

File metadata

  • Download URL: verify-0.5.0.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for verify-0.5.0.tar.gz
Algorithm Hash digest
SHA256 2852de0f7c6c2922300b947c86c5a4d58d73f12fe009b07d2b584bd5c7833f64
MD5 8d916aa00e388713e7273327b50b34ba
BLAKE2b-256 406c4bf051c5e448d6ef9f79a6a55da75764018d64a00940cf0a7d534e0e4c79

See more details on using hashes here.

File details

Details for the file verify-0.5.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for verify-0.5.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9c4f1064411ceea114382bba9cbfa3ea823d9da8c0dc2f9ec44e8fe2a6351da1
MD5 6602648700274bb2ff96685b1ad531db
BLAKE2b-256 e82b6271f7630533dbd9e26c14db888ebb6973614779386d50eaf5357fcdea43

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page