/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 19:21:31 UTC
  • mto: (776.3.1 gpush)
  • mto: This revision was merged to the branch mainline in revision 779.
  • Revision ID: sinzui.is@verizon.net-20120227192131-eye15mnp9os7cv6j
Clean up test module.

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_get_password(self):
 
83
        ui_factory = ui.GtkUIFactory()
 
84
        MockMethod.bind(self, ui.PasswordDialog, 'run', Gtk.ResponseType.OK)
 
85
        mock_property = MockProperty.bind(
 
86
            self, ui.PasswordDialog, 'passwd', 'secret')
 
87
        password = ui_factory.get_password('test')
 
88
        self.assertIs(True, ui.PasswordDialog.run.called)
 
89
        self.assertIs(True, mock_property.called)
 
90
        self.assertEqual('secret', password)
 
91
 
 
92
    def test_progress_all_finished_with_widget(self):
 
93
        ui_factory = ui.GtkUIFactory()
 
94
        progress_widget = ui.ProgressPanel()
 
95
        MockMethod.bind(self, progress_widget, 'finished')
 
96
        ui_factory.set_progress_bar_widget(progress_widget)
 
97
        self.assertIs(None, ui_factory._progress_all_finished())
 
98
        self.assertIs(True, progress_widget.finished.called)
 
99
 
 
100
    def test_progress_all_finished_without_widget(self):
 
101
        ui_factory = ui.GtkUIFactory()
 
102
        self.assertIs(None, ui_factory._progress_all_finished())
 
103
 
 
104
    def test_progress_updated_with_widget(self):
 
105
        ui_factory = ui.GtkUIFactory()
 
106
        progress_widget = ui.ProgressPanel()
 
107
        MockMethod.bind(self, progress_widget, 'update')
 
108
        ui_factory.set_progress_bar_widget(progress_widget)
 
109
        task = ProgressTask()
 
110
        task.msg = 'test'
 
111
        task.current_cnt = 1
 
112
        task.total_cnt = 2
 
113
        self.assertIs(None, ui_factory._progress_updated(task))
 
114
        self.assertIs(True, progress_widget.update.called)
 
115
        self.assertEqual(
 
116
            ('test', 1, 2), progress_widget.update.args)
 
117
 
 
118
    def test_progress_updated_without_widget(self):
 
119
        ui_factory = ui.GtkUIFactory()
 
120
        MockMethod.bind(self, ui.ProgressBarWindow, 'update')
 
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.assertIsInstance(
 
127
            ui_factory._progress_bar_widget, ui.ProgressBarWindow)
 
128
        self.assertIs(True, ui_factory._progress_bar_widget.update.called)
 
129
        self.assertEqual(
 
130
            ('test', 1, 2), ui_factory._progress_bar_widget.update.args)
 
131
 
 
132
    def test_report_transport_activity_with_widget(self):
 
133
        ui_factory = ui.GtkUIFactory()
 
134
        progress_widget = ui.ProgressPanel()
 
135
        MockMethod.bind(self, progress_widget, 'tick')
 
136
        ui_factory.set_progress_bar_widget(progress_widget)
 
137
        self.assertIs(
 
138
            None, ui_factory.report_transport_activity(None, None, None))
 
139
        self.assertIs(True, progress_widget.tick.called)
 
140
 
 
141
    def test_report_transport_activity_without_widget(self):
 
142
        ui_factory = ui.GtkUIFactory()
 
143
        MockMethod.bind(self, ui.ProgressBarWindow, 'tick')
 
144
        self.assertIs(
 
145
            None, ui_factory.report_transport_activity(None, None, None))
 
146
        self.assertIsInstance(
 
147
            ui_factory._progress_bar_widget, ui.ProgressBarWindow)
 
148
        self.assertIs(True, ui.ProgressBarWindow.tick.called)
 
149
 
 
150
 
56
151
class PromptDialogTestCase(tests.TestCase):
57
152
 
58
153
    def test_init(self):
59
 
        # The text and buttons are created.
 
154
        # The label and buttons are created, then shown.
 
155
        MockMethod.bind(self, Gtk.Box, 'show_all')
60
156
        dialog = ui.PromptDialog('test 123')
61
 
        self.assertEqual('test 123', dialog.props.text)
62
 
        self.assertEqual(Gtk.MessageType.QUESTION, dialog.props.message_type)
63
 
        buttons = dialog.get_action_area().get_children()
64
 
        self.assertEqual('gtk-yes', buttons[0].props.label)
65
 
        self.assertEqual('gtk-no', buttons[1].props.label)
66
 
 
67
 
 
68
 
class InfoDialogTestCase(tests.TestCase):
69
 
 
70
 
    def test_init(self):
71
 
        # The text and buttons are created.
72
 
        dialog = ui.InfoDialog('test 123')
73
 
        self.assertEqual('test 123', dialog.props.text)
