Skip to content

Commit

Permalink
add test case for static methods (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasSchneegans authored Jun 18, 2024
1 parent b2e1371 commit c3a6836
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions unittests/test_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,34 @@ def func(hello: str) -> str:
assert result == success_tracker[0][0][0] == "Hello World!"
assert success_tracker[0][0][1] == "World!"

def test_decorator_static_method_error_case(self):
error_callback, error_tracker = create_callback_tracker()

class TestClass:
@staticmethod
@error_handler.decorator(on_error=error_callback, on_success=assert_not_called, on_error_return_always=None)
def func(hello: str) -> None:
raise ValueError(f"This is a test error {hello}")

result = TestClass.func("world")
assert isinstance(error_tracker[0][0][0], ValueError)
assert str(error_tracker[0][0][0]) == "This is a test error world"
assert error_tracker[0][0][1] == "world"
assert result is None

def test_decorator_static_method_success_case(self):
on_success_callback, success_tracker = create_callback_tracker()

class TestClass:
@staticmethod
@error_handler.decorator(on_success=on_success_callback, on_error=assert_not_called)
def func(hello: str) -> str:
return f"Hello {hello}"

result = TestClass.func("World!")
assert result == success_tracker[0][0][0] == "Hello World!"
assert success_tracker[0][0][1] == "World!"

async def test_decorator_reraise_coroutine(self):
catched_error: Exception | None = None

Expand Down

0 comments on commit c3a6836

Please sign in to comment.