Skip to main content

conditions-py is a library that helps write pre- and postcondition validations in a fluent manner, helping improve the readability and reliability of code.

Project description

Image

Build Status codecov PyPI version

Conditions-PY

Conditions is a Python port of the famous .NET library Conditions which helps developers write pre- and postcondition validations in a fluent manner. Writing these validations is easy and it improves the readability and maintainability of code.

Contents

Installation

Installation is done via PIP:

pip install conditions-py

Conditions

A full list of all the available conditions can be found in the Wiki.

Tests

Currently both unit and integration tests are written using the pytest library. Execution of tests in Visual Studio Code is performed using the pytest test runner.

Examples

import conditions_py


def speak(message: str):
    Condition\
        .requires_str(message, 'message')\
        .is_not_null_or_whitespace()

    # Do speaking...


def multiple(left: int, right: int):
    Condition\
        .requires_num(left, 'left')\
        .is_positive()

    Condition\
        .requires_num(right, 'right')\
        .is_greater_than(4)
        
    # Do multiplication
    
    
def is_true(value: bool):
    Condition\
        .requires_bool(value, 'value')\
        .is_true()
        
    # Do other stuff
    
    
def animals(dog: object, cat: object):
    Condition\
        .requires_obj(dog, 'dog')\
        .is_not_null()
        
    Condition\
        .requires_obj(cat, 'cat')\
        .is_null()
        
    # Do other stuff

A particular validation is executed immediately when it's method is called, and therefore all checks are executed in the order in which they are written:

Acknowledgements

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

conditions_py-0.1.5.tar.gz (6.0 kB view details)

Uploaded Source

File details

Details for the file conditions_py-0.1.5.tar.gz.

File metadata

  • Download URL: conditions_py-0.1.5.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4

File hashes

Hashes for conditions_py-0.1.5.tar.gz
Algorithm Hash digest
SHA256 7cc46e3ba4df43444846ff078aebee2598d8b0fd62ea82696e1950c62a9f277e
MD5 6347f4298ae46cd1e568e0fbdd65092a
BLAKE2b-256 35e0fb7deb754a7f2a10bf67adc4bfd8b62c862f0836065f92aba79f2ab5e1e5

See more details on using hashes here.

Supported by

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