package/python-dbus-fast: new package
Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com> Reviewed-by: James Hilliard <james.hilliard1@gmail.com> [yann.morin.1998@free.fr: - select host-cython in Config.in - introduce obj_path in test sample ] Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
This commit is contained in:
committed by
Yann E. MORIN
parent
acaae6c39b
commit
82522d2547
45
support/testing/tests/package/sample_python_dbus_fast.py
Normal file
45
support/testing/tests/package/sample_python_dbus_fast.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import asyncio
|
||||
from dbus_fast.aio import MessageBus
|
||||
from dbus_fast.service import ServiceInterface, method
|
||||
import dbus_fast.introspection as intr
|
||||
from dbus_fast import BusType
|
||||
|
||||
|
||||
class SampleInterface(ServiceInterface):
|
||||
def __init__(self):
|
||||
super().__init__('test.interface')
|
||||
|
||||
@method()
|
||||
def Ping(self):
|
||||
pass
|
||||
|
||||
@method()
|
||||
def ConcatStrings(self, what1: 's', what2: 's') -> 's': # noqa: F821
|
||||
return what1 + what2
|
||||
|
||||
|
||||
async def main():
|
||||
bus_name = 'dbus.fast.sample'
|
||||
obj_path = '/test/path'
|
||||
|
||||
bus = await MessageBus(bus_type=BusType.SYSTEM).connect()
|
||||
bus2 = await MessageBus(bus_type=BusType.SYSTEM).connect()
|
||||
|
||||
await bus.request_name(bus_name)
|
||||
|
||||
service_interface = SampleInterface()
|
||||
bus.export(obj_path, service_interface)
|
||||
|
||||
introspection = await bus2.introspect(bus_name, obj_path)
|
||||
assert type(introspection) is intr.Node
|
||||
obj = bus2.get_proxy_object(bus_name, obj_path, introspection)
|
||||
interface = obj.get_interface(service_interface.name)
|
||||
|
||||
result = await interface.call_ping()
|
||||
assert result is None
|
||||
|
||||
result = await interface.call_concat_strings('hello ', 'world')
|
||||
assert result == 'hello world'
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user