1
# -*- coding: utf-8 -*-
3
# Authors: Natalia B Bidart <natalia.bidart@canonical.com>
5
# Copyright 2010 Canonical Ltd.
7
# This program is free software: you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License version 3, as published
9
# by the Free Software Foundation.
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranties of
13
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14
# PURPOSE. See the GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License along
17
# with this program. If not, see <http://www.gnu.org/licenses/>.
19
"""The test suite for the extra widgets."""
21
from ubuntuone.controlpanel.tests import TestCase
22
from ubuntuone.controlpanel.gtk import widgets
25
class LoadingTestCase(TestCase):
26
"""Test suite for the Loading widget (a spinner plus a label)."""
29
super(LoadingTestCase, self).setUp()
30
self.label = 'A loading tests...'
31
self.loading = widgets.Loading(self.label)
33
def test_creation(self):
34
"""A Loading can be created."""
35
self.assertEqual(self.loading.label.get_text(), self.label)
36
self.assertEqual(self.loading.spinner.get_property('active'), True)
38
def test_visibility(self):
39
"""All widgets are visible."""
40
self.assertTrue(self.loading.label.get_visible())
41
self.assertTrue(self.loading.spinner.get_visible())
43
def test_children(self):
44
"""A Loading can be created."""
45
children = self.loading.get_children()
46
self.assertEqual(2, len(children))
47
self.assertTrue(self.loading.spinner is children[0])
48
self.assertTrue(self.loading.label is children[-1])
50
def test_fg_color(self):
51
"""Foreground color can be set."""
53
widget = widgets.Loading(self.label, fg_color=expected)
55
win = widgets.gtk.Window()
57
win.realize() # ensure realization
59
self.assertEqual(widget.label.style.fg[widgets.gtk.STATE_NORMAL],
60
widgets.gtk.gdk.Color(expected))
63
class LabelLoadingTestCase(TestCase):
64
"""Test suite for the LabelLoading widget.
66
(a label that shows a Loading until the text is set).
71
super(LabelLoadingTestCase, self).setUp()
72
self.label = 'A label loading tests...'
73
self.widget = widgets.LabelLoading(self.label)
75
def test_creation(self):
76
"""A LabelLoading can be created."""
77
self.assertEqual(self.widget.label.get_text(), '')
78
self.assertTrue(self.widget.label.get_visible())
80
self.assertIsInstance(self.widget.loading, widgets.Loading)
81
self.assertTrue(self.widget.loading.get_visible())
82
self.assertTrue(self.widget.active) # loading label is packed
85
"""Stop hides the Loading widget."""
88
self.assertTrue(self.widget.get_child() is self.widget.label)
89
self.assertFalse(self.widget.active)
92
"""Start shows the Loading widget."""
95
self.assertTrue(self.widget.get_child() is self.widget.loading)
96
self.assertTrue(self.widget.active)
98
def test_get_text(self):
99
"""Text can be queried."""
101
self.widget.label.set_text(text)
102
self.assertEqual(self.widget.get_text(), text)
104
def test_set_text(self):
105
"""Text can be set."""
107
self.widget.set_text(text)
108
self.assertEqual(self.widget.label.get_text(), text)
110
def test_get_label(self):
111
"""Label (markup text) can be queried."""
112
text = 'Test <b>me</b>.'
113
self.widget.label.set_markup(text)
114
self.assertEqual(self.widget.get_label(), text)
116
def test_set_markup(self):
117
"""Markup can be set."""
118
text = 'Test <b>me</b>.'
119
self.widget.set_markup(text)
120
self.assertEqual(self.widget.label.get_label(), text)
122
def test_fg_color(self):
123
"""Foreground color can be set."""
125
widget = widgets.LabelLoading(self.label, fg_color=expected)
126
widget.stop() # show label instead of loading
128
win = widgets.gtk.Window()
130
win.realize() # ensure realization
132
assert widget.label.get_visible()
133
self.assertEqual(widget.label.style.fg[widgets.gtk.STATE_NORMAL],
134
widgets.gtk.gdk.Color(expected))
136
def test_fg_color_loading(self):
137
"""Foreground color can be set to loading label."""
139
widget = widgets.LabelLoading(self.label, fg_color=expected)
141
win = widgets.gtk.Window()
143
win.realize() # ensure realization
145
assert widget.loading.get_visible()
146
actual = widget.loading.label.style.fg[widgets.gtk.STATE_NORMAL]
147
self.assertEqual(actual, widgets.gtk.gdk.Color(expected))
148
actual = widget.loading.spinner.style.fg[widgets.gtk.STATE_NORMAL]
149
self.assertEqual(actual, widgets.gtk.gdk.Color(expected))
151
def test_selectable(self):
152
"""The widget is selectable."""
153
self.assertTrue(self.widget.label.get_selectable())
156
class PanelTitleTestCase(TestCase):
157
"""Tets case for a special title for each management panel."""
159
# pylint: disable=W0612
161
TITLE = '<b>Foo Bar</b>'
164
super(PanelTitleTestCase, self).setUp()
165
self.widget = widgets.PanelTitle(markup=self.TITLE)
167
win = widgets.gtk.Window()
169
win.realize() # ensure realization
171
def test_visibility(self):
172
"""The widget and children visibility is correct."""
173
self.assertTrue(self.widget.get_visible())
175
def test_label_markup(self):
176
"""The label markup is correct."""
177
self.assertEqual(self.widget.get_label(), self.TITLE)
179
def test_label_xalign(self):
180
"""The label is left aligned."""
181
self.assertEqual(self.widget.get_property('xalign'), 0.0)
183
def test_label_line_wrap(self):
184
"""The label is left aligned."""
185
self.assertTrue(self.widget.get_line_wrap())
186
self.assertEqual(self.widget.get_line_wrap_mode(),
187
widgets.pango.WRAP_WORD)
189
def test_label_padding(self):
190
"""The label padding is correct."""
191
self.assertEqual(self.widget.get_padding(),
192
widgets.DEFAULT_PADDING)
194
def test_selectable(self):
195
"""The widget is selectable."""
196
self.assertTrue(self.widget.get_selectable())