Merge lp:~diegosarmentero/ubuntuone-control-panel/fix-reactor into lp:ubuntuone-control-panel

Proposed by Diego Sarmentero on 2012-01-02
Status: Merged
Approved by: Diego Sarmentero on 2012-01-03
Approved revision: 251
Merged at revision: 249
Proposed branch: lp:~diegosarmentero/ubuntuone-control-panel/fix-reactor
Merge into: lp:ubuntuone-control-panel
Diff against target: 254 lines (+126/-124)
1 file modified
ubuntuone/controlpanel/gui/qt/tests/test_systray.py (+126/-124)
To merge this branch: bzr merge lp:~diegosarmentero/ubuntuone-control-panel/fix-reactor
Reviewer Review Type Date Requested Status
Alejandro J. Cura (community) Approve on 2012-01-02
Roberto Alsina (community) 2012-01-02 Approve on 2012-01-02
Review via email: mp+87267@code.launchpad.net

Commit Message

Fix dirty reactor.

Description of the Change

Fix dirty reactor.

To post a comment you must log in.
250. By Diego Sarmentero on 2012-01-02

Fixing lint issues

251. By Diego Sarmentero on 2012-01-02

Fixed reactor

Roberto Alsina (ralsina) wrote :

+1 tested on windows

review: Approve
Alejandro J. Cura (alecu) wrote :

