Merge lp:~3v1n0/autopilot/badwindow-errors-protect-legacy into lp:autopilot/legacy

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Andrea Azzarone
Approved revision: 498
Merged at revision: 498
Proposed branch: lp:~3v1n0/autopilot/badwindow-errors-protect-legacy
Merge into: lp:autopilot/legacy
Diff against target: 149 lines (+34/-30)
6 files modified
autopilot/process/_bamf.py (+30/-6)
autopilot/tests/unit/test_platform.py (+2/-2)
autopilot/tests/unit/test_testresults.py (+1/-1)
bin/autopilot-sandbox-run (+1/-2)
debian/patches/sandbox_run_exit.patch (+0/-18)
debian/patches/series (+0/-1)
To merge this branch: bzr merge lp:~3v1n0/autopilot/badwindow-errors-protect-legacy
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
Autopilot Hackers Pending
Review via email: mp+268995@code.launchpad.net

Commit message

Bamf: protect from BadWindow errors when getting the title

A bamf window might be still on bus, but actually closed at X level,
so we must protect from errors when trying to fetch properties.

To post a comment you must log in.
Revision history for this message
Andrea Azzarone (azzar1) wrote :

LGTM.

review: Approve
499. By Marco Trevisan (Treviño)

tests: fix failing unit tests

500. By Martin Pitt

Fix autopilot3-sandbox-run exit status.

If autopilot fails with a non-zero exit code, capture this in $RC, instead of
capturing the exit status of "echo" (which will always succeed).

501. By Marco Trevisan (Treviño)

debian: remove downstream patches, as they're merged now

502. By Marco Trevisan (Treviño)

Bamf: avoid to crash on __repr__ because of unreachable view

503. By Marco Trevisan (Treviño)

