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},
{("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.4.tar.gz
(7.6 kB
view details)
Built Distribution
File details
Details for the file ycontract-0.2.4.tar.gz
.
File metadata
- Download URL: ycontract-0.2.4.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 | a9937b346276b4bc12f53971769db7b677b1c13e2e6bea7fb8e8621da4c84bbf |
|
MD5 | dca937ccc33f057ac24b561f6b79a873 |
|
BLAKE2b-256 | b430badc20823686379fd37bbb7c8ed60cd9f4e59e43541f41f90b8280792b55 |
File details
Details for the file ycontract-0.2.4-py3-none-any.whl
.
File metadata
- Download URL: ycontract-0.2.4-py3-none-any.whl
- Upload date:
- Size: 7.6 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 | a6043f1bf472269c4f69202a1f5df8c2da5a3cf6d45449b6d3bd3a1f54620cb2 |
|
MD5 | fcb66e9082e1bdb54200367c6b3d672a |
|
BLAKE2b-256 | 261fb447194fb0641f263b28b47aa9ed691524940641f0455c7ac98ec86d5d00 |