From 85182074170fae356f121f5a03ca745b6be33de7 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 1 Jan 2014 14:59:57 +0000 Subject: [PATCH] Fix up test failures --- openlp/core/common/registry.py | 2 +- .../openlp_core_common/test_registry.py | 14 ++--- .../openlp_core_ui/test_listpreviewwidget.py | 4 +- .../openlp_core_ui/test_mainwindow.py | 7 ++- .../openlp_core_ui/test_starttimedialog.py | 60 +++++++++---------- .../openlp_core_ui/test_thememanagerhelper.py | 21 +------ 6 files changed, 43 insertions(+), 65 deletions(-) diff --git a/openlp/core/common/registry.py b/openlp/core/common/registry.py index f0c508da4..5bcf01d0f 100644 --- a/openlp/core/common/registry.py +++ b/openlp/core/common/registry.py @@ -80,7 +80,7 @@ class Registry(object): else: trace_error_handler(log) log.error('Service %s not found in list' % key) - #raise KeyError('Service %s not found in list' % key) + return None def register(self, key, reference): """ diff --git a/tests/functional/openlp_core_common/test_registry.py b/tests/functional/openlp_core_common/test_registry.py index ee236035d..84813195e 100644 --- a/tests/functional/openlp_core_common/test_registry.py +++ b/tests/functional/openlp_core_common/test_registry.py @@ -59,22 +59,18 @@ class TestRegistry(TestCase): with self.assertRaises(KeyError) as context: Registry().register('test1', mock_1) self.assertEqual(context.exception.args[0], 'Duplicate service exception test1', - 'KeyError exception should have been thrown for duplicate service') + 'KeyError exception should have been thrown for duplicate service') # WHEN I try to get back a non existent component # THEN I will get an exception - with self.assertRaises(KeyError) as context: - temp = Registry().get('test2') - self.assertEqual(context.exception.args[0], 'Service test2 not found in list', - 'KeyError exception should have been thrown for missing service') + temp = Registry().get('test2') + self.assertEqual(temp, None, 'KeyError error None should not have been returned for missing service') # WHEN I try to replace a component I should be allowed (testing only) Registry().remove('test1') # THEN I will get an exception - with self.assertRaises(KeyError) as context: - temp = Registry().get('test1') - self.assertEqual(context.exception.args[0], 'Service test1 not found in list', - 'KeyError exception should have been thrown for deleted service') + temp = Registry().get('test1') + self.assertEqual(temp, None, 'KeyError error None should have been returned for deleted service') def registry_function_test(self): """ diff --git a/tests/interfaces/openlp_core_ui/test_listpreviewwidget.py b/tests/interfaces/openlp_core_ui/test_listpreviewwidget.py index f11ad6939..6d638cdd1 100644 --- a/tests/interfaces/openlp_core_ui/test_listpreviewwidget.py +++ b/tests/interfaces/openlp_core_ui/test_listpreviewwidget.py @@ -38,7 +38,7 @@ class TestListPreviewWidget(TestCase): def initial_slide_count_test(self): """ - Test the inital slide count. + Test the initial slide count . """ # GIVEN: A new ListPreviewWidget instance. # WHEN: No SlideItem has been added yet. @@ -47,7 +47,7 @@ class TestListPreviewWidget(TestCase): def initial_slide_number_test(self): """ - Test the inital slide number. + Test the initial current slide number. """ # GIVEN: A new ListPreviewWidget instance. # WHEN: No SlideItem has been added yet. diff --git a/tests/interfaces/openlp_core_ui/test_mainwindow.py b/tests/interfaces/openlp_core_ui/test_mainwindow.py index b073b2219..279fe15db 100644 --- a/tests/interfaces/openlp_core_ui/test_mainwindow.py +++ b/tests/interfaces/openlp_core_ui/test_mainwindow.py @@ -22,12 +22,13 @@ class TestMainWindow(TestCase): # Mock cursor busy/normal methods. self.app.set_busy_cursor = MagicMock() self.app.set_normal_cursor = MagicMock() - self.app.args =[] + self.app.args = [] Registry().register('application', self.app) # Mock classes and methods used by mainwindow. with patch('openlp.core.ui.mainwindow.SettingsForm') as mocked_settings_form, \ patch('openlp.core.ui.mainwindow.ImageManager') as mocked_image_manager, \ - patch('openlp.core.ui.mainwindow.SlideController') as mocked_slide_controller, \ + patch('openlp.core.ui.mainwindow.LiveController') as mocked_live_controller, \ + patch('openlp.core.ui.mainwindow.PreviewController') as mocked_preview_controller, \ patch('openlp.core.ui.mainwindow.OpenLPDockWidget') as mocked_dock_widget, \ patch('openlp.core.ui.mainwindow.QtGui.QToolBox') as mocked_q_tool_box_class, \ patch('openlp.core.ui.mainwindow.QtGui.QMainWindow.addDockWidget') as mocked_add_dock_method, \ @@ -53,7 +54,7 @@ class TestMainWindow(TestCase): mocked_value.side_effect = [True, 2] # WHEN: Call the restore method. - Registry().execute('bootstrap_post_set_up') + self.main_window.restore_current_media_manager_item() # THEN: The current widget should have been set. self.main_window.media_tool_box.setCurrentIndex.assert_called_with(2) diff --git a/tests/interfaces/openlp_core_ui/test_starttimedialog.py b/tests/interfaces/openlp_core_ui/test_starttimedialog.py index 211bd2219..709a5d68f 100644 --- a/tests/interfaces/openlp_core_ui/test_starttimedialog.py +++ b/tests/interfaces/openlp_core_ui/test_starttimedialog.py @@ -34,28 +34,28 @@ class TestStartTimeDialog(TestCase): """ Test StartTimeDialog are defaults correct """ - self.assertEqual(self.form.hourSpinBox.minimum(), 0, 'The minimum hour should stay the same as the dialog') - self.assertEqual(self.form.hourSpinBox.maximum(), 4, 'The maximum hour should stay the same as the dialog') - self.assertEqual(self.form.minuteSpinBox.minimum(), 0, - 'The minimum minute should stay the same as the dialog') - self.assertEqual(self.form.minuteSpinBox.maximum(), 59, - 'The maximum minute should stay the same as the dialog') - self.assertEqual(self.form.secondSpinBox.minimum(), 0, - 'The minimum second should stay the same as the dialog') - self.assertEqual(self.form.secondSpinBox.maximum(), 59, - 'The maximum second should stay the same as the dialog') - self.assertEqual(self.form.hourFinishSpinBox.minimum(), 0, - 'The minimum finish hour should stay the same as the dialog') - self.assertEqual(self.form.hourFinishSpinBox.maximum(), 4, - 'The maximum finish hour should stay the same as the dialog') - self.assertEqual(self.form.minuteFinishSpinBox.minimum(), 0, - 'The minimum finish minute should stay the same as the dialog') - self.assertEqual(self.form.minuteFinishSpinBox.maximum(), 59, - 'The maximum finish minute should stay the same as the dialog') - self.assertEqual(self.form.secondFinishSpinBox.minimum(), 0, - 'The minimum finish second should stay the same as the dialog') - self.assertEqual(self.form.secondFinishSpinBox.maximum(), 59, - 'The maximum finish second should stay the same as the dialog') + self.assertEqual(self.form.hour_spin_box.minimum(), 0, 'The minimum hour should stay the same as the dialog') + self.assertEqual(self.form.hour_spin_box.maximum(), 4, 'The maximum hour should stay the same as the dialog') + self.assertEqual(self.form.minute_spin_box.minimum(), 0, + 'The minimum minute should stay the same as the dialog') + self.assertEqual(self.form.minute_spin_box.maximum(), 59, + 'The maximum minute should stay the same as the dialog') + self.assertEqual(self.form.second_spin_box.minimum(), 0, + 'The minimum second should stay the same as the dialog') + self.assertEqual(self.form.second_spin_box.maximum(), 59, + 'The maximum second should stay the same as the dialog') + self.assertEqual(self.form.hour_finish_spin_box.minimum(), 0, + 'The minimum finish hour should stay the same as the dialog') + self.assertEqual(self.form.hour_finish_spin_box.maximum(), 4, + 'The maximum finish hour should stay the same as the dialog') + self.assertEqual(self.form.minute_finish_spin_box.minimum(), 0, + 'The minimum finish minute should stay the same as the dialog') + self.assertEqual(self.form.minute_finish_spin_box.maximum(), 59, + 'The maximum finish minute should stay the same as the dialog') + self.assertEqual(self.form.second_finish_spin_box.minimum(), 0, + 'The minimum finish second should stay the same as the dialog') + self.assertEqual(self.form.second_finish_spin_box.maximum(), 59, + 'The maximum finish second should stay the same as the dialog') def time_display_test(self): """ @@ -75,22 +75,22 @@ class TestStartTimeDialog(TestCase): QtTest.QTest.mouseClick(ok_widget, QtCore.Qt.LeftButton) # THEN the following input values are returned - self.assertEqual(self.form.hourSpinBox.value(), 0) - self.assertEqual(self.form.minuteSpinBox.value(), 1) - self.assertEqual(self.form.secondSpinBox.value(), 1) + self.assertEqual(self.form.hour_spin_box.value(), 0) + self.assertEqual(self.form.minute_spin_box.value(), 1) + self.assertEqual(self.form.second_spin_box.value(), 1) self.assertEqual(self.form.item['service_item'].start_time, 61, 'The start time should stay the same') # WHEN displaying the UI, changing the time to 2min 3secs and pressing enter self.form.item = {'service_item': mocked_serviceitem} with patch('PyQt4.QtGui.QDialog.exec_'): self.form.exec_() - self.form.minuteSpinBox.setValue(2) - self.form.secondSpinBox.setValue(3) + self.form.minute_spin_box.setValue(2) + self.form.second_spin_box.setValue(3) ok_widget = self.form.button_box.button(self.form.button_box.Ok) QtTest.QTest.mouseClick(ok_widget, QtCore.Qt.LeftButton) # THEN the following values are returned - self.assertEqual(self.form.hourSpinBox.value(), 0) - self.assertEqual(self.form.minuteSpinBox.value(), 2) - self.assertEqual(self.form.secondSpinBox.value(), 3) + self.assertEqual(self.form.hour_spin_box.value(), 0) + self.assertEqual(self.form.minute_spin_box.value(), 2) + self.assertEqual(self.form.second_spin_box.value(), 3) self.assertEqual(self.form.item['service_item'].start_time, 123, 'The start time should have changed') diff --git a/tests/interfaces/openlp_core_ui/test_thememanagerhelper.py b/tests/interfaces/openlp_core_ui/test_thememanagerhelper.py index d0456edc2..b4757fef7 100644 --- a/tests/interfaces/openlp_core_ui/test_thememanagerhelper.py +++ b/tests/interfaces/openlp_core_ui/test_thememanagerhelper.py @@ -50,6 +50,7 @@ class TestThemeManagerHelper(TestCase): Settings().set_filename(self.ini_file) self.helper = ThemeManagerHelper() self.helper.settings_section = "themes" + self.helper.log_debug = MagicMock() def tearDown(self): """ @@ -58,26 +59,6 @@ class TestThemeManagerHelper(TestCase): os.unlink(self.ini_file) os.unlink(Settings().fileName()) - def test_initialise(self): - """ - Test the thememanagerhelper initialise - basic test - """ - # GIVEN: A new a call to initialise - Settings().setValue('themes/global theme', 'my_theme') - self.helper.build_theme_path = MagicMock() - self.helper.load_first_time_themes = MagicMock() - - # WHEN: the initialistion is run - self.helper.initialise() - - # THEN: - self.assertEqual(1, self.helper.build_theme_path.call_count, - 'The function build_theme_path should have been called') - self.assertEqual(1, self.helper.load_first_time_themes.call_count, - 'The function load_first_time_themes should have been called only once') - self.assertEqual(self.helper.global_theme, 'my_theme', - 'The global theme should have been set to my_theme') - def test_build_theme_path(self): """ Test the thememanagerhelper build_theme_path - basic test