def test_unhandled(): unhandled = [] router = Router(Future, on_unhandled=unhandled.append) msg = message_bus.Hello() router.incoming(msg) assert len(unhandled) == 1 assert unhandled[0] == msg
async def open_dbus_connection(bus='SESSION', *, enable_fds=False) -> DBusConnection: """Open a plain D-Bus connection :return: :class:`DBusConnection` """ bus_addr = get_bus(bus) sock: trio.SocketStream = await trio.open_unix_socket(bus_addr) # Authentication authr = Authenticator(enable_fds=enable_fds) for req_data in authr: await sock.send_all(req_data) authr.feed(await sock.receive_some()) await sock.send_all(BEGIN) conn = DBusConnection(sock.socket, enable_fds=enable_fds) # Say *Hello* to the message bus - this must be the first message, and the # reply gives us our unique name. async with conn.router() as router: reply = await router.send_and_get_reply(message_bus.Hello()) conn.unique_name = reply.body[0] return conn
async def open_dbus_connection(bus='SESSION') -> DBusConnection: """Open a plain D-Bus connection :return: :class:`DBusConnection` """ bus_addr = get_bus(bus) sock: trio.SocketStream = await trio.open_unix_socket(bus_addr) # Authentication flow await sock.send_all(b'\0' + make_auth_external()) auth_parser = SASLParser() while not auth_parser.authenticated: b = await sock.receive_some() auth_parser.feed(b) if auth_parser.error: raise AuthenticationError(auth_parser.error) await sock.send_all(BEGIN) # Authentication finished conn = DBusConnection(sock) conn.parser.add_data(auth_parser.buffer) # Say *Hello* to the message bus - this must be the first message, and the # reply gives us our unique name. async with conn.router() as router: reply = await router.send_and_get_reply(message_bus.Hello()) conn.unique_name = reply.body[0] return conn
def test_error(): router = Router(Future) call = message_bus.Hello() future = router.outgoing(call) router.incoming(new_error(call, 'TestError', 'u', (31, ))) with pytest.raises(DBusErrorResponse) as e: future.result() assert e.value.name == 'TestError' assert e.value.data == (31, )
def test_message_reply(): router = Router(Future) call = message_bus.Hello() future = router.outgoing(call) router.incoming(new_method_return(call, 's', ('test', ))) assert future.result() == ('test', )