Skip to content

Commit

Permalink
Fix interface compositioning not working because of common interfaces
Browse files Browse the repository at this point in the history
The issue is that any interface has the interfaces like
`org.freedesktop.DBus.Introspectable` or `org.freedesktop.DBus.Properties`.
The interface names and member names of those built-in interfaces
should not be checked for collisions.

Thank you @AndersBlomdell for testing NetworkManager binds against
development version.
  • Loading branch information
igo95862 committed Jan 4, 2024
1 parent 8b11d3f commit e7bd8dc
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/sdbus/dbus_proxy_async_interface_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ def __new__(cls, name: str,
f"async interface: {attr_name!r}"
)

if not serving_enabled:
continue

if isinstance(attr, DbusMethodAsync):
dbus_class_meta.dbus_member_to_python_attr[
attr.method_name] = attr_name
Expand Down
5 changes: 4 additions & 1 deletion src/sdbus/dbus_proxy_sync_interface_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __new__(cls, name: str,
) -> DbusInterfaceMetaSync:

dbus_class_meta = DbusClassMeta()
if interface_name is not None:
if interface_name is not None and serving_enabled:
dbus_class_meta.dbus_interfaces_names.add(interface_name)

for attr_name, attr in namespace.items():
Expand All @@ -58,6 +58,9 @@ def __new__(cls, name: str,
f"Can't mix async methods in sync interface: {attr_name!r}"
)

if not serving_enabled:
continue

if isinstance(attr, DbusMethodSync):
dbus_class_meta.dbus_member_to_python_attr[
attr.method_name] = attr_name
Expand Down
24 changes: 22 additions & 2 deletions test/test_sdbus_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,12 @@ def test_property_setter(self, var: str) -> None:

with self.subTest('Test dbus to python mapping'):
self.assertIn(
"PropertiesChanged",
"TestInt",
test_object._dbus_meta.dbus_member_to_python_attr,
)

self.assertIn(
"PropertiesChanged",
"TestInt",
test_subclass._dbus_meta.dbus_member_to_python_attr,
)

Expand Down Expand Up @@ -887,3 +887,23 @@ async def catch_properties_changed() -> int:
await wait_for(catch_changed_task, timeout=1),
10,
)

async def test_interface_composition(self) -> None:
class OneInterface(
DbusInterfaceCommonAsync,
interface_name="org.example.one",
):
@dbus_method_async(result_signature="x")
async def one(self) -> int:
raise NotImplementedError

class TwoInterface(
DbusInterfaceCommonAsync,
interface_name="org.example.two",
):
@dbus_method_async(result_signature="t")
async def two(self) -> int:
return 2

class CombinedInterface(OneInterface, TwoInterface):
...
22 changes: 22 additions & 0 deletions test/test_sdbus_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from sdbus.unittest import IsolatedDbusTestCase
from sdbus_block.dbus_daemon import FreedesktopDbus

from sdbus import DbusInterfaceCommon, dbus_method


class TestSync(IsolatedDbusTestCase):

Expand Down Expand Up @@ -70,6 +72,26 @@ def test_docstring(self) -> None:
with self.subTest('Property doc (through class dict)'):
self.assertTrue(getdoc(s.__class__.__dict__['features']))

def test_interface_composition(self) -> None:
class OneInterface(
DbusInterfaceCommon,
interface_name="org.example.one",
):
@dbus_method(result_signature="x")
def one(self) -> int:
raise NotImplementedError

class TwoInterface(
DbusInterfaceCommon,
interface_name="org.example.two",
):
@dbus_method(result_signature="t")
def two(self) -> int:
raise NotImplementedError

class CombinedInterface(OneInterface, TwoInterface):
...


if __name__ == '__main__':
main()

0 comments on commit e7bd8dc

Please sign in to comment.