Skip to content

Commit

Permalink
fix: check message attribute in error representation (#25)
Browse files Browse the repository at this point in the history
* tests: add test to check error representation without message attr

* fix: check message attribute in error representation
  • Loading branch information
franciscorode authored Aug 5, 2022
1 parent 11df0af commit cade58e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion meiga/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def __eq__(self, other) -> bool:

def __repr__(self) -> str:
suffix = ""
if self.message:
if hasattr(self, "message") and self.message is not None:
suffix = f": {self.message}"

return f"{self.__class__.__name__}{suffix}"
11 changes: 11 additions & 0 deletions tests/unit/test_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,14 @@ def __init__(self, message: str):
f"Result[status: failure | value: ErrorWithMessage: {given_any_message}]"
== result.__repr__()
)


@pytest.mark.unit
def test_should_repr_as_expected_an_error_without_message_attribute():
class ErrorWithOutMessage(Error):
def __init__(self):
pass

result = Result(failure=ErrorWithOutMessage())

assert "Result[status: failure | value: ErrorWithOutMessage]" == result.__repr__()

0 comments on commit cade58e

Please sign in to comment.