def test_finished(self): progress_widget = self.progress_container() MockMethod.bind(self, progress_widget, 'hide') MockMethod.bind(self, progress_widget.pb, 'finished') progress_widget.finished() self.assertIs(True, progress_widget.hide.called) self.assertIs(True, progress_widget.pb.finished.called)
def test_clear(self): progress_widget = self.progress_container() MockMethod.bind(self, progress_widget, 'hide') MockMethod.bind(self, progress_widget.pb, 'clear') progress_widget.clear() self.assertIs(True, progress_widget.hide.called) self.assertIs(True, progress_widget.pb.clear.called)
def test_tick(self): progress_widget = self.progress_container() MockMethod.bind(self, progress_widget, 'show_all') MockMethod.bind(self, progress_widget.pb, 'tick') progress_widget.tick() self.assertIs(True, progress_widget.show_all.called) self.assertIs(True, progress_widget.pb.tick.called)
def test_show_user_warning_supressed(self): ui_factory = ui.GtkUIFactory() ui_factory.suppressed_warnings.add('recommend_upgrade') MockMethod.bind(self, ui.WarningDialog, 'run', Gtk.ResponseType.CLOSE) ui_factory.show_user_warning( 'recommend_upgrade', current_format_name='1.0', basedir='./test') self.assertIs(False, ui.WarningDialog.run.called)
def test_progress_all_finished_with_widget(self): ui_factory = ui.GtkUIFactory() progress_widget = ui.ProgressPanel() MockMethod.bind(self, progress_widget, 'finished') ui_factory.set_progress_bar_widget(progress_widget) self.assertIs(None, ui_factory._progress_all_finished()) self.assertIs(True, progress_widget.finished.called)
def test_report_transport_activity_without_widget(self): ui_factory = ui.GtkUIFactory() MockMethod.bind(self, ui.ProgressBarWindow, 'tick') self.assertIs( None, ui_factory.report_transport_activity(None, None, None)) self.assertIsInstance( ui_factory._progress_bar_widget, ui.ProgressBarWindow) self.assertIs(True, ui.ProgressBarWindow.tick.called)
def test_treeview_cursor_cb_with_destroyed_treeview(self): widget = FakeDiffWidget() widget.set_diff_text_sections( [('', None, 'patch1'), ('a', 'a', 'patch2')]) MockMethod.bind(self, widget.diff_view, 'show_diff') widget.treeview.destroy() widget._treeview_cursor_cb(None) self.assertFalse(widget.diff_view.show_diff.called)
def test_report_transport_activity_with_widget(self): ui_factory = ui.GtkUIFactory() progress_widget = ui.ProgressPanel() MockMethod.bind(self, progress_widget, 'tick') ui_factory.set_progress_bar_widget(progress_widget) self.assertIs( None, ui_factory.report_transport_activity(None, None, None)) self.assertIs(True, progress_widget.tick.called)
def test_do_push_without_parent_dir(self): progress_panel = self.setup_ui() from_branch = self.make_from_branch() MockMethod.bind(self, push, 'question_dialog', Gtk.ResponseType.OK) message = push.do_push(from_branch, 'that/there', False) self.assertEqual('1 revision(s) pushed.', message) self.assertEqual(True, push.question_dialog.called) self.assertEqual(True, progress_panel.pb.update.called) self.assertEqual(True, progress_panel.pb.finished.called)
def test_tick(self): # tick() shows the widget, does one pulse, then handles the pending # events in the main loop. MockMethod.bind(self, ui.GtkProgressBar, 'show') MockMethod.bind(self, ui.GtkProgressBar, 'pulse') progress_bar = ui.GtkProgressBar() progress_bar.tick() self.assertIs(True, progress_bar.show.called) self.assertEqual('with_main_iteration', progress_bar.tick.__name__)
def test_get_password(self): ui_factory = ui.GtkUIFactory() MockMethod.bind(self, ui.PasswordDialog, 'run', Gtk.ResponseType.OK) mock_property = MockProperty.bind( self, ui.PasswordDialog, 'passwd', 'secret') password = ui_factory.get_password('test') self.assertIs(True, ui.PasswordDialog.run.called) self.assertIs(True, mock_property.called) self.assertEqual('secret', password)
def test_create_push_message_stacked_on(self): from_branch = object() to_branch = self.make_branch_and_tree('that').branch MockMethod.bind(self, to_branch, 'get_stacked_on_url', 'lp:project') push_result = push.create_push_result(from_branch, to_branch) from_branch = self.make_from_branch() message = push.create_push_message(from_branch, push_result) self.assertEqual( '1 revision(s) pushed.\nStacked on lp:project.', message)
def test_update(self): progress_widget = self.progress_container() MockMethod.bind(self, progress_widget, 'show_all') MockMethod.bind(self, progress_widget.pb, 'update') progress_widget.update('test', 5, 10) self.assertIs(True, progress_widget.show_all.called) self.assertIs(True, progress_widget.pb.update.called) self.assertEqual( ('test', 5, 10), progress_widget.pb.update.args)
def test_update_with_data(self): # update() shows the widget, sets the fraction, then handles the # pending events in the main loop. MockMethod.bind(self, ui.GtkProgressBar, 'show') progress_bar = ui.GtkProgressBar() progress_bar.update(msg='test', current_cnt=5, total_cnt=10) self.assertIs(True, progress_bar.show.called) self.assertEqual(0.5, progress_bar.props.fraction) self.assertEqual(10, progress_bar.total) self.assertEqual(5, progress_bar.current) self.assertEqual('with_main_iteration', progress_bar.update.__name__)
def test_finished(self): # finished() hides the widget, resets the state, then handles the # pending events in the main loop. MockMethod.bind(self, ui.GtkProgressBar, 'hide') progress_bar = ui.GtkProgressBar() progress_bar.finished() self.assertIs(True, progress_bar.hide.called) self.assertEqual(0.0, progress_bar.props.fraction) self.assertIs(None, progress_bar.total) self.assertIs(None, progress_bar.current) self.assertEqual('with_main_iteration', progress_bar.finished.__name__)
def test_progress_updated_without_widget(self): ui_factory = ui.GtkUIFactory() MockMethod.bind(self, ui.ProgressBarWindow, 'update') task = ProgressTask() task.msg = 'test' task.current_cnt = 1 task.total_cnt = 2 self.assertIs(None, ui_factory._progress_updated(task)) self.assertIsInstance( ui_factory._progress_bar_widget, ui.ProgressBarWindow) self.assertIs(True, ui_factory._progress_bar_widget.update.called) self.assertEqual( ('test', 1, 2), ui_factory._progress_bar_widget.update.args)
def test_progress_updated_with_widget(self): ui_factory = ui.GtkUIFactory() progress_widget = ui.ProgressPanel() MockMethod.bind(self, progress_widget, 'update') ui_factory.set_progress_bar_widget(progress_widget) task = ProgressTask() task.msg = 'test' task.current_cnt = 1 task.total_cnt = 2 self.assertIs(None, ui_factory._progress_updated(task)) self.assertIs(True, progress_widget.update.called) self.assertEqual( ('test', 1, 2), progress_widget.update.args)
def test_on_push_clicked_with_divered_branches(self): # Verify that when DivergedBranches is raise, the user can choose # to overwrite the branch. error = errors.DivergedBranches(None, None) MockMethod.bind(self, push, 'do_push', raise_error=error) MockMethod.bind(self, push, 'question_dialog', Gtk.ResponseType.YES) set_ui_factory() branch = self.make_push_branch() dialog = push.PushDialog(None, None, branch) dialog._combo.get_child().props.text = 'lp:~user/fnord/test' dialog._on_push_clicked(None) self.assertIs(True, push.do_push.called) self.assertEqual(2, push.do_push.call_count) self.assertEqual( (branch, 'lp:~user/fnord/test'), push.do_push.args) self.assertEqual( {'overwrite': True}, push.do_push.kwargs)
def test_init(self): # The label, password entry, and buttons are created, then shown. MockMethod.bind(self, Gtk.Box, 'show_all') dialog = ui.PasswordDialog('test password') content_area = dialog.get_content_area() self.assertIs(True, dialog.get_content_area().show_all.called) widgets = content_area.get_children() self.assertEqual('test password', widgets[0].props.label) self.assertEqual(False, widgets[1].props.visibility) buttons = dialog.get_action_area().get_children() self.assertEqual('gtk-cancel', buttons[0].props.label) self.assertEqual( Gtk.ResponseType.CANCEL, dialog.get_response_for_widget(buttons[0])) self.assertEqual('gtk-ok', buttons[1].props.label) self.assertEqual( Gtk.ResponseType.OK, dialog.get_response_for_widget(buttons[1]))
def test_on_push_clicked_without_errors(self): # Verify the dialog's and branch's final states after a push. MockMethod.bind(self, push, 'do_push', "test success") set_ui_factory() branch = self.make_push_branch() dialog = push.PushDialog(None, None, branch) MockMethod.bind(self, dialog._progress_widget, 'tick') dialog._combo.get_child().props.text = 'lp:~user/fnord/test' dialog._on_push_clicked(None) self.assertIs(True, dialog._progress_widget.tick.called) self.assertIs(False, dialog._progress_widget.props.visible) self.assertIs(True, push.do_push.called) self.assertEqual( (branch, 'lp:~user/fnord/test'), push.do_push.args) self.assertEqual( {'overwrite': False}, push.do_push.kwargs) self.assertIs(True, dialog._push_message.props.visible) self.assertEqual('test success', dialog._push_message.props.label) self.assertEqual( 'lp:~user/fnord/test', dialog._history.get_entries()[-1]) self.assertEqual('lp:~user/fnord/test', branch.get_push_location())
def setup_ui(self): set_ui_factory() progress_panel = ProgressPanel() ui.ui_factory.set_progress_bar_widget(progress_panel) MockMethod.bind(self, progress_panel.pb, 'tick') MockMethod.bind(self, progress_panel.pb, 'update') MockMethod.bind(self, progress_panel.pb, 'finished') return progress_panel
def test_clear(self): # clear() is synonymous with finished. MockMethod.bind(self, ui.GtkProgressBar, 'finished') progress_bar = ui.GtkProgressBar() progress_bar.finished() self.assertIs(True, progress_bar.finished.called)
def test_create_push_result_stacked(self): from_branch = object() to_branch = self.make_branch_and_tree('that').branch MockMethod.bind(self, to_branch, 'get_stacked_on_url', 'lp:project') push_result = push.create_push_result(from_branch, to_branch) self.assertEqual('lp:project', push_result.stacked_on)
def test_do_push_without_parent_dir_aborted(self): self.setup_ui() from_branch = self.make_from_branch() MockMethod.bind(self, push, 'question_dialog', Gtk.ResponseType.CANCEL) message = push.do_push(from_branch, 'that/there', False) self.assertEqual('Push aborted.', message)
def test_get_boolean_false(self): ui_factory = ui.GtkUIFactory() MockMethod.bind(self, ui.PromptDialog, 'run', Gtk.ResponseType.NO) boolean_value = ui_factory.get_boolean('test') self.assertIs(True, ui.PromptDialog.run.called) self.assertIs(False, boolean_value)
def test_show_Error(self): ui_factory = ui.GtkUIFactory() MockMethod.bind(self, ui.ErrorDialog, 'run', Gtk.ResponseType.CLOSE) ui_factory.show_error('test') self.assertIs(True, ui.ErrorDialog.run.called)