Skip to content

Commit ff551df

Browse files
chore(pre-commit.ci): auto fixes
1 parent 1f9a152 commit ff551df

File tree

4 files changed

+71
-70
lines changed

4 files changed

+71
-70
lines changed

src/dbus_fast/aio/message_bus.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,7 @@ async def introspect(
318318
finally:
319319
timer_handle.cancel()
320320

321-
def introspect_sync(
322-
self,
323-
bus_name: str,
324-
path: str,
325-
*args, **kwargs
326-
) -> intr.Node:
321+
def introspect_sync(self, bus_name: str, path: str, *args, **kwargs) -> intr.Node:
327322
return self._loop.run_until_complete(
328323
self.introspect(bus_name, path, *args, **kwargs)
329324
)

src/dbus_fast/glib/proxy_object.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import xml.etree.ElementTree as ET
2-
from typing import Union
32

43
from .. import introspection as intr
54
from ..constants import ErrorType

src/dbus_fast/proxy_object.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,9 @@ def child_paths(self) -> List[str]:
311311
- :class:`InvalidIntrospectionError <dbus_fast.InvalidIntrospectionError>` - If the introspection data for the node is not valid.
312312
"""
313313
if self._child_paths is None:
314-
self._child_paths = [f"{self.path}/{n.name}" for n in self.introspection.nodes]
314+
self._child_paths = [
315+
f"{self.path}/{n.name}" for n in self.introspection.nodes
316+
]
315317
return self._child_paths
316318

317319
def get_interface(self, name: str) -> BaseProxyInterface:
@@ -379,9 +381,12 @@ def get_children(self) -> list[BaseProxyObject]:
379381
"""Get the child nodes of this proxy object according to the introspection data."""
380382
if self._children is None:
381383
self._children = [
382-
self.__class__(self.bus_name, f"{self.path}/{child.name}",
383-
child if child.interfaces or child.nodes else None,
384-
self.bus)
384+
self.__class__(
385+
self.bus_name,
386+
f"{self.path}/{child.name}",
387+
child if child.interfaces or child.nodes else None,
388+
self.bus,
389+
)
385390
for child in self.introspection.nodes
386391
]
387392

tests/test_introspection.py

Lines changed: 61 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import pytest
32
import xml.etree.ElementTree as ET
43

54
from dbus_fast import (
@@ -12,7 +11,7 @@
1211
from dbus_fast.constants import ErrorType
1312
from dbus_fast.errors import DBusError
1413
from dbus_fast.message_bus import BaseMessageBus
15-
from dbus_fast.proxy_object import BaseProxyObject, BaseProxyInterface
14+
from dbus_fast.proxy_object import BaseProxyInterface, BaseProxyObject
1615

1716
with open(f"{os.path.dirname(__file__)}/data/strict-introspection.xml") as f:
1817
strict_data = f.read()
@@ -154,30 +153,27 @@ def test_default_interfaces():
154153

155154

156155
class MockMessageBus(BaseMessageBus):
157-
158-
def __init__(self,
159-
nodes: dict[str, dict[str, intr.Node]]
160-
) -> None:
156+
def __init__(self, nodes: dict[str, dict[str, intr.Node]]) -> None:
161157
super().__init__(ProxyObject=MockProxyObject)
162158
self.nodes = nodes
163159
self.introspect_count = 0
160+
164161
# disable bus name tracking for testing purposes
165162
class MockNameOwners:
166163
@staticmethod
167164
def get(key, default):
168-
return ':'
165+
return ":"
166+
169167
self._name_owners = MockNameOwners
170168

171169
def introspect_sync(self, bus_name: str, path: str) -> intr.Node:
172170
self.introspect_count = self.introspect_count + 1
173171
service = self.nodes.get(bus_name)
174172
if service is None:
175-
raise DBusError(ErrorType.NAME_HAS_NO_OWNER,
176-
f"unknown service: {bus_name}")
173+
raise DBusError(ErrorType.NAME_HAS_NO_OWNER, f"unknown service: {bus_name}")
177174
node = service.get(path)
178175
if node is None:
179-
raise DBusError(ErrorType.UNKNOWN_OBJECT,
180-
f"unknown object: {path}")
176+
raise DBusError(ErrorType.UNKNOWN_OBJECT, f"unknown object: {path}")
181177
return node
182178

183179
def _setup_socket(self) -> None:
@@ -188,7 +184,6 @@ def _init_high_level_client(self) -> None:
188184

189185

190186
class MockProxyInterface(BaseProxyInterface):
191-
192187
def _add_method(self, intr_method: intr.Method) -> None:
193188
pass
194189

@@ -197,21 +192,22 @@ def _add_property(self, intr_property: intr.Property) -> None:
197192

198193

199194
class MockProxyObject(BaseProxyObject):
200-
201-
def __init__(self,
195+
def __init__(
196+
self,
202197
bus_name: str,
203198
path: str,
204199
introspection: intr.Node | str | ET.Element | None,
205-
bus: BaseMessageBus
200+
bus: BaseMessageBus,
206201
) -> None:
207202
super().__init__(bus_name, path, introspection, bus, MockProxyInterface)
208203

209204

210205
def test_inline_child():
211-
bus = MockMessageBus({
212-
'com.example': {
213-
'/com/example/parent_object': intr.Node.parse(
214-
"""<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
206+
bus = MockMessageBus(
207+
{
208+
"com.example": {
209+
"/com/example/parent_object": intr.Node.parse(
210+
"""<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
215211
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
216212
<node name="/com/example/parent_object">
217213
<interface name="com.example.ParentInterface">
@@ -222,78 +218,84 @@ def test_inline_child():
222218
<property name="ChildProperty" type="i"/>
223219
</interface>
224220
</node>
225-
</node>""")
221+
</node>"""
222+
)
226223
}
227-
})
228-
introspection = bus.introspect_sync('com.example',
229-
'/com/example/parent_object')
224+
}
225+
)
226+
introspection = bus.introspect_sync("com.example", "/com/example/parent_object")
230227
assert bus.introspect_count == 1
231228

232-
parent = bus.get_proxy_object('com.example', '/com/example/parent_object',
233-
introspection)
234-
assert parent.bus_name == 'com.example'
235-
assert parent.path == '/com/example/parent_object'
236-
assert parent.child_paths == [
237-
'/com/example/parent_object/child_object'
238-
]
239-
interface = parent.get_interface('com.example.ParentInterface')
240-
assert interface.bus_name == 'com.example'
241-
assert interface.path == '/com/example/parent_object'
229+
parent = bus.get_proxy_object(
230+
"com.example", "/com/example/parent_object", introspection
231+
)
232+
assert parent.bus_name == "com.example"
233+
assert parent.path == "/com/example/parent_object"
234+
assert parent.child_paths == ["/com/example/parent_object/child_object"]
235+
interface = parent.get_interface("com.example.ParentInterface")
236+
assert interface.bus_name == "com.example"
237+
assert interface.path == "/com/example/parent_object"
242238
assert [method.name for method in interface.introspection.methods] == [
243-
'ParentMethod'
244-
]
239+
"ParentMethod"
240+
]
245241

246242
child = next(iter(parent.get_children()))
247-
assert child.bus_name == 'com.example'
248-
assert child.path == '/com/example/parent_object/child_object'
249-
interface = child.get_interface('com.example.ChildInterface')
243+
assert child.bus_name == "com.example"
244+
assert child.path == "/com/example/parent_object/child_object"
245+
interface = child.get_interface("com.example.ChildInterface")
250246
assert [prop.name for prop in interface.introspection.properties] == [
251-
'ChildProperty'
252-
]
247+
"ChildProperty"
248+
]
253249

254250
# getting the inline child should not have required another introspection
255251
assert bus.introspect_count == 1
256252

257253

258254
def test_noninline_child():
259255
obj0_node = intr.Node.parse(strict_data)
260-
bus = MockMessageBus({
261-
'com.example': {
256+
bus = MockMessageBus(
257+
{
258+
"com.example": {
262259
obj0_node.name: obj0_node,
263-
f'{obj0_node.name}/child_of_sample_object': intr.Node.parse(
264-
f"""<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
260+
f"{obj0_node.name}/child_of_sample_object": intr.Node.parse(
261+
f"""<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
265262
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
266263
<node name="{obj0_node.name}/child_of_sample_object">
267264
<interface name="com.example.ChildInterface">
268265
<property name="ChildProperty" type="i"/>
269266
</interface>
270-
</node>"""),
267+
</node>"""
268+
),
271269
}
272-
})
273-
introspection = bus.introspect_sync('com.example',
274-
'/com/example/sample_object0')
270+
}
271+
)
272+
introspection = bus.introspect_sync("com.example", "/com/example/sample_object0")
275273
assert bus.introspect_count == 1
276-
parent = bus.get_proxy_object('com.example', '/com/example/sample_object0',
277-
introspection)
274+
parent = bus.get_proxy_object(
275+
"com.example", "/com/example/sample_object0", introspection
276+
)
278277

279-
assert parent.path == '/com/example/sample_object0'
278+
assert parent.path == "/com/example/sample_object0"
280279
assert parent.child_paths == [
281-
'/com/example/sample_object0/child_of_sample_object',
282-
'/com/example/sample_object0/another_child_of_sample_object',
283-
]
280+
"/com/example/sample_object0/child_of_sample_object",
281+
"/com/example/sample_object0/another_child_of_sample_object",
282+
]
284283
children = parent.get_children()
285284
assert [child.path for child in children] == parent.child_paths
286285

287286
# merely listing the children should not have required another introspection
288287
assert bus.introspect_count == 1
289288

290-
child = next(child for child in children if child.path == \
291-
'/com/example/sample_object0/child_of_sample_object')
292-
interface = child.get_interface('com.example.ChildInterface')
289+
child = next(
290+
child
291+
for child in children
292+
if child.path == "/com/example/sample_object0/child_of_sample_object"
293+
)
294+
interface = child.get_interface("com.example.ChildInterface")
293295

294296
# obtaining the child interface should have required a second introspection
295297
assert bus.introspect_count == 2
296298

297299
assert [prop.name for prop in interface.introspection.properties] == [
298-
'ChildProperty'
299-
]
300+
"ChildProperty"
301+
]

0 commit comments

Comments
 (0)