Skip to content

Commit f8ee1a8

Browse files
committed
Minor Fixes
1 parent 6bb86d7 commit f8ee1a8

3 files changed

Lines changed: 19 additions & 20 deletions

File tree

classmods/_decorators.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from functools import wraps
33
from typing import Any, Callable, Literal, Optional, ParamSpec, Tuple, TypeAlias, TypeVar, Union, overload
44

5-
LOG_LEVEL: TypeAlias = Literal['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'NOTSET', 'DEFAULT']
5+
LOG_LEVEL: TypeAlias = Literal['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'NOTSET']
66

77
P = ParamSpec("P")
88
R = TypeVar("R")
@@ -17,7 +17,7 @@ def logwrap(
1717
A simple dynamic decorator to log function calls using the `logging` module with your current project configurations.
1818
Use the `LOG_LEVEL` literal to specify standard log levels.
1919
20-
LOG_LEVEL = ['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'NOTSET', 'DEFAULT']
20+
LOG_LEVEL = ['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'NOTSET']
2121
2222
- The messages are formatted dynamically using templating.
2323
- Available variables:
@@ -88,8 +88,8 @@ def normalize(
8888
return option
8989

9090
before = normalize('DEBUG', 'Calling {func} - kwargs={kwargs}', before)
91-
after = normalize('INFO', 'Function {func} ended. result={result}', after)
9291
on_exception = normalize('ERROR', 'Error in {func}: {e}', on_exception)
92+
after = normalize('INFO', 'Function {func} ended. result={result}', after)
9393

9494
def decorator(func: Callable[P, R]) -> Callable[P, R]:
9595
sig = inspect.signature(func)

test/test_decorators.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from classmods import suppress_errors
1+
from classmods import logwrap, suppress_errors
22

33
@suppress_errors(Exception)
44
def return_exception():
@@ -27,4 +27,18 @@ def test_supress_error():
2727
assert result is False, f"Expected False, got {result}"
2828

2929
result = return_any()
30-
assert result == 'Failed', f"Expected 'Failed', got {result}"
30+
assert result == 'Failed', f"Expected 'Failed', got {result}"
31+
32+
def test_standard_use():
33+
# Example with defaults.
34+
@logwrap(before='Starting', after='Ended')
35+
def my_new_func():
36+
...
37+
my_new_func()
38+
39+
def test_with_custom_leveling():
40+
# Example with Custom Levels
41+
@logwrap(before=('INFO', 'Function starting'), after=('INFO', 'Function ended'))
42+
def my_func(my_arg, my_kwarg=None):
43+
...
44+
my_func('hello', my_kwarg=123) # calling the function

test/test_logwrap.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)