Skip to main content

Python library for contracts testing

Project description

ycontract

PyPI PyPI - Python Version pipeline status coverage report PyPI - License

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,
    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

Apache 2.0

Project details


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.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

ycontract-0.2.7-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file ycontract-0.2.7.tar.gz.

File metadata

  • Download URL: ycontract-0.2.7.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

Hashes for ycontract-0.2.7.tar.gz
Algorithm Hash digest
SHA256 ba5efa42e5aa458afadb1bf92dd0afe6b6d6447157d0479a46af6e65bd9ed483
MD5 d05e1b41a49855c0bc7538b9b966a725
BLAKE2b-256 c81f724fcac6192d9f1c271921335198c82ee39643211951dd42e3d9400c49d8

See more details on using hashes here.

File details

Details for the file ycontract-0.2.7-py3-none-any.whl.

File metadata

  • Download URL: ycontract-0.2.7-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

Hashes for ycontract-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1ff610f79a265024290c012f920d590f792e28f3325b1b492c2bc51b5e945acd
MD5 27f7a150a606db9639c283e3a1e8f239
BLAKE2b-256 68f25320d097e1b4437a3dc29639ae0fa7651b4860676c9dffd54d335913fd57

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page