Giter Site home page Giter Site logo

genesiscoast / conditions-py Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 168 KB

Conditions libary for Python 3+

License: GNU General Public License v3.0

Python 100.00%
python libary conditions conditional-statements conditional conditionals python3 python-3 fluentvalidation fluent-validation fluent-assertions assertions validation validators

conditions-py's Introduction

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

conditions-py's People

Contributors

genesiscoast avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.