https://github.com/genesiscoast/conditions-py
Conditions libary for Python 3+
https://github.com/genesiscoast/conditions-py
assertions conditional conditional-statements conditionals conditions fluent-assertions fluent-validation fluentvalidation libary python python-3 python3 validation validators
Last synced: 11 months ago
JSON representation
Conditions libary for Python 3+
- Host: GitHub
- URL: https://github.com/genesiscoast/conditions-py
- Owner: GenesisCoast
- License: gpl-3.0
- Created: 2019-07-25T10:52:51.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-11-14T14:12:44.000Z (over 6 years ago)
- Last Synced: 2025-07-03T01:18:54.355Z (11 months ago)
- Topics: assertions, conditional, conditional-statements, conditionals, conditions, fluent-assertions, fluent-validation, fluentvalidation, libary, python, python-3, python3, validation, validators
- Language: Python
- Size: 164 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/GenesisCoast/conditions-py) [](https://codecov.io/gh/GenesisCoast/conditions-py) [](https://badge.fury.io/py/conditions-py)
# Conditions-PY
Conditions is a Python port of the famous .NET library [Conditions](https://github.com/ghuntley/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)
- [Conditions](#conditions)
- [Tests](#tests)
- [Examples](#examples)
- [Acknowledgements](#acknowledgements)
## 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](https://github.com/GenesisCoast/conditions-py/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
```python
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
- The icon "Tornado" designed by Adam Whitcroft from The Noun Project.
- Geoffrey Huntley (ghuntley) who is the original author of "Conditions" from which this project was based on.