fix: pass return value to SendReply.__exit__ (#127)

This commit is contained in:
David Lechner
2022-10-29 18:43:47 -05:00
committed by GitHub
parent 8f6a431ea4
commit f8c67ed00f
2 changed files with 47 additions and 19 deletions

View File

@@ -762,8 +762,8 @@ class BaseMessageBus:
exc_type: Optional[Type[Exception]], exc_type: Optional[Type[Exception]],
exc_value: Optional[Exception], exc_value: Optional[Exception],
tb: Optional[TracebackType], tb: Optional[TracebackType],
) -> None: ) -> bool:
self._exit(exc_type, exc_value, tb) return self._exit(exc_type, exc_value, tb)
def send_error(self, exc: Exception) -> None: def send_error(self, exc: Exception) -> None:
self._exit(exc.__class__, exc, exc.__traceback__) self._exit(exc.__class__, exc, exc.__traceback__)

View File

@@ -1,3 +1,7 @@
import logging
from logging.handlers import QueueHandler
from queue import SimpleQueue
import pytest import pytest
import dbus_fast.introspection as intr import dbus_fast.introspection as intr
@@ -93,14 +97,26 @@ async def test_aio_proxy_object():
result = await interface.call_get_complex(unpack_variants=True) result = await interface.call_get_complex(unpack_variants=True)
assert result == {"hello": "world"} assert result == {"hello": "world"}
with pytest.raises(DBusError): # In addition to the exception passing through, we need to verify that
try: # the exception doesn't trigger logging errors.
await interface.call_throws_error() log_error_queue = SimpleQueue()
except DBusError as e: log_handler = QueueHandler(log_error_queue)
assert e.reply is not None logger = logging.getLogger()
assert e.type == "test.error"
assert e.text == "something went wrong" logger.addHandler(log_handler)
raise e try:
with pytest.raises(DBusError):
try:
await interface.call_throws_error()
except DBusError as e:
assert e.reply is not None
assert e.type == "test.error"
assert e.text == "something went wrong"
raise e
finally:
logger.removeHandler(log_handler)
assert log_error_queue.empty()
bus.disconnect() bus.disconnect()
bus2.disconnect() bus2.disconnect()
@@ -138,15 +154,27 @@ def test_glib_proxy_object():
result = interface.call_get_complex_sync(unpack_variants=True) result = interface.call_get_complex_sync(unpack_variants=True)
assert result == {"hello": "world"} assert result == {"hello": "world"}
with pytest.raises(DBusError): # In addition to the exception passing through, we need to verify that
try: # the exception doesn't trigger logging errors.
result = interface.call_throws_error_sync() log_error_queue = SimpleQueue()
assert False, result log_handler = QueueHandler(log_error_queue)
except DBusError as e: logger = logging.getLogger()
assert e.reply is not None
assert e.type == "test.error" logger.addHandler(log_handler)
assert e.text == "something went wrong" try:
raise e with pytest.raises(DBusError):
try:
result = interface.call_throws_error_sync()
assert False, result
except DBusError as e:
assert e.reply is not None
assert e.type == "test.error"
assert e.text == "something went wrong"
raise e
finally:
logger.removeHandler(log_handler)
assert log_error_queue.empty()
bus.disconnect() bus.disconnect()
bus2.disconnect() bus2.disconnect()