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.2.7.3.tar.gz
(8.3 kB
view details)
Built Distribution
File details
Details for the file ycontract-0.2.7.3.tar.gz
.
File metadata
- Download URL: ycontract-0.2.7.3.tar.gz
- Upload date:
- Size: 8.3 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 | 3da49d0f473589c2bb771871c04cffb5ccd0c06b1807fb026e31a83bd012158b |
|
MD5 | 9a299d63ec079dd3a4e29fd8b8239a91 |
|
BLAKE2b-256 | 5117592b763aceee7112e52b8d2756d720d4bc9fd0e0547f76668b1c4420270f |
File details
Details for the file ycontract-0.2.7.3-py3-none-any.whl
.
File metadata
- Download URL: ycontract-0.2.7.3-py3-none-any.whl
- Upload date:
- Size: 9.7 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 | 183763687875fb0b1ef9bfb10dcdd4f150f83c50a9dcc08fd70689ed0d94024c |
|
MD5 | 0517a2a75e554baaad540db077948b52 |
|
BLAKE2b-256 | 370a5ea056764b409550aff28af40d84ab63e885c0b41d9c6f6352780666b202 |