From a08c2e750c11d4d7c5006343d1a8f64e68c9c019 Mon Sep 17 00:00:00 2001 From: Oleg A Date: Sun, 11 Sep 2022 23:16:47 +0300 Subject: [PATCH] Add representation for aiogram exception (#989) * feat: add repr for aiogram exception #988 * docs: add changelog #988 * tests: add representation coverage #988 * fix: correct test result type #988 --- CHANGES/988.feature | 1 + aiogram/exceptions.py | 3 +++ tests/test_api/test_types/test_exception.py | 15 +++++++++++++++ 3 files changed, 19 insertions(+) create mode 100644 CHANGES/988.feature create mode 100644 tests/test_api/test_types/test_exception.py diff --git a/CHANGES/988.feature b/CHANGES/988.feature new file mode 100644 index 00000000..2cec018b --- /dev/null +++ b/CHANGES/988.feature @@ -0,0 +1 @@ +Added message text to aiogram exceptions representation diff --git a/aiogram/exceptions.py b/aiogram/exceptions.py index 514d7382..5a52670c 100644 --- a/aiogram/exceptions.py +++ b/aiogram/exceptions.py @@ -23,6 +23,9 @@ class DetailedAiogramError(AiogramError): message += f"\n(background on this error at: {self.url})" return message + def __repr__(self) -> str: + return f"{type(self).__name__}('{self}')" + class TelegramAPIError(DetailedAiogramError): def __init__( diff --git a/tests/test_api/test_types/test_exception.py b/tests/test_api/test_types/test_exception.py new file mode 100644 index 00000000..93c82ad6 --- /dev/null +++ b/tests/test_api/test_types/test_exception.py @@ -0,0 +1,15 @@ +import pytest + +from aiogram.exceptions import DetailedAiogramError + + +class TestException: + @pytest.mark.parametrize( + "message,result", + [ + ["reason", "DetailedAiogramError('reason')"], + ], + ) + def test_representation(self, message: str, result: str): + exc = DetailedAiogramError(message=message) + assert repr(exc) == result