Merge lp:~veebers/autopilot/introspection-using-paths into lp:autopilot

Proposed by Christopher Lee
Status: Merged
Approved by: Thomi Richards
Approved revision: 167
Merged at revision: 165
Proposed branch: lp:~veebers/autopilot/introspection-using-paths
Merge into: lp:autopilot
Diff against target: 148 lines (+21/-33)
3 files modified
autopilot/introspection/__init__.py (+3/-1)
autopilot/introspection/dbus.py (+16/-30)
debian/control (+2/-2)
To merge this branch: bzr merge lp:~veebers/autopilot/introspection-using-paths
Reviewer Review Type Date Requested Status
Thomi Richards (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+159995@code.launchpad.net

Commit message

Changes to xpathselect mean that the dbus tuple returns the objects full path (was just the object name).

Description of the change

Changes to xpathselect mean that the dbus tuple returns the objects full path (was just the object name).

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
166. By Christopher Lee

fix use of path_info

167. By Christopher Lee

Update recommends version

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'autopilot/introspection/__init__.py'
2--- autopilot/introspection/__init__.py 2013-04-12 03:53:14 +0000
3+++ autopilot/introspection/__init__.py 2013-04-22 02:07:28 +0000
4@@ -32,6 +32,7 @@
5 DBusIntrospectionObject,
6 object_passes_filters,
7 get_session_bus,
8+ get_classname_from_path,
9 )
10 from autopilot.utilities import get_debug_logger, addCleanup
11
12@@ -238,7 +239,8 @@
13 """Return the class name and root state dictionary."""
14 dbus_object = get_session_bus().get_object(service_name, obj_path)
15 dbus_iface = dbus.Interface(dbus_object, AP_INTROSPECTION_IFACE)
16- return dbus_iface.GetState("/")[0]
17+ object_path, object_state = dbus_iface.GetState("/")[0]
18+ return get_classname_from_path(object_path), object_state
19
20
21 class ApplicationProxyObect(DBusIntrospectionObject):
22
23=== modified file 'autopilot/introspection/dbus.py'
24--- autopilot/introspection/dbus.py 2013-04-05 05:10:14 +0000
25+++ autopilot/introspection/dbus.py 2013-04-22 02:07:28 +0000
26@@ -99,6 +99,10 @@
27 return {k.replace('-','_'):v for k,v in state_dict.iteritems() }
28
29
30+def get_classname_from_path(object_path):
31+ return object_path.split("/")[-1]
32+
33+
34 def object_passes_filters(instance, **kwargs):
35 """Return true if *instance* satisifies all the filters present in kwargs."""
36 with instance.no_automatic_refreshing():
37@@ -124,16 +128,11 @@
38 DBUS_SERVICE = None
39 DBUS_OBJECT = None
40
41- def __init__(self, state_dict, path_info=None):
42+ def __init__(self, state_dict, path):
43 self.__state = {}
44 self.__refresh_on_attribute = True
45 self.set_properties(state_dict)
46- if path_info is None:
47- logger.warning("Constructing object '%s' without path information. This will make \
48-queries on this object, and all child objects considerably slower." % self.__class__.__name__)
49- logger.warning("To avoid this, make sure objects are _not_ constructed with the \
50-get_all_instances(...) class method.")
51- self.path_info = path_info
52+ self.path = path
53
54 def set_properties(self, state_dict):
55 """Creates and set attributes of *self* based on contents of *state_dict*.
56@@ -180,7 +179,7 @@
57
58 time_left = timeout
59 while True:
60- name, new_state = self.parent.get_new_state()
61+ _, new_state = self.parent.get_new_state()
62 new_state = translate_state_keys(new_state)
63 new_value = new_state[self.name]
64 # Support for testtools.matcher classes:
65@@ -274,8 +273,7 @@
66
67 query = self.get_class_query_string() + "/*"
68 state_dicts = self.get_state_by_path(query)
69- path_info = self.path_info + "/" if self.path_info else None
70- children = [self.make_introspection_object(i, path_info) for i in state_dicts]
71+ children = [self.make_introspection_object(i) for i in state_dicts]
72 return children
73
74 def refresh_state(self):
75@@ -284,7 +282,7 @@
76 :raises: **StateNotFound** if the object in unity has been destroyed.
77
78 """
79- name, new_state = self.get_new_state()
80+ _, new_state = self.get_new_state()
81 self.set_properties(new_state)
82
83 @classmethod
84@@ -313,7 +311,7 @@
85 if len(instances) != 1:
86 logger.error("Could not retrieve root object.")
87 return None
88- return cls.make_introspection_object(instances[0], "/")
89+ return cls.make_introspection_object(instances[0])
90
91 def __getattr__(self, name):
92 # avoid recursion if for some reason we have no state set (should never
93@@ -362,34 +360,22 @@
94
95 def get_class_query_string(self):
96 """Get the XPath query string required to refresh this class's state."""
97- if self.path_info is None:
98- return "//%s[id=%d]" % (self.__class__.__name__, self.id)
99- else:
100- return self.path_info + "[id=%d]" % self.id
101+ return self.path + "[id=%d]" % self.id
102
103 @classmethod
104- def make_introspection_object(cls, dbus_tuple, path_info=None):
105- """Make an introspection object given a DBus tuple of (name, state_dict).
106-
107- The optional 'path_info' parameter can be set to a string that contains
108- the full, absolute path in the introspection tree to this object.
109+ def make_introspection_object(cls, dbus_tuple):
110+ """Make an introspection object given a DBus tuple of (path, state_dict).
111
112 This only works for classes that derive from DBusIntrospectionObject.
113 """
114- name, state = dbus_tuple
115+ path, state = dbus_tuple
116+ name = get_classname_from_path(path)
117 try:
118 class_type = _object_registry[name]
119 except KeyError:
120 logger.warning("Generating introspection instance for type '%s' based on generic class.", name)
121 class_type = type(str(name), (cls,), {})
122- if isinstance(path_info, basestring):
123- if not path_info.endswith(name):
124- if not path_info.endswith("/"):
125- logger.error("path_info must end with '/' or class name.")
126- path_info = None
127- else:
128- path_info += name
129- return class_type(state, path_info)
130+ return class_type(state, path)
131
132 @contextmanager
133 def no_automatic_refreshing(self):
134
135=== modified file 'debian/control'
136--- debian/control 2013-04-17 22:02:14 +0000
137+++ debian/control 2013-04-22 02:07:28 +0000
138@@ -38,8 +38,8 @@
139 python-xdg,
140 python-xlib,
141 python-zeitgeist,
142-Recommends: libautopilot-gtk,
143- libautopilot-qt,
144+Recommends: libautopilot-gtk (>= 1.3),
145+ libautopilot-qt (>= 1.3),
146 Description: Utility to write and run integration tests easily
147 The autopilot engine enables to ease the writing of python tests
148 for your application manipulating your inputs like the mouse and

Subscribers

People subscribed via source and target branches