Skip to content

Commit

Permalink
mockobject: Allow passing some extra data to DBusMockObject
Browse files Browse the repository at this point in the history
This makes it possible to store some data in the object created via
DBusMockObject.add_object which can be useful if one e.g. needs some
information stored in the parent object.
  • Loading branch information
swick committed Sep 13, 2024
1 parent 6a68a42 commit bbcb469
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions dbusmock/mockobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def __init__(
props: PropsType,
logfile: Optional[str] = None,
is_object_manager: bool = False,
data: Any = None,
) -> None:
"""Create a new DBusMockObject
Expand Down Expand Up @@ -235,6 +236,8 @@ def __init__(
self.is_logfile_owner = True
self.call_log: List[CallLogType] = []

self.data = data

if props is None:
props = {}

Expand Down Expand Up @@ -322,13 +325,13 @@ def Set(self, interface_name: str, property_name: str, value: Any, *_, **__) ->
[interface_name, dbus.Dictionary({property_name: value}, signature="sv"), dbus.Array([], signature="s")],
)

def add_object(self, mock_class: Type[Self], path: str, interface: str, properties: PropsType, methods: List[MethodType]) -> Self:
def add_object(self, mock_class: Type[Self], path: str, interface: str, properties: PropsType, methods: List[MethodType], data: Any = None) -> Self:
if path in objects:
raise dbus.exceptions.DBusException(
f"object {path} already exists", name="org.freedesktop.DBus.Mock.NameError"
)

obj = mock_class(self.bus_name, path, interface, properties)
obj = mock_class(self.bus_name, path, interface, properties, data=data)
# make sure created objects inherit the log file stream
obj.logfile = self.logfile
obj.object_manager = self.object_manager
Expand Down

0 comments on commit bbcb469

Please sign in to comment.