Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1 | From c4436fd42f2936e5fb0f95434d06e45aa9959ca0 Mon Sep 17 00:00:00 2001 |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 2 | From: Simon Busch <simon.busch@lge.com> |
| 3 | Date: Wed, 9 Apr 2014 13:18:33 +0200 |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 4 | Subject: [PATCH] Add functionality to add own objects to internal object |
| 5 | |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 6 | list |
| 7 | |
| 8 | In some case the tests might want to create dynamically dbus objects which extended |
| 9 | functionality from own class definitions within templates. In such cases we need to |
| 10 | register those objects with the internal object manager of dbusmock. |
| 11 | |
| 12 | Signed-off-by: Simon Busch <simon.busch@lge.com> |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 13 | |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 14 | --- |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 15 | dbusmock/__init__.py | 4 ++-- |
| 16 | dbusmock/mockobject.py | 8 ++++++++ |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 17 | 2 files changed, 10 insertions(+), 2 deletions(-) |
| 18 | |
| 19 | diff --git a/dbusmock/__init__.py b/dbusmock/__init__.py |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 20 | index 8a482ab..3d5d71a 100644 |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 21 | --- a/dbusmock/__init__.py |
| 22 | +++ b/dbusmock/__init__.py |
| 23 | @@ -14,8 +14,8 @@ __license__ = 'LGPL 3+' |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 24 | __version__ = '0.16.7' |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 25 | |
| 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'] |
| 34 | diff --git a/dbusmock/mockobject.py b/dbusmock/mockobject.py |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 35 | index 586dbad..e4f130f 100644 |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 36 | --- a/dbusmock/mockobject.py |
| 37 | +++ b/dbusmock/mockobject.py |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 38 | @@ -688,6 +688,14 @@ dbus.service._method_lookup = _dbusmock_method_lookup |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 39 | # 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''' |