Merge lp:~mikemc/ubuntuone-control-panel/fix-1015825-reorder-reactor into lp:ubuntuone-control-panel

Proposed by Mike McCracken on 2012-06-27
Status: Merged
Approved by: Alejandro J. Cura on 2012-06-28
Approved revision: 340
Merged at revision: 335
Proposed branch: lp:~mikemc/ubuntuone-control-panel/fix-1015825-reorder-reactor
Merge into: lp:ubuntuone-control-panel
Diff against target: 98 lines (+48/-3)
3 files modified
bin/ubuntuone-control-panel-qt (+2/-2)
ubuntuone/controlpanel/gui/qt/main/__init__.py (+13/-1)
ubuntuone/controlpanel/gui/qt/main/tests/test_main.py (+33/-0)
To merge this branch: bzr merge lp:~mikemc/ubuntuone-control-panel/fix-1015825-reorder-reactor
Reviewer Review Type Date Requested Status
Manuel de la Peña (community) Approve on 2012-06-28
Diego Sarmentero (community) 2012-06-27 Approve on 2012-06-28
Review via email: mp+112432@code.launchpad.net

Commit Message

- On Darwin, install qt4reactor after QApplication is created. (LP: #1015825)

Description of the Change

- On Darwin, install qt4reactor after QApplication is created. (LP: #1015825)

To post a comment you must log in.
339. By Mike McCracken on 2012-06-28

Refactor and add tests for installing qt4reactor in main on darwin.

340. By Mike McCracken on 2012-06-28

fix pep8 complaints

Mike McCracken (mikemc) wrote :

Tests added using alecu's suggestion to make the import testable - encapsulate import & install into a patch-able function.

Patched sys.platform in these new tests so they work on all platforms.

Diego Sarmentero (diegosarmentero) wrote :

+1

review: Approve
Manuel de la Peña (mandel) wrote :

I've ran the ui and works prefectly, I'll +1.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/ubuntuone-control-panel-qt'
2--- bin/ubuntuone-control-panel-qt 2012-06-15 21:28:44 +0000
3+++ bin/ubuntuone-control-panel-qt 2012-06-28 04:27:18 +0000
4@@ -22,7 +22,7 @@
5 import signal
6 import sys
7
8-if sys.platform in ('win32', 'darwin'):
9+if sys.platform == 'win32':
10 import qt4reactor
11 qt4reactor.install()
12
13@@ -31,4 +31,4 @@
14
15 if __name__ == "__main__":
16 signal.signal(signal.SIGINT, signal.SIG_DFL)
17- main.main(sys.argv)
18+ main.main(sys.argv, install_reactor_darwin=True)
19
20=== modified file 'ubuntuone/controlpanel/gui/qt/main/__init__.py'
21--- ubuntuone/controlpanel/gui/qt/main/__init__.py 2012-06-15 22:02:39 +0000
22+++ ubuntuone/controlpanel/gui/qt/main/__init__.py 2012-06-28 04:27:18 +0000
23@@ -61,7 +61,13 @@
24 return result
25
26
27-def main(args):
28+def install_qt4reactor():
29+ """Import and install the qt4reactor."""
30+ import qt4reactor
31+ qt4reactor.install()
32+
33+
34+def main(args, install_reactor_darwin=False):
35 """Start the Qt mainloop and open the main window."""
36 # The following cannot be imported outside this function
37 # because u1trial already provides a reactor.
38@@ -69,6 +75,12 @@
39 args = ['ubuntuone-installer'] + args
40 app = UniqueApplication(args, "ubuntuone-control-panel")
41
42+ # on darwin, must install qt4reactor after UniqueApplication init.
43+ # otherwise qt4reactor will create a QCoreApplication for us,
44+ # instead of the QApplication we need
45+ if install_reactor_darwin and sys.platform == 'darwin':
46+ install_qt4reactor()
47+
48 # Install translator for standard dialogs.
49 locale = unicode(QtCore.QLocale.system().name())
50 translator = QtCore.QTranslator()
51
52=== modified file 'ubuntuone/controlpanel/gui/qt/main/tests/test_main.py'
53--- ubuntuone/controlpanel/gui/qt/main/tests/test_main.py 2012-05-14 22:30:47 +0000
54+++ ubuntuone/controlpanel/gui/qt/main/tests/test_main.py 2012-06-28 04:27:18 +0000
55@@ -130,6 +130,15 @@
56 self.patch(main.source, "main_start", lambda app: None)
57 self.patch(QtCore, "QTranslator", lambda: self.translator)
58
59+ self.qt4reactor_installed = False
60+
61+ def fake_install_qt4reactor():
62+ """Record the install without importing."""
63+ self.qt4reactor_installed = True
64+
65+ self.patch(main, "install_qt4reactor",
66+ fake_install_qt4reactor)
67+
68 def test_wm_class(self):
69 """Test that we set the 1st argument, used for WM_CLASS, correctly."""
70 main.main([sys.argv[0]])
71@@ -200,3 +209,27 @@
72 main.main([sys.argv[0]])
73 self.assertEqual(self.app.new_instance.target,
74 self.start.window.raise_)
75+
76+ def test_darwin_installs_qt4reactor(self):
77+ """Ensure the qt4 reactor is installed when requested."""
78+ self.patch(sys, 'platform', 'darwin')
79+ main.main([sys.argv[0]], install_reactor_darwin=True)
80+ self.assertEqual(self.qt4reactor_installed, True)
81+
82+ def test_darwin_doesnt_install_qt4reactor(self):
83+ """Ensure the qt4 reactor isn't installed by default."""
84+ self.patch(sys, 'platform', 'darwin')
85+ main.main([sys.argv[0]])
86+ self.assertEqual(self.qt4reactor_installed, False)
87+
88+ def test_nondarwin_ignores_true_install_flag(self):
89+ """Ensure the qt4 reactor isn't installed on non-darwin."""
90+ self.patch(sys, 'platform', 'not-darwin')
91+ main.main([sys.argv[0]], install_reactor_darwin=True)
92+ self.assertEqual(self.qt4reactor_installed, False)
93+
94+ def test_nondarwin_ignores_false_install_flag(self):
95+ """Ensure the qt4 reactor isn't installed on non-darwin."""
96+ self.patch(sys, 'platform', 'not-darwin')
97+ main.main([sys.argv[0]], install_reactor_darwin=False)
98+ self.assertEqual(self.qt4reactor_installed, False)

Subscribers

People subscribed via source and target branches