blob: c4d817849f6bc1f62df5953e09fcde6572300685 [file] [log] [blame]
Brad Bishop316dfdd2018-06-25 12:45:53 -04001From c4436fd42f2936e5fb0f95434d06e45aa9959ca0 Mon Sep 17 00:00:00 2001
Patrick Williamsb48b7b42016-08-17 15:04:38 -05002From: Simon Busch <simon.busch@lge.com>
3Date: Wed, 9 Apr 2014 13:18:33 +0200
Brad Bishop316dfdd2018-06-25 12:45:53 -04004Subject: [PATCH] Add functionality to add own objects to internal object
5
Patrick Williamsb48b7b42016-08-17 15:04:38 -05006 list
7
8In some case the tests might want to create dynamically dbus objects which extended
9functionality from own class definitions within templates. In such cases we need to
10register those objects with the internal object manager of dbusmock.
11
12Signed-off-by: Simon Busch <simon.busch@lge.com>
Brad Bishop316dfdd2018-06-25 12:45:53 -040013
Patrick Williamsb48b7b42016-08-17 15:04:38 -050014---
Brad Bishop316dfdd2018-06-25 12:45:53 -040015 dbusmock/__init__.py | 4 ++--
16 dbusmock/mockobject.py | 8 ++++++++
Patrick Williamsb48b7b42016-08-17 15:04:38 -050017 2 files changed, 10 insertions(+), 2 deletions(-)
18
19diff --git a/dbusmock/__init__.py b/dbusmock/__init__.py
Brad Bishop316dfdd2018-06-25 12:45:53 -040020index 8a482ab..3d5d71a 100644
Patrick Williamsb48b7b42016-08-17 15:04:38 -050021--- a/dbusmock/__init__.py
22+++ b/dbusmock/__init__.py
23@@ -14,8 +14,8 @@ __license__ = 'LGPL 3+'
Brad Bishop316dfdd2018-06-25 12:45:53 -040024 __version__ = '0.16.7'
Patrick Williamsb48b7b42016-08-17 15:04:38 -050025
26 from dbusmock.mockobject import (DBusMockObject, MOCK_IFACE,
27- OBJECT_MANAGER_IFACE, get_object, get_objects)
28+ OBJECT_MANAGER_IFACE, get_object, get_objects, add_object)
29 from dbusmock.testcase import DBusTestCase
30
31 __all__ = ['DBusMockObject', 'MOCK_IFACE', 'OBJECT_MANAGER_IFACE',
32- 'DBusTestCase', 'get_object', 'get_objects']
33+ 'DBusTestCase', 'get_object', 'get_objects', 'add_object']
34diff --git a/dbusmock/mockobject.py b/dbusmock/mockobject.py
Brad Bishop316dfdd2018-06-25 12:45:53 -040035index 586dbad..e4f130f 100644
Patrick Williamsb48b7b42016-08-17 15:04:38 -050036--- a/dbusmock/mockobject.py
37+++ b/dbusmock/mockobject.py
Brad Bishop316dfdd2018-06-25 12:45:53 -040038@@ -688,6 +688,14 @@ dbus.service._method_lookup = _dbusmock_method_lookup
Patrick Williamsb48b7b42016-08-17 15:04:38 -050039 # Helper API for templates
40 #
41
42+def add_object(path, obj):
43+ if path in objects:
44+ raise dbus.exceptions.DBusException(
45+ 'org.freedesktop.DBus.Mock.NameError',
46+ 'object %s already exists' % path)
47+
48+ objects[path] = obj
49+
50
51 def get_objects():
52 '''Return all existing object paths'''