Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame^] | 1 | From eebe0f66435c4d821b0f5f93f69efe17b4a384c2 Mon Sep 17 00:00:00 2001 |
| 2 | From: Simon Busch <simon.busch@lge.com> |
| 3 | Date: Wed, 9 Apr 2014 13:18:33 +0200 |
| 4 | Subject: [PATCH 1/2] Add functionality to add own objects to internal object |
| 5 | list |
| 6 | |
| 7 | In some case the tests might want to create dynamically dbus objects which extended |
| 8 | functionality from own class definitions within templates. In such cases we need to |
| 9 | register those objects with the internal object manager of dbusmock. |
| 10 | |
| 11 | Signed-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 | |
| 17 | diff --git a/dbusmock/__init__.py b/dbusmock/__init__.py |
| 18 | index 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'] |
| 32 | diff --git a/dbusmock/mockobject.py b/dbusmock/mockobject.py |
| 33 | index 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 | -- |
| 52 | 1.7.9.5 |
| 53 | |