~dobey/ubuntu/oneiric/ubuntuone-control-panel/release-113

« back to all changes in this revision

Viewing changes to ubuntuone/controlpanel/gtk/tests/test_widgets.py

  • Committer: Sebastien Bacher
  • Date: 2011-07-25 13:17:38 UTC
  • mfrom: (25.1.2 ubuntuone-control-panel)
  • Revision ID: seb128@ubuntu.com-20110725131738-yuevatnd859d1phs
Tags: 1.1.1-0ubuntu1
releasing version 1.1.1-0ubuntu1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
 
3
 
# Authors: Natalia B Bidart <natalia.bidart@canonical.com>
4
 
#
5
 
# Copyright 2010 Canonical Ltd.
6
 
#
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.
10
 
#
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.
15
 
#
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/>.
18
 
 
19
 
"""The test suite for the extra widgets."""
20
 
 
21
 
from ubuntuone.controlpanel.tests import TestCase
22
 
from ubuntuone.controlpanel.gtk import widgets
23
 
 
24
 
 
25
 
class LoadingTestCase(TestCase):
26
 
    """Test suite for the Loading widget (a spinner plus a label)."""
27
 
 
28
 
    def setUp(self):
29
 
        super(LoadingTestCase, self).setUp()
30
 
        self.label = 'A loading tests...'
31
 
        self.loading = widgets.Loading(self.label)
32
 
 
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)
37
 
 
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())
42
 
 
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])
49
 
 
50
 
    def test_fg_color(self):
51
 
        """Foreground color can be set."""
52
 
        expected = '#654321'
53
 
        widget = widgets.Loading(self.label, fg_color=expected)
54
 
 
55
 
        win = widgets.gtk.Window()
56
 
        win.add(widget)
57
 
        win.realize()  # ensure realization
58
 
 
59
 
        self.assertEqual(widget.label.style.fg[widgets.gtk.STATE_NORMAL],
60
 
                         widgets.gtk.gdk.Color(expected))
61
 
 
62
 
 
63
 
class LabelLoadingTestCase(TestCase):
64
 
    """Test suite for the LabelLoading widget.
65
 
 
66
 
    (a label that shows a Loading until the text is set).
67
 
 
68
 
    """
69
 
 
70
 
    def setUp(self):
71
 
        super(LabelLoadingTestCase, self).setUp()
72
 
        self.label = 'A label loading tests...'
73
 
        self.widget = widgets.LabelLoading(self.label)
74
 
 
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())
79
 
 
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
83
 
 
84
 
    def test_stop(self):
85
 
        """Stop hides the Loading widget."""
86
 
        self.widget.stop()
87
 
 
88
 
        self.assertTrue(self.widget.get_child() is self.widget.label)
89
 
        self.assertFalse(self.widget.active)
90
 
 
91
 
    def test_start(self):
92
 
        """Start shows the Loading widget."""
93
 
        self.widget.start()
94
 
 
95
 
        self.assertTrue(self.widget.get_child() is self.widget.loading)
96
 
        self.assertTrue(self.widget.active)
97
 
 
98
 
    def test_get_text(self):
99
 
        """Text can be queried."""
100
 
        text = 'Test me.'
101
 
        self.widget.label.set_text(text)
102
 
        self.assertEqual(self.widget.get_text(), text)
103
 
 
104
 
    def test_set_text(self):
105
 
        """Text can be set."""
106
 
        text = 'Test me.'
107
 
        self.widget.set_text(text)
108
 
        self.assertEqual(self.widget.label.get_text(), text)
109
 
 
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)
115
 
 
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)
121
 
 
122
 
    def test_fg_color(self):
123
 
        """Foreground color can be set."""
124
 
        expected = '#123456'
125
 
        widget = widgets.LabelLoading(self.label, fg_color=expected)
126
 
        widget.stop()  # show label instead of loading
127
 
 
128
 
        win = widgets.gtk.Window()
129
 
        win.add(widget)
130
 
        win.realize()  # ensure realization
131
 
 
132
 
        assert widget.label.get_visible()
133
 
        self.assertEqual(widget.label.style.fg[widgets.gtk.STATE_NORMAL],
134
 
                         widgets.gtk.gdk.Color(expected))
135
 
 
136
 
    def test_fg_color_loading(self):
137
 
        """Foreground color can be set to loading label."""
138
 
        expected = '#123456'
139
 
        widget = widgets.LabelLoading(self.label, fg_color=expected)
140
 
 
141
 
        win = widgets.gtk.Window()
142
 
        win.add(widget)
143
 
        win.realize()  # ensure realization
144
 
 
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))
150
 
 
151
 
    def test_selectable(self):
152
 
        """The widget is selectable."""
153
 
        self.assertTrue(self.widget.label.get_selectable())
154
 
 
155
 
 
156
 
class PanelTitleTestCase(TestCase):
157
 
    """Tets case for a special title for each management panel."""
158
 
 
159
 
    # pylint: disable=W0612
160
 
 
161
 
    TITLE = '<b>Foo Bar</b>'
162
 
 
163
 
    def setUp(self):
164
 
        super(PanelTitleTestCase, self).setUp()
165
 
        self.widget = widgets.PanelTitle(markup=self.TITLE)
166
 
 
167
 
        win = widgets.gtk.Window()
168
 
        win.add(self.widget)
169
 
        win.realize()  # ensure realization
170
 
 
171
 
    def test_visibility(self):
172
 
        """The widget and children visibility is correct."""
173
 
        self.assertTrue(self.widget.get_visible())
174
 
 
175
 
    def test_label_markup(self):
176
 
        """The label markup is correct."""
177
 
        self.assertEqual(self.widget.get_label(), self.TITLE)
178
 
 
179
 
    def test_label_xalign(self):
180
 
        """The label is left aligned."""
181
 
        self.assertEqual(self.widget.get_property('xalign'), 0.0)
182
 
 
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)
188
 
 
189
 
    def test_label_padding(self):
190
 
        """The label padding is correct."""
191
 
        self.assertEqual(self.widget.get_padding(),
192
 
                         widgets.DEFAULT_PADDING)
193
 
 
194
 
    def test_selectable(self):
195
 
        """The widget is selectable."""
196
 
        self.assertTrue(self.widget.get_selectable())