74
 
        self.assertEqual(Gtk.MessageType.INFO, dialog.props.message_type)
75
 
        buttons = dialog.get_action_area().get_children()
76
 
        self.assertEqual('gtk-close', buttons[0].props.label)
77
 
 
78
 
 
79
 
class WarningDialogTestCase(tests.TestCase):
80
 
 
81
 
    def test_init(self):
82
 
        # The text and buttons are created.
83
 
        dialog = ui.WarningDialog('test 123')
84
 
        self.assertEqual('test 123', dialog.props.text)
85
 
        self.assertEqual(Gtk.MessageType.WARNING, dialog.props.message_type)
86
 
        buttons = dialog.get_action_area().get_children()
87
 
        self.assertEqual('gtk-close', buttons[0].props.label)
88
 
 
89
 
 
90
 
class ErrorDialogTestCase(tests.TestCase):
91
 
 
92
 
    def test_init(self):
93
 
        # The text and buttons are created, then shown.
94
 
        dialog = ui.ErrorDialog('test 123')
95
 
        self.assertEqual('test 123', dialog.props.text)
96
 
        self.assertEqual(Gtk.MessageType.ERROR, dialog.props.message_type)
97
 
        buttons = dialog.get_action_area().get_children()
98
 
        self.assertEqual('gtk-close', buttons[0].props.label)
 
157
        content_area = dialog.get_content_area()
 
158
        self.assertIs(True, dialog.get_content_area().show_all.called)
 
159
        self.assertIs(1, dialog.get_content_area().show_all.call_count)
 
160
        label = content_area.get_children()[0]
 
161
        self.assertEqual('test 123', label.props.label)
 
162
        buttons = dialog.get_action_area().get_children()
 
163
        self.assertEqual('gtk-no', buttons[0].props.label)
 
164
        self.assertEqual(
 
165
            Gtk.ResponseType.NO, dialog.get_response_for_widget(buttons[0]))
 
166
        self.assertEqual('gtk-yes', buttons[1].props.label)
 
167
        self.assertEqual(
 
168
            Gtk.ResponseType.YES, dialog.get_response_for_widget(buttons[1]))
99
169
 
100
170
 
101
171
class PasswordDialogTestCase(tests.TestCase):
245
315
        widgets = pb_window.get_children()
246
316
        # The image's stock and icon_name properties are always None?
247
317
        self.assertIsInstance(widgets[0], Gtk.Image)
248
 
 
249
 
 
250
 
class GtkUIFactoryTestCase(tests.TestCase):
251
 
 
252
 
    def test__init(self):
253
 
        ui_factory = ui.GtkUIFactory()
254
 
        self.assertIs(None, ui_factory._progress_bar_widget)
255
 
 
256
 
    def test_set_progress_bar_widget(self):
257
 
        ui_factory = ui.GtkUIFactory()
258
 
        progress_widget = ui.ProgressPanel()
259
 
        ui_factory.set_progress_bar_widget(progress_widget)
260
 
        self.assertIs(progress_widget, ui_factory._progress_bar_widget)
261
 
 
262
 
    def test_get_boolean_true(self):
263
 
        ui_factory = ui.GtkUIFactory()
264
 
        MockMethod.bind(self, ui.PromptDialog, 'run', Gtk.ResponseType.YES)
265
 
        boolean_value = ui_factory.get_boolean('test')
266
 
        self.assertIs(True, ui.PromptDialog.run.called)
267
 
        self.assertIs(True, boolean_value)
268
 
 
269
 
    def test_get_boolean_false(self):
270
 
        ui_factory = ui.GtkUIFactory()
271
 
        MockMethod.bind(self, ui.PromptDialog, 'run', Gtk.ResponseType.NO)
272
 
        boolean_value = ui_factory.get_boolean('test')
273
 
        self.assertIs(True, ui.PromptDialog.run.called)
274
 
        self.assertIs(False, boolean_value)
275
 
 
276
 
    def test_show_message(self):
277
 
        ui_factory = ui.GtkUIFactory()
278
 
        MockMethod.bind(self, ui.InfoDialog, 'run', Gtk.ResponseType.CLOSE)
279
 
        ui_factory.show_message('test')
280
 
        self.assertIs(True, ui.InfoDialog.run.called)
281
 
 
282
 
    def test_show_warning(self):
283
 
        ui_factory = ui.GtkUIFactory()
284
 
        MockMethod.bind(self, ui.WarningDialog, 'run', Gtk.ResponseType.CLOSE)
285
 
        ui_factory.show_warning('test')
286
 
        self.assertIs(True, ui.WarningDialog.run.called)
287
 
 
288
 
    def test_show_Error(self):
289
 
        ui_factory = ui.GtkUIFactory()
290
 
        MockMethod.bind(self, ui.ErrorDialog, 'run', Gtk.ResponseType.CLOSE)
291
 
        ui_factory.show_error('test')
