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,
)
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.5.tar.gz
(7.6 kB
view details)
Built Distribution
File details
Details for the file ycontract-0.2.5.tar.gz
.
File metadata
- Download URL: ycontract-0.2.5.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 | 84ed8142cbf6eacf1634181090c30946507414b09d59e9d54292b4d9af71c27e |
|
MD5 | 46943aba656a67502444461d21476094 |
|
BLAKE2b-256 | 594c9daf9e8e73ab0671719e144ee1f0fa4c4e8ae1dbbb2afdddab1bf2c89d04 |
File details
Details for the file ycontract-0.2.5-py3-none-any.whl
.
File metadata
- Download URL: ycontract-0.2.5-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 | 4c0d08705540da6ca086cfc3d9b77418e73437691ba55bf15dcd770b8e220b80 |
|
MD5 | 306aeea6d4aecfab7564fb26249c87ca |
|
BLAKE2b-256 | 79751adb8d61a5ba73cc8357e45d60e0e0697183bc71b586709a6dd08e84d133 |