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 in_contract, out_contract
@in_contract(lambda a, b: a * b > 0)
def add(a, b, c):
return a + b
@out_contract(lambda res: res > 0)
def sub(a, b):
return a - b
And more complex example about in_contract is
@in_contract(
lambda a0: a0 > 0,
lambda a1, b: a1 > 0 and b > 0,
{"a2": lambda x: x > 0},
{("a3",): lambda x: x > 0},
{("a4", "a5"): lambda x, y: x > 0 and y > 0},
b=lambda x: x > 0,
)
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.2.3.tar.gz
(7.6 kB
view details)
Built Distribution
File details
Details for the file ycontract-0.2.3.tar.gz
.
File metadata
- Download URL: ycontract-0.2.3.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.9 CPython/3.7.0 Darwin/19.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8156f8362aeb4847dfc4b4f962b659ccd6bb7a8cbea76162c573a94c00c5552f |
|
MD5 | f27cd232aba5d11d9b2eaec9285e3e60 |
|
BLAKE2b-256 | 3ec66e8f2c7d42528e864ae22473e70797b517c565be253b05fb40c440486399 |
File details
Details for the file ycontract-0.2.3-py3-none-any.whl
.
File metadata
- Download URL: ycontract-0.2.3-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.9 CPython/3.7.0 Darwin/19.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 998ba84e5de5fce815a1dcbfc475e46dd67fea8a2471574ef19d5e7e0c206893 |
|
MD5 | 17abc020bcfd974dc128ab37bdd83172 |
|
BLAKE2b-256 | 8291e629ae316ed0e9efae88f121fd5dd2e7d7e4d1812d73801746c1237bd57a |