/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to tests/test_ui.py

  • Committer: Curtis Hovey
  • Date: 2012-02-27 20:27:22 UTC
  • mto: (776.3.1 gpush)
  • mto: This revision was merged to the branch mainline in revision 779.
  • Revision ID: sinzui.is@verizon.net-20120227202722-fvk66bekcjtwq2nd
Chnge test order to match the order of classes in  the module under test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
        self.assertEqual('after', button.props.label)
54
54
 
55
55
 
56
 
class GtkUIFactoryTestCase(tests.TestCase):
57
 
 
58
 
    def test__init(self):
59
 
        ui_factory = ui.GtkUIFactory()
60
 
        self.assertIs(None, ui_factory._progress_bar_widget)
61
 
 
62
 
    def test_set_progress_bar_widget(self):
63
 
        ui_factory = ui.GtkUIFactory()
64
 
        progress_widget = ui.ProgressPanel()
65
 
        ui_factory.set_progress_bar_widget(progress_widget)
66
 
        self.assertIs(progress_widget, ui_factory._progress_bar_widget)
67
 
 
68
 
    def test_get_boolean_true(self):
69
 
        ui_factory = ui.GtkUIFactory()
70
 
        MockMethod.bind(self, ui.PromptDialog, 'run', Gtk.ResponseType.YES)
71
 
        boolean_value = ui_factory.get_boolean('test')
72
 
        self.assertIs(True, ui.PromptDialog.run.called)
73
 
        self.assertIs(True, boolean_value)
74
 
 
75
 
    def test_get_boolean_false(self):
76
 
        ui_factory = ui.GtkUIFactory()
77
 
        MockMethod.bind(self, ui.PromptDialog, 'run', Gtk.ResponseType.NO)
78
 
        boolean_value = ui_factory.get_boolean('test')
79
 
        self.assertIs(True, ui.PromptDialog.run.called)
80
 
        self.assertIs(False, boolean_value)
81
 
 
82
 
    def test_show_message(self):
83
 
        ui_factory = ui.GtkUIFactory()
84
 
        MockMethod.bind(self, ui.InfoDialog, 'run', Gtk.ResponseType.CLOSE)
85
 
        ui_factory.show_message('test')
86
 
        self.assertIs(True, ui.InfoDialog.run.called)
87
 
 
88
 
    def test_show_warning(self):
89
 
        ui_factory = ui.GtkUIFactory()
90
 
        MockMethod.bind(self, ui.WarningDialog, 'run', Gtk.ResponseType.CLOSE)
91
 
        ui_factory.show_warning('test')
92
 
        self.assertIs(True, ui.WarningDialog.run.called)
93
 
 
94
 
    def test_get_password(self):
95
 
        ui_factory = ui.GtkUIFactory()
96
 
        MockMethod.bind(self, ui.PasswordDialog, 'run', Gtk.ResponseType.OK)
97
 
        mock_property = MockProperty.bind(
98
 
            self, ui.PasswordDialog, 'passwd', 'secret')
99
 
        password = ui_factory.get_password('test')
100
 
        self.assertIs(True, ui.PasswordDialog.run.called)
101
 
        self.assertIs(True, mock_property.called)
102
 
        self.assertEqual('secret', password)
103
 
 
104
 
    def test_progress_all_finished_with_widget(self):
105
 
        ui_factory = ui.GtkUIFactory()
106
 
        progress_widget = ui.ProgressPanel()
107
 
        MockMethod.bind(self, progress_widget, 'finished')
108
 
        ui_factory.set_progress_bar_widget(progress_widget)
109
 
        self.assertIs(None, ui_factory._progress_all_finished())
110
 
        self.assertIs(True, progress_widget.finished.called)
111
 
 
112
 
    def test_progress_all_finished_without_widget(self):
113
 
        ui_factory = ui.GtkUIFactory()
114
 
        self.assertIs(None, ui_factory._progress_all_finished())
115
 
 
116
 
    def test_progress_updated_with_widget(self):
117
 
        ui_factory = ui.GtkUIFactory()
118
 
        progress_widget = ui.ProgressPanel()
119
 
        MockMethod.bind(self, progress_widget, 'update')
120
 
        ui_factory.set_progress_bar_widget(progress_widget)
121
 
        task = ProgressTask()
