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.1.tar.gz
(8.3 kB
view details)
Built Distribution
File details
Details for the file ycontract-0.2.7.1.tar.gz
.
File metadata
- Download URL: ycontract-0.2.7.1.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 | 73d21d95be5b00e228737ee52ef11d68cbcb5f9b45681136a01a1470a0135328 |
|
MD5 | 85febb0b816ca5fa9fea7fa80f50dc51 |
|
BLAKE2b-256 | 13cac71479f6a8ecc1338ea4603b0b2b44d31dfda6998be1025494f716c1202e |
File details
Details for the file ycontract-0.2.7.1-py3-none-any.whl
.
File metadata
- Download URL: ycontract-0.2.7.1-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 | b7c2e90ad47d3b66a636421b8e9ae6b3f572584bab8cf70f34f50193c6a9257f |
|
MD5 | fadc84fd5b330174e0d8c3a7db6ea948 |
|
BLAKE2b-256 | 47c8571674e7b956b99ed3e07c807ec89d870d6dde5ee5acf29d59f0b0679445 |