292
 
        self.assertIs(True, ui.ErrorDialog.run.called)
293
 
 
294
 
    def test_show_user_warning(self):
295
 
        ui_factory = ui.GtkUIFactory()
296
 
        MockMethod.bind(self, ui.WarningDialog, 'run', Gtk.ResponseType.CLOSE)
297
 
        ui_factory.show_user_warning(
298
 
            'recommend_upgrade', current_format_name='1.0', basedir='./test')
299
 
        self.assertIs(True, ui.WarningDialog.run.called)
300
 
 
301
 
    def test_show_user_warning_supressed(self):
302
 
        ui_factory = ui.GtkUIFactory()
303
 
        ui_factory.suppressed_warnings.add('recommend_upgrade')
304
 
        MockMethod.bind(self, ui.WarningDialog, 'run', Gtk.ResponseType.CLOSE)
305
 
        ui_factory.show_user_warning(
306
 
            'recommend_upgrade', current_format_name='1.0', basedir='./test')
307
 
        self.assertIs(False, ui.WarningDialog.run.called)
308
 
 
309
 
    def test_get_password(self):
310
 
        ui_factory = ui.GtkUIFactory()
311
 
        MockMethod.bind(self, ui.PasswordDialog, 'run', Gtk.ResponseType.OK)
312
 
        mock_property = MockProperty.bind(
313
 
            self, ui.PasswordDialog, 'passwd', 'secret')
314
 
        password = ui_factory.get_password('test')
315
 
        self.assertIs(True, ui.PasswordDialog.run.called)
316
 
        self.assertIs(True, mock_property.called)
317
 
        self.assertEqual('secret', password)
318
 
 
319
 
    def test_progress_all_finished_with_widget(self):
320
 
        ui_factory = ui.GtkUIFactory()
321
 
        progress_widget = ui.ProgressPanel()
322
 
        MockMethod.bind(self, progress_widget, 'finished')
323
 
        ui_factory.set_progress_bar_widget(progress_widget)
324
 
        self.assertIs(None, ui_factory._progress_all_finished())
325
 
        self.assertIs(True, progress_widget.finished.called)
326
 
 
327
 
    def test_progress_all_finished_without_widget(self):
328
 
        ui_factory = ui.GtkUIFactory()
329
 
        self.assertIs(None, ui_factory._progress_all_finished())
330
 
 
331
 
    def test_progress_updated_with_widget(self):
332
 
        ui_factory = ui.GtkUIFactory()
333
 
        progress_widget = ui.ProgressPanel()
334
 
        MockMethod.bind(self, progress_widget, 'update')
335
 
        ui_factory.set_progress_bar_widget(progress_widget)
336
 
        task = ProgressTask()
337
 
        task.msg = 'test'
338
 
        task.current_cnt = 1
339
 
        task.total_cnt = 2
340
 
        self.assertIs(None, ui_factory._progress_updated(task))
341
 
        self.assertIs(True, progress_widget.update.called)
342
 
        self.assertEqual(
343
 
            ('test', 1, 2), progress_widget.update.args)
344
 
 
345
 
    def test_progress_updated_without_widget(self):
346
 
        ui_factory = ui.GtkUIFactory()
347
 
        MockMethod.bind(self, ui.ProgressBarWindow, 'update')
348
 
        task = ProgressTask()
349
 
        task.msg = 'test'
350
 
        task.current_cnt = 1
351
 
        task.total_cnt = 2
352
 
        self.assertIs(None, ui_factory._progress_updated(task))
353
 
        self.assertIsInstance(
354
 
            ui_factory._progress_bar_widget, ui.ProgressBarWindow)
355
 
        self.assertIs(True, ui_factory._progress_bar_widget.update.called)
356
 
        self.assertEqual(
357
 
            ('test', 1, 2), ui_factory._progress_bar_widget.update.args)
358
 
 
359
 
    def test_report_transport_activity_with_widget(self):
360
 
        ui_factory = ui.GtkUIFactory()
361
 
        progress_widget = ui.ProgressPanel()
362
 
        MockMethod.bind(self, progress_widget, 'tick')
363
 
        ui_factory.set_progress_bar_widget(progress_widget)
364
 
        self.assertIs(
365
 
            None, ui_factory.report_transport_activity(None, None, None))
366
 
        self.assertIs(True, progress_widget.tick.called)
367
 
 
368
 
    def test_report_transport_activity_without_widget(self):
369
 
        ui_factory = ui.GtkUIFactory()
370
 
        MockMethod.bind(self, ui.ProgressBarWindow, 'tick')
371
 
        self.assertIs(
372
 
            None, ui_factory.report_transport_activity(None, None, None))
373
 
        self.assertIsInstance(
374
 
            ui_factory._progress_bar_widget, ui.ProgressBarWindow)
375
 
        self.assertIs(True, ui.ProgressBarWindow.tick.called)