122
 
        task.msg = 'test'
123
 
        task.current_cnt = 1
124
 
        task.total_cnt = 2
125
 
        self.assertIs(None, ui_factory._progress_updated(task))
126
 
        self.assertIs(True, progress_widget.update.called)
127
 
        self.assertEqual(
128
 
            ('test', 1, 2), progress_widget.update.args)
129
 
 
130
 
    def test_progress_updated_without_widget(self):
131
 
        ui_factory = ui.GtkUIFactory()
132
 
        MockMethod.bind(self, ui.ProgressBarWindow, 'update')
133
 
        task = ProgressTask()
134
 
        task.msg = 'test'
135
 
        task.current_cnt = 1
136
 
        task.total_cnt = 2
137
 
        self.assertIs(None, ui_factory._progress_updated(task))
138
 
        self.assertIsInstance(
139
 
            ui_factory._progress_bar_widget, ui.ProgressBarWindow)
140
 
        self.assertIs(True, ui_factory._progress_bar_widget.update.called)
141
 
        self.assertEqual(
142
 
            ('test', 1, 2), ui_factory._progress_bar_widget.update.args)
143
 
 
144
 
    def test_report_transport_activity_with_widget(self):
145
 
        ui_factory = ui.GtkUIFactory()
146
 
        progress_widget = ui.ProgressPanel()
147
 
        MockMethod.bind(self, progress_widget, 'tick')
148
 
        ui_factory.set_progress_bar_widget(progress_widget)
149
 
        self.assertIs(
150
 
            None, ui_factory.report_transport_activity(None, None, None))
151
 
        self.assertIs(True, progress_widget.tick.called)
152
 
 
153
 
    def test_report_transport_activity_without_widget(self):
154
 
        ui_factory = ui.GtkUIFactory()
155
 
        MockMethod.bind(self, ui.ProgressBarWindow, 'tick')
156
 
        self.assertIs(
157
 
            None, ui_factory.report_transport_activity(None, None, None))
158
 
        self.assertIsInstance(
159
 
            ui_factory._progress_bar_widget, ui.ProgressBarWindow)
160
 
        self.assertIs(True, ui.ProgressBarWindow.tick.called)
161
 
 
162
 
 
163
56
class PromptDialogTestCase(tests.TestCase):
164
57
 
165
58
    def test_init(self):
341
234
        widgets = pb_window.get_children()
342
235
        # The image's stock and icon_name properties are always None?
343
236
        self.assertIsInstance(widgets[0], Gtk.Image)
 
237
 
 
238
 
 
239
class GtkUIFactoryTestCase(tests.TestCase):
 
240
 
 
241
    def test__init(self):
 
242
        ui_factory = ui.GtkUIFactory()
 
243
        self.assertIs(None, ui_factory._progress_bar_widget)
 
244
 
 
245
    def test_set_progress_bar_widget(self):
 
246
        ui_factory = ui.GtkUIFactory()
 
247
        progress_widget = ui.ProgressPanel()
 
248
        ui_factory.set_progress_bar_widget(progress_widget)
 
249
        self.assertIs(progress_widget, ui_factory._progress_bar_widget)
 
250
 
 
251
    def test_get_boolean_true(self):
 
252
        ui_factory = ui.GtkUIFactory()
 
253
        MockMethod.bind(self, ui.PromptDialog, 'run', Gtk.ResponseType.YES)
 
254
        boolean_value = ui_factory.get_boolean('test')
 
255
        self.assertIs(True, ui.PromptDialog.run.called)
 
256
        self.assertIs(True, boolean_value)
 
257
 
 
258
    def test_get_boolean_false(self):
 
259
        ui_factory = ui.GtkUIFactory()
 
260
        MockMethod.bind(self, ui.PromptDialog, 'run', Gtk.ResponseType.NO)
 
261
        boolean_value = ui_factory.get_boolean('test')
 
262
        self.assertIs(True, ui.PromptDialog.run.called)
 
263
        self.assertIs(False, boolean_value)
 
264
 
 
265
    def test_show_message(self):
 
266
        ui_factory = ui.GtkUIFactory()
 
267
        MockMethod.bind(self, ui.InfoDialog, 'run', Gtk.ResponseType.CLOSE)
 
