Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pass return value to SendReply.__exit__ #127

Merged
merged 1 commit into from
Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/dbus_fast/message_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,8 +762,8 @@ def __exit__(
exc_type: Optional[Type[Exception]],
exc_value: Optional[Exception],
tb: Optional[TracebackType],
) -> None:
self._exit(exc_type, exc_value, tb)
) -> bool:
return self._exit(exc_type, exc_value, tb)

def send_error(self, exc: Exception) -> None:
self._exit(exc.__class__, exc, exc.__traceback__)
Expand Down
62 changes: 45 additions & 17 deletions tests/client/test_methods.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import logging
from logging.handlers import QueueHandler
from queue import SimpleQueue

import pytest

import dbus_fast.introspection as intr
Expand Down Expand Up @@ -93,14 +97,26 @@ async def test_aio_proxy_object():
result = await interface.call_get_complex(unpack_variants=True)
assert result == {"hello": "world"}

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
# In addition to the exception passing through, we need to verify that
# the exception doesn't trigger logging errors.
log_error_queue = SimpleQueue()
log_handler = QueueHandler(log_error_queue)
logger = logging.getLogger()

logger.addHandler(log_handler)
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()
bus2.disconnect()
Expand Down Expand Up @@ -138,15 +154,27 @@ def test_glib_proxy_object():
result = interface.call_get_complex_sync(unpack_variants=True)
assert result == {"hello": "world"}

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
# In addition to the exception passing through, we need to verify that
# the exception doesn't trigger logging errors.
log_error_queue = SimpleQueue()
log_handler = QueueHandler(log_error_queue)
logger = logging.getLogger()

logger.addHandler(log_handler)
try:
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()
bus2.disconnect()