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.0.tar.gz
(8.9 kB
view details)
Built Distribution
ycontract-0.3.0-py3-none-any.whl
(10.4 kB
view details)
File details
Details for the file ycontract-0.3.0.tar.gz
.
File metadata
- Download URL: ycontract-0.3.0.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.10 CPython/3.9.0b5 Darwin/19.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa5984c57f55e5add8f7a3f9ca507604f975a24c6bf3eab6a1b6ed976d471116 |
|
MD5 | 1913ac8ecacb4fa42ed575735a2144ec |
|
BLAKE2b-256 | b2e5ddfb63d1be362ef3cc59b92acdc6b0f3c47a45c5ec7e66b82ccfbd262db2 |
File details
Details for the file ycontract-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: ycontract-0.3.0-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.10 CPython/3.9.0b5 Darwin/19.3.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85add42577163fd539455d1462dee2a0dcb731de5e4e88acfcd2b1009fda6ede |
|
MD5 | e3d0b19be47e2e32e076b48b0fcec0b2 |
|
BLAKE2b-256 | 8a6e25add7e80ca48887299349c0ac20e489bc0bce7fe15323ea63f6e0d418f9 |