Merge lp:~thomir-deactivatedaccount/autopilot/catch-stateerror-printtree into lp:autopilot

Proposed by Thomi Richards
Status: Merged
Approved by: Christopher Lee
Approved revision: 446
Merged at revision: 472
Proposed branch: lp:~thomir-deactivatedaccount/autopilot/catch-stateerror-printtree
Merge into: lp:autopilot
Diff against target: 75 lines (+30/-7)
3 files modified
autopilot/introspection/dbus.py (+9/-6)
autopilot/introspection/types.py (+1/-1)
autopilot/tests/unit/test_introspection_features.py (+20/-0)
To merge this branch: bzr merge lp:~thomir-deactivatedaccount/autopilot/catch-stateerror-printtree
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Christopher Lee (community) Approve
Thomi Richards (community) Abstain
Chris Gagnon Pending
Max Brustkern Pending
Nicholas Skaggs Pending
Review via email: mp+214632@code.launchpad.net

Commit message

Don't abort print_tree when we catch the 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
Thomi Richards (thomir-deactivatedaccount) wrote :

LGTM, but since this is now some of my code, I'm abstaining.

review: Abstain
445. By Thomi Richards

Fix flake8 error.

446. By Thomi Richards

Fix test to print all the properties.

Revision history for this message
Christopher Lee (veebers) wrote :

LGTM

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

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 23:07:16 +0000
4@@ -652,12 +652,15 @@
5 else:
6 properties = self.get_properties()
7 # print properties
8- for key in sorted(properties.keys()):
9- output.write("%s%s: %r\n" % (indent, key, properties[key]))
10- # print children
11- if maxdepth is None or _curdepth < maxdepth:
12- for c in self.get_children():
13- c.print_tree(output, maxdepth, _curdepth + 1)
14+ try:
15+ for key in sorted(properties.keys()):
16+ output.write("%s%s: %r\n" % (indent, key, properties[key]))
17+ # print children
18+ if maxdepth is None or _curdepth < maxdepth:
19+ for c in self.get_children():
20+ c.print_tree(output, maxdepth, _curdepth + 1)
21+ except StateNotFoundError as error:
22+ output.write("%sError: %s\n" % (indent, error))
23
24 @contextmanager
25 def no_automatic_refreshing(self):
26
27=== modified file 'autopilot/introspection/types.py'
28--- autopilot/introspection/types.py 2014-04-01 00:46:18 +0000
29+++ autopilot/introspection/types.py 2014-04-07 23:07:16 +0000
30@@ -46,7 +46,7 @@
31 import six
32
33 from autopilot.introspection.utilities import translate_state_keys
34-from autopilot.utilities import sleep, compatible_repr, cached_result
35+from autopilot.utilities import sleep, compatible_repr
36
37
38 logger = logging.getLogger(__name__)
39
40=== modified file 'autopilot/tests/unit/test_introspection_features.py'
41--- autopilot/tests/unit/test_introspection_features.py 2014-04-01 01:30:00 +0000
42+++ autopilot/tests/unit/test_introspection_features.py 2014-04-07 23:07:16 +0000
43@@ -61,6 +61,7 @@
44 _try_custom_proxy_classes,
45 CustomEmulatorBase,
46 DBusIntrospectionObject,
47+ StateNotFoundError,
48 )
49 from autopilot.introspection.qt import QtObjectProxyMixin
50 import autopilot.introspection as _i
51@@ -313,6 +314,25 @@
52 text: 'Hello'
53 """))
54
55+ def test_print_tree_exception(self):
56+ """print_tree with StateNotFound exception"""
57+
58+ fake_object = self._print_test_fake_object()
59+ child = Mock()
60+ child.print_tree.side_effect = StateNotFoundError('child')
61+
62+ with patch.object(fake_object, 'get_children', return_value=[child]):
63+ out = StringIO()
64+ print_func = lambda: fake_object.print_tree(out)
65+ self.assertThat(print_func, Not(Raises(StateNotFoundError)))
66+ self.assertEqual(out.getvalue(), dedent("""\
67+ == /some/path ==
68+ id: 123
69+ path: '/some/path'
70+ text: 'Hello'
71+ Error: Object not found with name 'child'.
72+ """))
73+
74 def test_print_tree_fileobj(self):
75 """print_tree with file object output"""
76

Subscribers

People subscribed via source and target branches