blob: fdd00b6a4dd9be167e69bf19d562c353d13fd7c8 [file] [log] [blame]
Patrick Williamsb48b7b42016-08-17 15:04:38 -05001From eebe0f66435c4d821b0f5f93f69efe17b4a384c2 Mon Sep 17 00:00:00 2001
2From: Simon Busch <simon.busch@lge.com>
3Date: Wed, 9 Apr 2014 13:18:33 +0200
4Subject: [PATCH 1/2] Add functionality to add own objects to internal object
5 list
6
7In some case the tests might want to create dynamically dbus objects which extended
8functionality from own class definitions within templates. In such cases we need to
9register those objects with the internal object manager of dbusmock.
10
11Signed-off-by: Simon Busch <simon.busch@lge.com>
12---
13 dbusmock/__init__.py | 4 ++--
14 dbusmock/mockobject.py | 8 ++++++++
15 2 files changed, 10 insertions(+), 2 deletions(-)
16
17diff --git a/dbusmock/__init__.py b/dbusmock/__init__.py
18index f799cc7..6718c06 100644
19--- a/dbusmock/__init__.py
20+++ b/dbusmock/__init__.py
21@@ -14,8 +14,8 @@ __license__ = 'LGPL 3+'
22 __version__ = '0.10.1'
23
24 from dbusmock.mockobject import (DBusMockObject, MOCK_IFACE,
25- OBJECT_MANAGER_IFACE, get_object, get_objects)
26+ OBJECT_MANAGER_IFACE, get_object, get_objects, add_object)
27 from dbusmock.testcase import DBusTestCase
28
29 __all__ = ['DBusMockObject', 'MOCK_IFACE', 'OBJECT_MANAGER_IFACE',
30- 'DBusTestCase', 'get_object', 'get_objects']
31+ 'DBusTestCase', 'get_object', 'get_objects', 'add_object']
32diff --git a/dbusmock/mockobject.py b/dbusmock/mockobject.py
33index 97b79ce..a98e03d 100644
34--- a/dbusmock/mockobject.py
35+++ b/dbusmock/mockobject.py
36@@ -682,6 +682,14 @@ dbus.service._method_lookup = _dbusmock_method_lookup
37 # Helper API for templates
38 #
39
40+def add_object(path, obj):
41+ if path in objects:
42+ raise dbus.exceptions.DBusException(
43+ 'org.freedesktop.DBus.Mock.NameError',
44+ 'object %s already exists' % path)
45+
46+ objects[path] = obj
47+
48
49 def get_objects():
50 '''Return all existing object paths'''
51--
521.7.9.5
53