1
# -*- coding: utf-8 -*-
3
# Copyright 2012 Canonical Ltd.
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.
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.
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/>.
17
"""Tests for the control panel's Qt main."""
19
from twisted.internet.defer import inlineCallbacks
21
from ubuntuone.controlpanel.gui.qt import main
22
from ubuntuone.controlpanel.tests import TestCase
25
class FakeApplication(object):
27
"""A fake application."""
33
def __call__(self, argv, *args, **kwargs):
34
"""Fake arg filtering function."""
37
self.args = (argv, args, kwargs)
40
# pylint: disable=C0103
41
def setStyleSheet(self, *args, **kwargs):
42
"""Fake setStyleSheet."""
43
self.style = (args, kwargs)
44
# pylint: enable=C0103
47
"""Fake arguments function."""
51
"""Fake event loop."""
55
class FakeStart(object):
57
"""Fake start function."""
62
def __call__(self, *args, **kwargs):
63
self.args = (args, kwargs)
67
class MainTestCase(TestCase):
69
"""Test the argument parsing and passing in main."""
73
yield super(MainTestCase, self).setUp()
74
self.app = FakeApplication()
75
self.start = FakeStart()
76
self.patch(main, "UniqueApplication", self.app)
77
self.patch(main, "start", self.start)
79
def test_wm_class(self):
80
"""Test that we set the 1st argument, used for WM_CLASS, correctly."""
82
self.assertEqual(self.app.args,
83
(['ubuntuone-installer'], ('ubuntuone-control-panel',), {}))
85
def test_title_not_fail(self):
86
"""Ensure -title is removed before it gets to OptParser."""
87
main.main(["blah", "-title"])
90
def test_minimized_option(self):
91
"""Ensure the --minimized option is parsed and passed correctly."""
92
main.main(["blah", "--minimized"])
93
self.assertEqual(self.start.args[1],
94
{'minimized': True, 'with_icon': False})
96
def test_with_icon_option(self):
97
"""Ensure the --minimized option is parsed and passed correctly."""
98
main.main(["blah", "--with-icon"])
99
self.assertEqual(self.start.args[1],
100
{'minimized': False, 'with_icon': True})
102
def test_style_loads(self):
103
"""Ensure the stylesheet is loaded."""
105
self.assertTrue(self.app.style)