53
53
self.assertEqual('after', button.props.label)
56
class GtkUIFactoryTestCase(tests.TestCase):
59
ui_factory = ui.GtkUIFactory()
60
self.assertIs(None, ui_factory._progress_bar_widget)
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)
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)
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)
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)
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)
100
def test_progress_all_finished_without_widget(self):
101
ui_factory = ui.GtkUIFactory()
102
self.assertIs(None, ui_factory._progress_all_finished())
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()
113
self.assertIs(None, ui_factory._progress_updated(task))
114
self.assertIs(True, progress_widget.update.called)
116
('test', 1, 2), progress_widget.update.args)
118
def test_progress_updated_without_widget(self):
119
ui_factory = ui.GtkUIFactory()
120
MockMethod.bind(self, ui.ProgressBarWindow, 'update')
121
task = ProgressTask()
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)
130
('test', 1, 2), ui_factory._progress_bar_widget.update.args)
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)
138
None, ui_factory.report_transport_activity(None, None, None))
139
self.assertIs(True, progress_widget.tick.called)
141
def test_report_transport_activity_without_widget(self):
142
ui_factory = ui.GtkUIFactory()
143
MockMethod.bind(self, ui.ProgressBarWindow, 'tick')
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)
56
151
class PromptDialogTestCase(tests.TestCase):
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)
68
class InfoDialogTestCase(tests.TestCase):
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)
79
class WarningDialogTestCase(tests.TestCase):
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)
90
class ErrorDialogTestCase(tests.TestCase):
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)
165
Gtk.ResponseType.NO, dialog.get_response_for_widget(buttons[0]))
166
self.assertEqual('gtk-yes', buttons[1].props.label)
168
Gtk.ResponseType.YES, dialog.get_response_for_widget(buttons[1]))
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)
250
class GtkUIFactoryTestCase(tests.TestCase):
252
def test__init(self):
253
ui_factory = ui.GtkUIFactory()
254
self.assertIs(None, ui_factory._progress_bar_widget)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
327
def test_progress_all_finished_without_widget(self):
328
ui_factory = ui.GtkUIFactory()
329
self.assertIs(None, ui_factory._progress_all_finished())
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()
340
self.assertIs(None, ui_factory._progress_updated(task))
341
self.assertIs(True, progress_widget.update.called)
343
('test', 1, 2), progress_widget.update.args)
345
def test_progress_updated_without_widget(self):
346
ui_factory = ui.GtkUIFactory()
347
MockMethod.bind(self, ui.ProgressBarWindow, 'update')
348
task = ProgressTask()
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)
357
('test', 1, 2), ui_factory._progress_bar_widget.update.args)
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)
365
None, ui_factory.report_transport_activity(None, None, None))
366
self.assertIs(True, progress_widget.tick.called)
368
def test_report_transport_activity_without_widget(self):
369
ui_factory = ui.GtkUIFactory()
370
MockMethod.bind(self, ui.ProgressBarWindow, 'tick')
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)