Bamf: set proper __eq__ and __neq__ operators

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'autopilot/process/_bamf.py'
2--- autopilot/process/_bamf.py 2014-04-07 23:25:11 +0000
3+++ autopilot/process/_bamf.py 2015-09-11 01:29:21 +0000
4@@ -28,7 +28,7 @@
5 from gi.repository import GLib
6 import logging
7 import os
8-from Xlib import display, X, protocol
9+from Xlib import display, X, protocol, error as Xerror
10 from subprocess import check_output, CalledProcessError, call
11
12 from autopilot.dbus_handler import get_session_bus
13@@ -426,13 +426,20 @@
14 return [Window(w) for w in self._view_iface.Children()]
15
16 def __repr__(self):
17- return "<Application '%s'>" % (self.name)
18+ try:
19+ name = self.name
20+ except:
21+ name = self.bamf_app_path
22+ return "<Application '%s'>" % (name)
23
24 def __eq__(self, other):
25- if other is None:
26+ if not isinstance(other, self.__class__):
27 return False
28 return self.desktop_file == other.desktop_file
29
30+ def __ne__(self, other):
31+ return not self.__eq__(other)
32+
33
34 class Window(WindowBase):
35 """Represents an application window, as returned by Bamf.
36@@ -484,7 +491,10 @@
37 .. note:: This may change depending on the current locale.
38
39 """
40- return self._getProperty('_NET_WM_NAME')
41+ try:
42+ return self._getProperty('_NET_WM_NAME')
43+ except Xerror.BadWindow:
44+ return self.name
45
46 @property
47 def geometry(self):
48@@ -592,8 +602,22 @@
49 self._x_win.configure(stack_mode=X.Above)
50
51 def __repr__(self):
52- return "<Window '%s' Xid: %d>" % (
53- self.title if self._x_win else '', self.x_id)
54+ try:
55+ title = self.title
56+ except:
57+ title = self._bamf_win_path
58+
59+ return "<Window '%s' Xid: %d>" % (title, self.x_id)
60+
61+ def __eq__(self, other):
62+ if not isinstance(other, self.__class__):
63+ return False
64+ if self.x_id and other.x_id:
65+ return self.x_id == other.x_id
66+ return self._bamf_win_path == other._bamf_win_path
67+
68+ def __ne__(self, other):
69+ return not self.__eq__(other)
70
71 def _getProperty(self, _type):
72 """Get an X11 property.
73
74=== modified file 'autopilot/tests/unit/test_platform.py'
75--- autopilot/tests/unit/test_platform.py 2014-01-27 22:23:58 +0000
76+++ autopilot/tests/unit/test_platform.py 2015-09-11 01:29:21 +0000
77@@ -39,7 +39,7 @@
78 @patch('autopilot.platform._PlatformDetector')
79 def test_model_creates_platform_detector(self, mock_detector):
80 platform.model()
81- mock_detector.create.assert_called_once()
82+ mock_detector.create.assert_called_once_with()
83
84 @patch('autopilot.platform._PlatformDetector._cached_detector')
85 def test_model_returns_correct_value(self, mock_detector):
86@@ -49,7 +49,7 @@
87 @patch('autopilot.platform._PlatformDetector')
88 def test_image_codename_creates_platform_detector(self, mock_detector):
89 platform.image_codename()
90- mock_detector.create.assert_called_once()
91+ mock_detector.create.assert_called_once_with()
92
93 @patch('autopilot.platform._PlatformDetector._cached_detector')
94 def test_image_codename_returns_correct_value(self, mock_detector):
95
96=== modified file 'autopilot/tests/unit/test_testresults.py'
97--- autopilot/tests/unit/test_testresults.py 2014-02-26 02:18:50 +0000
98+++ autopilot/tests/unit/test_testresults.py 2015-09-11 01:29:21 +0000
99@@ -34,7 +34,7 @@
100 class LoggedTestResultDecoratorTests(TestCase):
101
102 def construct_simple_content_object(self):
103- return text_content(self.getUniqueString)
104+ return text_content(self.getUniqueString())
105
106 def test_can_construct(self):
107 testresult.LoggedTestResultDecorator(Mock())
108
109=== modified file 'bin/autopilot-sandbox-run'
110--- bin/autopilot-sandbox-run 2013-09-13 14:00:56 +0000
111+++ bin/autopilot-sandbox-run 2015-09-11 01:29:21 +0000
112@@ -173,6 +173,5 @@
113 export XAUTHORITY=/dev/null
114 wait_for_x $SERVERNUM
115 echo "I: Starting autopilot"
116-dbus-launch --exit-with-session autopilot run $AP_OPT $TESTLIST
117+dbus-launch --exit-with-session autopilot run $AP_OPT $TESTLIST || RC=$?
118 echo "I: autopilot tests done"
119-RC=$?
120
121=== removed directory 'debian/patches'
122=== removed file 'debian/patches/sandbox_run_exit.patch'
123--- debian/patches/sandbox_run_exit.patch 2014-08-06 05:48:00 +0000
124+++ debian/patches/sandbox_run_exit.patch 1970-01-01 00:00:00 +0000
125@@ -1,18 +0,0 @@
126-Description: Fix autopilot3-sandbox-run exit status.
127- If autopilot fails with a non-zero exit code, capture this in $RC, instead of
128- capturing the exit status of "echo" (which will always succeed).
129-Origin: Backport of https://code.launchpad.net/~pitti/autopilot/sandbox-run/+merge/219638.
130-Author: Martin Pitt <martin.pitt@ubuntu.com>
131-
132-Index: autopilot-legacy-1.4.1+14.10.20140430/bin/autopilot-sandbox-run
133-===================================================================
134---- autopilot-legacy-1.4.1+14.10.20140430.orig/bin/autopilot-sandbox-run
135-+++ autopilot-legacy-1.4.1+14.10.20140430/bin/autopilot-sandbox-run
136-@@ -173,6 +173,5 @@ export DISPLAY=:${SERVERNUM}.0
137- export XAUTHORITY=/dev/null
138- wait_for_x $SERVERNUM
139- echo "I: Starting autopilot"
140--dbus-launch --exit-with-session autopilot run $AP_OPT $TESTLIST
141-+dbus-launch --exit-with-session autopilot run $AP_OPT $TESTLIST || RC=$?
142- echo "I: autopilot tests done"
143--RC=$?
144
145=== removed file 'debian/patches/series'
146--- debian/patches/series 2014-08-06 05:48:00 +0000
147+++ debian/patches/series 1970-01-01 00:00:00 +0000
148@@ -1,1 +0,0 @@
149-sandbox_run_exit.patch

Subscribers

People subscribed via source and target branches