Python library for contracts testing
Project description
ycontract
Python library for contracts testing.
This library provides functions for checking argument(in_contract
) and return value(out_contract
) of a function.
How to install
$ pip install ycontract
Example
Example files are here(test file)
Main example is
from ycontract import contract, out_contract
@contract(lambda a, b: a * b > 0)
def add(a, b, c):
return a + b
@contract(returns=lambda res: res > 0)
def sub(a, b):
return a - b
And more complex example about in_contract is
@contract(
lambda a0: a0 > 0,
lambda a1, b: a1 > 0 and b > 0,
{
"a2": lambda x: x > 0,
"a3": [
lambda x: x >= 0,
lambda x: x < 4,
],
("a4", "a5"): lambda x, y: x > 0 and y > 0,
},
b=lambda x: x > 0,
contract_tag="tagtag",
)
def add_for_complex(a0, a1, a2, a3, a4, a5, b=1):
return a0 + a1 + a2 + a3 + a4 + a5 + b
Furthermore if you want to be disable, call
ycontract.disable_contract()
LICENSES
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ycontract-0.3.2.tar.gz
(9.9 kB
view hashes)
Built Distribution
ycontract-0.3.2-py3-none-any.whl
(11.3 kB
view hashes)
Close
Hashes for ycontract-0.3.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24ffeca58c98db652fffd12e03798568cf1c47232e26ea6d7cd49523264d857c |
|
MD5 | baaec659fb7451c63d2a8711faa18e65 |
|
BLAKE2b-256 | 0efcd44d3392ccb55f6fe5f87d751fe37f233ca86d1a8fd02717d4552b55dc77 |