Skip to content

Commit

Permalink
feat: add repr and str impl for OnFailureException (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
fgsalomon authored Nov 23, 2023
1 parent 743cf2c commit 78b3371
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions meiga/on_failure_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ class OnFailureException(Error):
def __init__(self, result: "AnyResult") -> None:
self.result = result
Exception.__init__(self)

def __str__(self) -> str:
return f"OnFailureException: {self.result}"

def __repr__(self) -> str:
return f"OnFailureException: {self.result}"
28 changes: 28 additions & 0 deletions tests/unit/test_on_failure_exception.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import pytest

from meiga import Error, Result
from meiga.on_failure_exception import OnFailureException


@pytest.mark.unit
def test_should_str_as_expected_default_error():
result = Result(failure=Error())

exception = OnFailureException(result)

assert "OnFailureException: Result[status: failure | value: Error]" == str(
exception
)


@pytest.mark.unit
def test_should_str_as_expected_an_exception():
wrapped_exception = ValueError("Something went wrong")
result = Result(failure=wrapped_exception)

exception = OnFailureException(result)

assert (
f"OnFailureException: Result[status: failure | value: {wrapped_exception.__repr__()}]"
== str(exception)
)

0 comments on commit 78b3371

Please sign in to comment.