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,
("a3-2",): lambda x: x <= 0,
("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.6.tar.gz
(7.7 kB
view details)
Built Distribution
File details
Details for the file ycontract-0.2.6.tar.gz
.
File metadata
- Download URL: ycontract-0.2.6.tar.gz
- Upload date:
- Size: 7.7 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 | 3a2a3da696e0f49c5496663786e6dbe5892a5dc6258118f83c2b8adcad1ec902 |
|
MD5 | c4d7754175231d394e67aff732f675ce |
|
BLAKE2b-256 | 278ab6fc5143bf0432f61fe5ba3037b083d3cf5706ba3d03a722ab7a5f37e80b |
File details
Details for the file ycontract-0.2.6-py3-none-any.whl
.
File metadata
- Download URL: ycontract-0.2.6-py3-none-any.whl
- Upload date:
- Size: 7.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 | be01db22bf19504e5980de0c2c7378da036d563c6f75cc3c5a3773aaa70b1340 |
|
MD5 | 129fbf787c354a6a9ecdd38631e745e9 |
|
BLAKE2b-256 | f33109efd8c687e1c8c7ca7258dacc5b1fba0054fa9434d9e9b227416459eaac |