268
        ui_factory.show_message('test')
 
269
        self.assertIs(True, ui.InfoDialog.run.called)
 
270
 
 
271
    def test_show_warning(self):
 
272
        ui_factory = ui.GtkUIFactory()
 
273
        MockMethod.bind(self, ui.WarningDialog, 'run', Gtk.ResponseType.CLOSE)
 
274
        ui_factory.show_warning('test')
 
275
        self.assertIs(True, ui.WarningDialog.run.called)
 
276
 
 
277
    def test_get_password(self):
 
278
        ui_factory = ui.GtkUIFactory()
 
279
        MockMethod.bind(self, ui.PasswordDialog, 'run', Gtk.ResponseType.OK)
 
280
        mock_property = MockProperty.bind(
 
281
            self, ui.PasswordDialog, 'passwd', 'secret')
 
282
        password = ui_factory.get_password('test')
 
283
        self.assertIs(True, ui.PasswordDialog.run.called)
 
284
        self.assertIs(True, mock_property.called)
 
285
        self.assertEqual('secret', password)
 
286
 
 
287
    def test_progress_all_finished_with_widget(self):
 
288
        ui_factory = ui.GtkUIFactory()
 
289
        progress_widget = ui.ProgressPanel()
 
290
        MockMethod.bind(self, progress_widget, 'finished')
 
291
        ui_factory.set_progress_bar_widget(progress_widget)
 
292
        self.assertIs(None, ui_factory._progress_all_finished())
 
293
        self.assertIs(True, progress_widget.finished.called)
 
294
 
 
295
    def test_progress_all_finished_without_widget(self):
 
296
        ui_factory = ui.GtkUIFactory()
 
297
        self.assertIs(None, ui_factory._progress_all_finished())
 
298
 
 
299
    def test_progress_updated_with_widget(self):
 
300
        ui_factory = ui.GtkUIFactory()
 
301
        progress_widget = ui.ProgressPanel()
 
302
        MockMethod.bind(self, progress_widget, 'update')
 
303
        ui_factory.set_progress_bar_widget(progress_widget)
 
304
        task = ProgressTask()
 
305
        task.msg = 'test'
 
306
        task.current_cnt = 1
 
307
        task.total_cnt = 2
 
308
        self.assertIs(None, ui_factory._progress_updated(task))
 
309
        self.assertIs(True, progress_widget.update.called)
 
310
        self.assertEqual(
 
311
            ('test', 1, 2), progress_widget.update.args)
 
312
 
 
313
    def test_progress_updated_without_widget(self):
 
314
        ui_factory = ui.GtkUIFactory()
 
315
        MockMethod.bind(self, ui.ProgressBarWindow, 'update')
 
316
        task = ProgressTask()
 
317
        task.msg = 'test'
 
318
        task.current_cnt = 1
 
319
        task.total_cnt = 2
 
320
        self.assertIs(None, ui_factory._progress_updated(task))
 
321
        self.assertIsInstance(
 
322
            ui_factory._progress_bar_widget, ui.ProgressBarWindow)
 
323
        self.assertIs(True, ui_factory._progress_bar_widget.update.called)
 
324
        self.assertEqual(
 
325
            ('test', 1, 2), ui_factory._progress_bar_widget.update.args)
 
326
 
 
327
    def test_report_transport_activity_with_widget(self):
 
328
        ui_factory = ui.GtkUIFactory()
 
329
        progress_widget = ui.ProgressPanel()
 
330
        MockMethod.bind(self, progress_widget, 'tick')
 
331
        ui_factory.set_progress_bar_widget(progress_widget)
 
332
        self.assertIs(
 
333
            None, ui_factory.report_transport_activity(None, None, None))
 
334
        self.assertIs(True, progress_widget.tick.called)
 
335
 
 
336
    def test_report_transport_activity_without_widget(self):
 
337
        ui_factory = ui.GtkUIFactory()
 
338
        MockMethod.bind(self, ui.ProgressBarWindow, 'tick')
 
339
        self.assertIs(
 
340
            None, ui_factory.report_transport_activity(None, None, None))
 
341
        self.assertIsInstance(
 
342
            ui_factory._progress_bar_widget, ui.ProgressBarWindow)
 
343
        self.assertIs(True, ui.ProgressBarWindow.tick.called)