Merge lp:~nskaggs/autopilot/catch-stateerror-printtree into lp:autopilot

Proposed by Thomi Richards
Status: Superseded
Proposed branch: lp:~nskaggs/autopilot/catch-stateerror-printtree
Merge into: lp:autopilot
Prerequisite: lp:~thomir-deactivatedaccount/autopilot/trunk-make-print-tree-faster
Diff against target: 68 lines (+28/-6)
2 files modified
autopilot/introspection/dbus.py (+10/-6)
autopilot/tests/unit/test_introspection_features.py (+18/-0)
To merge this branch: bzr merge lp:~nskaggs/autopilot/catch-stateerror-printtree
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Thomi Richards Pending
Max Brustkern Pending
Nicholas Skaggs Pending
Chris Gagnon Pending
Review via email: mp+214616@code.launchpad.net

Commit message

Don't abort print_tree when we catch StateNotFoundError exception.

Description of the change

Dumping the object tree with print_tree often fails to complete due to StateNotFound errors. This modifies the print call to catch these errors and continue to print the largest possible tree. Other errors could be considered as well to try and print as complete a dump as possible.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'autopilot/introspection/dbus.py'
2--- autopilot/introspection/dbus.py 2014-04-01 00:44:23 +0000
3+++ autopilot/introspection/dbus.py 2014-04-07 21:35:38 +0000
4@@ -262,6 +262,7 @@
5 # Thomi: 2014-03-20: There used to be a call to 'self.refresh_state()'
6 # here. That's not needed, since the only thing we use is the proxy
7 # path, which isn't affected by the current state.
8+
9 query = self.get_class_query_string() + "/*"
10 state_dicts = self.get_state_by_path(query)
11 children = [self.make_introspection_object(i) for i in state_dicts]
12@@ -652,12 +653,15 @@
13 else:
14 properties = self.get_properties()
15 # print properties
16- for key in sorted(properties.keys()):
17- output.write("%s%s: %r\n" % (indent, key, properties[key]))
18- # print children
19- if maxdepth is None or _curdepth < maxdepth:
20- for c in self.get_children():
21- c.print_tree(output, maxdepth, _curdepth + 1)
22+ try:
23+ for key in sorted(properties.keys()):
24+ output.write("%s%s: %r\n" % (indent, key, properties[key]))
25+ # print children
26+ if maxdepth is None or _curdepth < maxdepth:
27+ for c in self.get_children():
28+ c.print_tree(output, maxdepth, _curdepth + 1)
29+ except StateNotFoundError as error:
30+ output.write("%sError: %s\n" % (indent, error))
31
32 @contextmanager
33 def no_automatic_refreshing(self):
34
35=== modified file 'autopilot/tests/unit/test_introspection_features.py'
36--- autopilot/tests/unit/test_introspection_features.py 2014-04-01 01:30:00 +0000
37+++ autopilot/tests/unit/test_introspection_features.py 2014-04-07 21:35:38 +0000
38@@ -61,6 +61,7 @@
39 _try_custom_proxy_classes,
40 CustomEmulatorBase,
41 DBusIntrospectionObject,
42+ StateNotFoundError,
43 )
44 from autopilot.introspection.qt import QtObjectProxyMixin
45 import autopilot.introspection as _i
46@@ -313,6 +314,23 @@
47 text: 'Hello'
48 """))
49
50+ def test_print_tree_exception(self):
51+ """print_tree with StateNotFound exception"""
52+
53+ fake_object = self._print_test_fake_object()
54+ child = Mock()
55+ child.print_tree.side_effect = StateNotFoundError('child')
56+
57+ with patch.object(fake_object, 'get_children', return_value=[child]):
58+ out = StringIO()
59+ print_func = lambda: fake_object.print_tree(out)
60+ self.assertThat(print_func, Not(Raises(StateNotFoundError)))
61+ self.assertEqual(out.getvalue(), dedent("""\
62+ == /some/path ==
63+ id: 123
64+ Error: Object not found with name 'child'.
65+ """))
66+
67 def test_print_tree_fileobj(self):
68 """print_tree with file object output"""
69

Subscribers

People subscribed via source and target branches