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
@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 <= 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.7.2.tar.gz
(8.3 kB
view details)
Built Distribution
File details
Details for the file ycontract-0.2.7.2.tar.gz
.
File metadata
- Download URL: ycontract-0.2.7.2.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 | eb33844a5d90e3ae78900ed025bfc770ae3b2ad46030971b16f17e0d5ffdf59f |
|
MD5 | 1e501bf748f457187f22ff140e9d3ea4 |
|
BLAKE2b-256 | 1b2453e0916c5d588ca312d4090e0846453c07bcc4024e0e76be11526126d796 |
File details
Details for the file ycontract-0.2.7.2-py3-none-any.whl
.
File metadata
- Download URL: ycontract-0.2.7.2-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 | 1ba1c71b422e11bb8375e0118ad72b9c4fed85a0af977bfe7a64b8f68a46b487 |
|
MD5 | cc4f3c5ede9cd0f8e001c5047f82b807 |
|
BLAKE2b-256 | 3aaa1f48f4aa461a05c018cf292b9ee8506196b06fb598ec90754f8407a6a6b3 |