olivierdalang / looplog

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Looplog

Looplog is a simple helper to log processing done in a loop, catching errors and warnings to produce a readble console output, both interactively and not.

Quickly see how it looks with the demo.

python -m looplog.demo

Usage

Decorate you function with @looplog(items) like this.

from looplog import SKIP, looplog

@looplog([1, 2, 3, 4, 5, 6, 7, 8, "9", 10, 11.5, 12, 0, 13, None, 15])
def func_basic(value):
    if value is None:
        return SKIP
    if isinstance(value, float) and not value.is_integer():
        warnings.warn("Input will be rounded !")
    10 // value

# [to stdout in realtime]
# Starting loop `func_basic`
# ..........!.X.-....X.

print(func_basic.details())

# ================================================================================
# WARNING step_11: Input will be rounded !
# ================================================================================
# ERROR step_13: integer division or modulo by zero
# ================================================================================
# ERROR step_20: unsupported operand type(s) for //: 'int' and 'str'
# ================================================================================

print(func_basic.summary())

# 17 ok / 1 warn / 2 err / 1 skip

Check the looplog docstring for some additional features (logging, limit, etc.).

Contribute

# install pre-commit
pip install pre-commit
pre-commit install

# run tests
python -m tests

About


Languages

Language:Python 100.0%