feat: refactor service bus handler lookup to avoid linear searches (#400)
This commit is contained in:
@@ -28,9 +28,14 @@ async def test_export_unexport():
|
||||
|
||||
bus = await MessageBus().connect()
|
||||
bus.export(export_path, interface)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
# Already exported
|
||||
bus.export(export_path, interface)
|
||||
|
||||
assert export_path in bus._path_exports
|
||||
assert len(bus._path_exports[export_path]) == 1
|
||||
assert bus._path_exports[export_path][0] is interface
|
||||
assert bus._path_exports[export_path][interface.name] is interface
|
||||
assert len(ServiceInterface._get_buses(interface)) == 1
|
||||
|
||||
bus.export(export_path2, interface2)
|
||||
@@ -60,11 +65,23 @@ async def test_export_unexport():
|
||||
assert not bus._path_exports
|
||||
assert not ServiceInterface._get_buses(interface)
|
||||
|
||||
# test unexporting by ServiceInterface
|
||||
bus.export(export_path, interface)
|
||||
bus.unexport(export_path, interface)
|
||||
assert not bus._path_exports
|
||||
assert not ServiceInterface._get_buses(interface)
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
bus.unexport(export_path, object())
|
||||
|
||||
node = bus._introspect_export_path("/path/doesnt/exist")
|
||||
assert type(node) is intr.Node
|
||||
assert not node.interfaces
|
||||
assert not node.nodes
|
||||
|
||||
# Should to nothing
|
||||
bus.unexport("/path/doesnt/exist", interface)
|
||||
|
||||
bus.disconnect()
|
||||
|
||||
|
||||
|
||||
@@ -149,6 +149,19 @@ async def test_peer_interface():
|
||||
assert reply.message_type == MessageType.METHOD_RETURN, reply.body[0]
|
||||
assert reply.signature == "s"
|
||||
|
||||
reply2 = await bus2.call(
|
||||
Message(
|
||||
destination=bus1.unique_name,
|
||||
path="/path/doesnt/exist",
|
||||
interface="org.freedesktop.DBus.Peer",
|
||||
member="GetMachineId",
|
||||
signature="",
|
||||
)
|
||||
)
|
||||
|
||||
assert reply2.message_type == MessageType.METHOD_RETURN, reply.body[0]
|
||||
assert reply2.signature == "s"
|
||||
|
||||
bus1.disconnect()
|
||||
bus2.disconnect()
|
||||
|
||||
@@ -213,9 +226,9 @@ async def test_object_manager():
|
||||
)
|
||||
)
|
||||
|
||||
assert reply_root.signature == "a{oa{sa{sv}}}"
|
||||
assert reply_level1.signature == "a{oa{sa{sv}}}"
|
||||
assert reply_level2.signature == "a{oa{sa{sv}}}"
|
||||
assert reply_root.signature == "a{oa{sa{sv}}}", reply_root
|
||||
assert reply_level1.signature == "a{oa{sa{sv}}}", reply_level1
|
||||
assert reply_level2.signature == "a{oa{sa{sv}}}", reply_level2
|
||||
|
||||
assert reply_level2.body == [{}]
|
||||
assert reply_level1.body == [expected_reply]
|
||||
|
||||
Reference in New Issue
Block a user