A lot of red and green, but it's really only a small change.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntuone/controlpanel/gui/qt/tests/test_systray.py'
2--- ubuntuone/controlpanel/gui/qt/tests/test_systray.py 2011-12-27 14:52:45 +0000
3+++ ubuntuone/controlpanel/gui/qt/tests/test_systray.py 2012-01-02 19:41:23 +0000
4@@ -1,124 +1,126 @@
5-# -*- coding: utf-8 -*-
6-
7-# Author: Roberto Alsina <roberto.alsina@canonical.com>
8-#
9-# Copyright 2011 Canonical Ltd.
10-#
11-# This program is free software: you can redistribute it and/or modify it
12-# under the terms of the GNU General Public License version 3, as published
13-# by the Free Software Foundation.
14-#
15-# This program is distributed in the hope that it will be useful, but
16-# WITHOUT ANY WARRANTY; without even the implied warranties of
17-# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
18-# PURPOSE. See the GNU General Public License for more details.
19-#
20-# You should have received a copy of the GNU General Public License along
21-# with this program. If not, see <http://www.gnu.org/licenses/>.
22-
23-"""Tests for the notification area icon."""
24-
25-from PyQt4 import QtGui
26-from twisted.internet.defer import inlineCallbacks
27-
28-from ubuntuone.controlpanel.gui.qt import systray
29-from ubuntuone.controlpanel.tests import TestCase
30-import ubuntuone.controlpanel.gui.qt.gui
31-
32-
33-class FakeSDTool(object):
34-
35- """Fake SyncDaemonTool."""
36-
37- called = False
38-
39- def quit(self):
40- """Fake quit."""
41- self.called = True
42-
43-
44-class FakeMainWindow(QtGui.QWidget):
45-
46- """Fake Main Window."""
47-
48- def __init__(self, *args, **kwargs):
49- self.args = (args, kwargs)
50- super(FakeMainWindow, self).__init__()
51-
52-
53-class SystrayTestCase(TestCase):
54-
55- """Test the notification area icon."""
56-
57- def test_quit(self):
58- """Test the quit option in the menu."""
59- # Not done on setup, because if I patch stop
60- # after instantiation, it doesn't get called.
61- self.patch(systray.TrayIcon, "stop", self._set_called)
62- tray = systray.TrayIcon()
63- tray.quit.trigger()
64- self.assertEqual(self._called, ((False,), {}))
65-
66- @inlineCallbacks
67- def test_stop_sd(self):
68- """Quit should call SyncDaemonTool.quit()."""
69- st = FakeSDTool()
70- self.patch(systray, "SyncDaemonTool", lambda: st)
71- tray = systray.TrayIcon()
72- yield tray.stop()
73- self.assertTrue(st.called)
74-
75- def test_restore_no_window(self):
76- """Test the restore window option in the menu, with no window."""
77- self.patch(ubuntuone.controlpanel.gui.qt.gui,
78- "MainWindow", FakeMainWindow)
79- tray = systray.TrayIcon()
80- self.assertEqual(tray.window, None)
81- tray.restore.trigger()
82- self.assertIsInstance(tray.window, FakeMainWindow)
83- self.assertTrue(tray.window.isVisible())
84- self.assertEqual(tray.window.args, ((),
85- {'close_callback': tray.delete_window}))
86-
87- def test_activate(self):
88- """Test the icon activation."""
89- tray = systray.TrayIcon()
90- window = FakeMainWindow()
91- tray.window = window
92- self.assertFalse(tray.window.isVisible())
93- tray.activated.emit(tray.Trigger)
94- self.assertEqual(tray.window, window)
95- self.assertTrue(tray.window.isVisible())
96-
97- def test_restore_window(self):
98- """Test the restore window option in the menu, with a window."""
99- tray = systray.TrayIcon()
100- window = FakeMainWindow()
101- tray.window = window
102- self.assertFalse(tray.window.isVisible())
103- tray.restore.trigger()
104- self.assertEqual(tray.window, window)
105- self.assertTrue(tray.window.isVisible())
106-
107- def test_delete_window(self):
108- """Test deleting an existing window."""
109- tray = systray.TrayIcon()
110- window = FakeMainWindow()
111- tray.window = window
112- tray.delete_window()
113- self.assertEqual(tray.window, None)
114- self.assertFalse(window.isVisible())
115-
116- def test_delete_no_window(self):
117- """Test deleting without an existing window."""
118- tray = systray.TrayIcon()
119- tray.delete_window()
120- self.assertEqual(tray.window, None)
121-
122- def test_initialization(self):
123- """Test that everything initializes correctly."""
124- tray = systray.TrayIcon()
125- self.assertTrue(tray.isVisible())
126- self.assertEqual(tray.window, None)
127- self.assertIsInstance(tray.context_menu, QtGui.QMenu)
128- self.assertFalse(tray.icon() == None)
129+# -*- coding: utf-8 -*-
130+
131+# Author: Roberto Alsina <roberto.alsina@canonical.com>
132+#
133+# Copyright 2011 Canonical Ltd.
134+#
135+# This program is free software: you can redistribute it and/or modify it
136+# under the terms of the GNU General Public License version 3, as published
137+# by the Free Software Foundation.
138+#
139+# This program is distributed in the hope that it will be useful, but
140+# WITHOUT ANY WARRANTY; without even the implied warranties of
141+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
142+# PURPOSE. See the GNU General Public License for more details.
143+#
144+# You should have received a copy of the GNU General Public License along
145+# with this program. If not, see <http://www.gnu.org/licenses/>.
146+
147+"""Tests for the notification area icon."""
148+
149+from PyQt4 import QtGui
150+from twisted.internet import reactor
151+from twisted.internet.defer import inlineCallbacks
152+
153+from ubuntuone.controlpanel.gui.qt import systray
154+from ubuntuone.controlpanel.tests import TestCase
155+import ubuntuone.controlpanel.gui.qt.gui
156+
157+
158+class FakeSDTool(object):
159+
160+ """Fake SyncDaemonTool."""
161+
162+ called = False
163+
164+ def quit(self):
165+ """Fake quit."""
166+ self.called = True
167+
168+
169+class FakeMainWindow(QtGui.QWidget):
170+
171+ """Fake Main Window."""
172+
173+ def __init__(self, *args, **kwargs):
174+ self.args = (args, kwargs)
175+ super(FakeMainWindow, self).__init__()
176+
177+
178+class SystrayTestCase(TestCase):
179+
180+ """Test the notification area icon."""
181+
182+ def test_quit(self):
183+ """Test the quit option in the menu."""
184+ # Not done on setup, because if I patch stop
185+ # after instantiation, it doesn't get called.
186+ self.patch(systray.TrayIcon, "stop", self._set_called)
187+ tray = systray.TrayIcon()
188+ tray.quit.trigger()
189+ self.assertEqual(self._called, ((False,), {}))
190+
191+ @inlineCallbacks
192+ def test_stop_sd(self):
193+ """Quit should call SyncDaemonTool.quit()."""
194+ st = FakeSDTool()
195+ self.patch(systray, "SyncDaemonTool", lambda: st)
196+ self.patch(reactor, "stop", lambda: None)
197+ tray = systray.TrayIcon()
198+ yield tray.stop()
199+ self.assertTrue(st.called)
200+
201+ def test_restore_no_window(self):
202+ """Test the restore window option in the menu, with no window."""
203+ self.patch(ubuntuone.controlpanel.gui.qt.gui,
204+ "MainWindow", FakeMainWindow)
205+ tray = systray.TrayIcon()
206+ self.assertEqual(tray.window, None)
207+ tray.restore.trigger()
208+ self.assertIsInstance(tray.window, FakeMainWindow)
209+ self.assertTrue(tray.window.isVisible())
210+ self.assertEqual(tray.window.args, ((),
211+ {'close_callback': tray.delete_window}))
212+
213+ def test_activate(self):
214+ """Test the icon activation."""
215+ tray = systray.TrayIcon()
216+ window = FakeMainWindow()
217+ tray.window = window
218+ self.assertFalse(tray.window.isVisible())
219+ tray.activated.emit(tray.Trigger)
220+ self.assertEqual(tray.window, window)
221+ self.assertTrue(tray.window.isVisible())
222+
223+ def test_restore_window(self):
224+ """Test the restore window option in the menu, with a window."""
225+ tray = systray.TrayIcon()
226+ window = FakeMainWindow()
227+ tray.window = window
228+ self.assertFalse(tray.window.isVisible())
229+ tray.restore.trigger()
230+ self.assertEqual(tray.window, window)
231+ self.assertTrue(tray.window.isVisible())
232+
233+ def test_delete_window(self):
234+ """Test deleting an existing window."""
235+ tray = systray.TrayIcon()
236+ window = FakeMainWindow()
237+ tray.window = window
238+ tray.delete_window()
239+ self.assertEqual(tray.window, None)
240+ self.assertFalse(window.isVisible())
241+
242+ def test_delete_no_window(self):
243+ """Test deleting without an existing window."""
244+ tray = systray.TrayIcon()
245+ tray.delete_window()
246+ self.assertEqual(tray.window, None)
247+
248+ def test_initialization(self):
249+ """Test that everything initializes correctly."""
250+ tray = systray.TrayIcon()
251+ self.assertTrue(tray.isVisible())
252+ self.assertEqual(tray.window, None)
253+ self.assertIsInstance(tray.context_menu, QtGui.QMenu)
254+ self.assertFalse(tray.icon() == None)

Subscribers

People subscribed via source and target branches