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

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

Uploaded Source

Built Distribution

ycontract-0.3.3.1-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ycontract-0.3.3.1.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.10 CPython/3.9.0b5 Darwin/19.3.0

File hashes

Hashes for ycontract-0.3.3.1.tar.gz
Algorithm Hash digest
SHA256 b645c555b681bbe4dc1bfb4cb7694e1e8e2be2a39d70a7ed96bf52ebce2ee1c4
MD5 77693785308d59256a8644c9805220b6
BLAKE2b-256 19137d9ff8a1d37ed9a7c9b77583eac225221ab2d8bfc97d19eebd1745f16895

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ycontract-0.3.3.1-py3-none-any.whl
  • Upload date:
  • Size: 11.5 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

Hashes for ycontract-0.3.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 95d62c2f6db4e86185595bc40d1f100050a432e2d3904de9a26edd9bc3f69901
MD5 69da33707e352c3c973c534e096247f6
BLAKE2b-256 e41af045368d7493eada5d9e233c5b7f7a98e6c3d50b00d546686a1582d7eff9

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