From c6a8301704162e1c4d07470c32ca0830f531b6d4 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Wed, 22 Nov 2023 09:26:11 +0100 Subject: [PATCH] feat: make ErrorType enums compare as strings (#269) The DBusError exception stores the error type as string. This makes the exception not directly compare to the ErrorType members (for example DBusError(ErrorType.FAILED, "").type != ErrorType.FAILED). This makes ErrorType also a string to make this comparision work. --- src/dbus_fast/constants.py | 2 +- tests/test_constants.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/dbus_fast/constants.py b/src/dbus_fast/constants.py index a705ce1..fe70b6e 100644 --- a/src/dbus_fast/constants.py +++ b/src/dbus_fast/constants.py @@ -91,7 +91,7 @@ class ArgDirection(Enum): OUT = "out" -class ErrorType(Enum): +class ErrorType(str, Enum): """An enum for the type of an error for a message reply. :seealso: http://man7.org/linux/man-pages/man3/sd-bus-errors.3.html diff --git a/tests/test_constants.py b/tests/test_constants.py index a0c3dfa..679cfb8 100644 --- a/tests/test_constants.py +++ b/tests/test_constants.py @@ -1,6 +1,12 @@ -from dbus_fast.constants import MESSAGE_FLAG_MAP, MessageFlag +from dbus_fast.constants import MESSAGE_FLAG_MAP, ErrorType, MessageFlag +from dbus_fast.errors import DBusError def test_message_flag_map(): assert 0 in MESSAGE_FLAG_MAP assert MessageFlag.NONE in MESSAGE_FLAG_MAP + + +def test_error_type(): + err = DBusError(ErrorType.FAILED, "") + assert ErrorType.FAILED == err.type