~ubuntu-branches/ubuntu/raring/ubuntuone-control-panel/raring

« back to all changes in this revision

Viewing changes to .pc/00_scrolled_workaround.patch/ubuntuone/controlpanel/gui/qt/main/tests/test_main.py

  • Committer: Package Import Robot
  • Author(s): Rodney Dawes
  • Date: 2012-08-23 15:19:03 UTC
  • mfrom: (1.1.36)
  • Revision ID: package-import@ubuntu.com-20120823151903-3xm1f1477ut3tqxc
Tags: 3.99.4-0ubuntu1
* New upstream release.
  - Show error for folder subscribe if local path already exists and is not
    a folder. (LP: #1033488)
* debian/copyright:
  - Update to be more in line with dep5.
* debian/patches:
  - Remove patches included upstream.
* debian/rules:
  - Update to allow building directly on older versions of Ubuntu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
#
3
 
# Copyright 2012 Canonical Ltd.
4
 
#
5
 
# This program is free software: you can redistribute it and/or modify it
6
 
# under the terms of the GNU General Public License version 3, as published
7
 
# by the Free Software Foundation.
8
 
#
9
 
# This program is distributed in the hope that it will be useful, but
10
 
# WITHOUT ANY WARRANTY; without even the implied warranties of
11
 
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12
 
# PURPOSE.  See the GNU General Public License for more details.
13
 
#
14
 
# You should have received a copy of the GNU General Public License along
15
 
# with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 
 
17
 
"""Tests for the control panel's Qt main."""
18
 
 
19
 
import sys
20
 
 
21
 
from PyQt4 import QtCore
22
 
from twisted.internet.defer import inlineCallbacks
23
 
 
24
 
from ubuntuone.controlpanel.gui.qt import main
25
 
from ubuntuone.controlpanel.tests import TestCase
26
 
from ubuntuone.controlpanel.gui.tests import FakeSignal
27
 
 
28
 
 
29
 
class FakeTranslator(object):
30
 
 
31
 
    """A fake QTranslator."""
32
 
 
33
 
    args = None
34
 
 
35
 
    def load(self, *args, **kwargs):
36
 
        """fake load."""
37
 
        self.args = (args, kwargs)
38
 
 
39
 
 
40
 
class FakeApplication(object):
41
 
 
42
 
    """A fake application."""
43
 
 
44
 
    def __init__(self):
45
 
        self.args = None
46
 
        self.style = None
47
 
        self.translator = None
48
 
        self.new_instance = FakeSignal()
49
 
 
50
 
    def __call__(self, argv, *args, **kwargs):
51
 
        """Fake arg filtering function."""
52
 
        if '-title' in argv:
53
 
            argv.remove('-title')
54
 
        self.args = (argv, args, kwargs)
55
 
        return self
56
 
 
57
 
    # pylint: disable=C0103
58
 
    def setStyleSheet(self, *args, **kwargs):
59
 
        """Fake setStyleSheet."""
60
 
        self.style = (args, kwargs)
61
 
 
62
 
    def installTranslator(self, translator):
63
 
        """Fake installTranslator."""
64
 
        self.translator = translator
65
 
 
66
 
    def isRightToLeft(self):
67
 
        """Fake isRightToLeft."""
68
 
        return False
69
 
    # pylint: enable=C0103
70
 
 
71
 
    def arguments(self):
72
 
        """Fake arguments function."""
73
 
        return self.args[0]
74
 
 
75
 
    def exec_(self):
76
 
        """Fake event loop."""
77
 
        pass
78
 
 
79
 
 
80
 
class FakeMainWindow(object):
81
 
 
82
 
    """A fake MainWindow."""
83
 
 
84
 
    tabname = None
85
 
    urgent = None
86
 
    raised = None
87
 
 
88
 
    def switch_to(self, tabname):
89
 
        """Fake switch_to."""
90
 
        self.tabname = tabname
91
 
 
92
 
    def set_urgent(self, value):
93
 
        """Fake set_urgent."""
94
 
        self.urgent = value
95
 
 
96
 
    def raise_(self):
97
 
        """Fake raise."""
98
 
        self.raised = True
99
 
 
100
 
 
101
 
class FakeStart(object):
102
 
 
103
 
    """Fake start function."""
104
 
 
105
 
    def __init__(self):
106
 
        self.args = None
107
 
        self.window = None
108
 
 
109
 
    def __call__(self, *args, **kwargs):
110
 
        if kwargs.get('minimized', False):
111
 
            self.window = None
112
 
        else:
113
 
            self.window = FakeMainWindow()
114
 
        self.args = (args, kwargs)
115
 
        return None, self.window
116
 
 
117
 
 
118
 
class MainTestCase(TestCase):
119
 
 
120
 
    """Test the argument parsing and passing in main."""
121
 
 
122
 
    @inlineCallbacks
123
 
    def setUp(self):
124
 
        yield super(MainTestCase, self).setUp()
125
 
        self.app = FakeApplication()
126
 
        self.translator = FakeTranslator()
127
 
        self.start = FakeStart()
128
 
        self.patch(main, "UniqueApplication", self.app)
129
 
        self.patch(main, "start", self.start)
130
 
        self.patch(main.source, "main_start", lambda app: None)
131
 
        self.patch(QtCore, "QTranslator", lambda: self.translator)
132
 
 
133
 
        self.qt4reactor_installed = False
134
 
 
135
 
        def fake_install_qt4reactor():
136
 
            """Record the install without importing."""
137
 
            self.qt4reactor_installed = True
138
 
 
139
 
        self.patch(main, "install_qt4reactor",
140
 
                   fake_install_qt4reactor)
141
 
 
142
 
    def test_wm_class(self):
143
 
        """Test that we set the 1st argument, used for WM_CLASS, correctly."""
144
 
        main.main([sys.argv[0]])
145
 
        self.assertEqual(self.app.args,
146
 
            (['ubuntuone-installer', sys.argv[0]],
147
 
            ('ubuntuone-control-panel',), {}))
148
 
 
149
 
    def test_title_not_fail(self):
150
 
        """Ensure -title is removed before it gets to argparse."""
151
 
        main.main([sys.argv[0], "-title"])
152
 
        # Did not crash!
153
 
 
154
 
    def test_truncate_argv(self):
155
 
        """Ensure the binary name is not given to argparse."""
156
 
        main.main(["foo", "bar", sys.argv[0], "--minimized"])
157
 
        self.assertEqual(self.start.args[1],
158
 
            {'minimized': True, 'with_icon': False, 'installer': False})
159
 
 
160
 
    def test_minimized_option(self):
161
 
        """Ensure the --minimized option is parsed and passed correctly."""
162
 
        main.main([sys.argv[0], "--minimized"])
163
 
        self.assertEqual(self.start.args[1],
164
 
            {'minimized': True, 'with_icon': False, 'installer': False})
165
 
 
166
 
    def test_with_icon_option(self):
167
 
        """Ensure the --minimized option is parsed and passed correctly."""
168
 
        main.main([sys.argv[0], "--with-icon"])
169
 
        self.assertEqual(self.start.args[1],
170
 
            {'minimized': False, 'with_icon': True, 'installer': False})
171
 
 
172
 
    def test_all_styles_load(self):
173
 
        """Ensure the platform style is loaded."""
174
 
        main.main([sys.argv[0]])
175
 
        data = []
176
 
        for qss_name in (":/ubuntuone.qss", main.source.PLATFORM_QSS):
177
 
            qss = QtCore.QResource(qss_name)
178
 
            data.append(unicode(qss.data()))
179
 
        self.assertEqual((('\n'.join(data),), {}), self.app.style)
180
 
 
181
 
    def test_switch_to_option(self):
182
 
        """Ensure the --switch-to option is parsed and passed correctly."""
183
 
        main.main([sys.argv[0], "--switch-to", "folders"])
184
 
        self.assertEqual(self.start.window.tabname, "folders")
185
 
 
186
 
    def test_installer_option(self):
187
 
        """Ensure the --installer option is parsed and passed correctly."""
188
 
        main.main([sys.argv[0], "--installer"])
189
 
        self.assertEqual(self.start.args[1],
190
 
            {'minimized': False, 'with_icon': False, 'installer': True})
191
 
 
192
 
    def test_minimized_with_icon_options(self):
193
 
        """Ensure you can be minimized and with icon at the same time."""
194
 
        main.main([sys.argv[0], "--minimized", "--with-icon"])
195
 
        self.assertEqual(self.start.args[1],
196
 
            {'minimized': True, 'with_icon': True, 'installer': False})
197
 
 
198
 
    def test_translator(self):
199
 
        """Ensure the Qt translator is loaded."""
200
 
        main.main([sys.argv[0]])
201
 
        locale = unicode(QtCore.QLocale.system().name())
202
 
        self.assertEqual(self.app.translator, self.translator)
203
 
        self.assertEqual(self.translator.args, (("qt_" + locale,
204
 
            QtCore.QLibraryInfo.location(
205
 
                QtCore.QLibraryInfo.TranslationsPath)), {}))
206
 
 
207
 
    def test_new_instance(self):
208
 
        """Ensure the new_instance signal is connected."""
209
 
        main.main([sys.argv[0]])
210
 
        self.assertEqual(self.app.new_instance.target,
211
 
            self.start.window.raise_)
212
 
 
213
 
    def test_darwin_installs_qt4reactor(self):
214
 
        """Ensure the qt4 reactor is installed when requested."""
215
 
        self.patch(sys, 'platform', 'darwin')
216
 
        main.main([sys.argv[0]], install_reactor_darwin=True)
217
 
        self.assertEqual(self.qt4reactor_installed, True)
218
 
 
219
 
    def test_darwin_doesnt_install_qt4reactor(self):
220
 
        """Ensure the qt4 reactor isn't installed by default."""
221
 
        self.patch(sys, 'platform', 'darwin')
222
 
        main.main([sys.argv[0]])
223
 
        self.assertEqual(self.qt4reactor_installed, False)
224
 
 
225
 
    def test_nondarwin_ignores_true_install_flag(self):
226
 
        """Ensure the qt4 reactor isn't installed on non-darwin."""
227
 
        self.patch(sys, 'platform', 'not-darwin')
228
 
        main.main([sys.argv[0]], install_reactor_darwin=True)
229
 
        self.assertEqual(self.qt4reactor_installed, False)
230
 
 
231
 
    def test_nondarwin_ignores_false_install_flag(self):
232
 
        """Ensure the qt4 reactor isn't installed on non-darwin."""
233
 
        self.patch(sys, 'platform', 'not-darwin')
234
 
        main.main([sys.argv[0]], install_reactor_darwin=False)
235
 
        self.assertEqual(self.qt4reactor_installed, False)