I've started a new Python project: verify
Verify is billed as
A painless assertion and validation library for Python
Why make this when similar libraries already exist? Simply, I wanted a library with the following features:
- All objects raise an AssertionError when invalid.
- Ability to easily apply multiple assertions to a single value either via method chaining or passing multiple arguments to an assertion runner function.
- Simple callables as assertions.
- Support for using external predicate functions for validation.
Using verify is simple:
import verify as v # These will pass. v.expect(5 * 5, v.Truthy(), v.Greater(15), v.Less(30)) v.Truthy(1) v.Equal(2, 2) v.Greater(3, 2) # These will fail with an AssertionError v.Truthy(0) v.Equal(2, 3) v.Greater(2, 3) # Using custom assert functions def is_just_right(value): assert value == 'just right', 'Not just right!' return True # Passes expect('just right', is_just_right) # Fails try: expect('too cold', is_just_right) expect AssertionError: raise # Using custom 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)
Active development is underway with the goal of releasing v1.0.0 soon to lock in a stable API. You can track or contribute to verify on Github.