diff --git a/tests/functional/openlp_core_ui/test_listpreviewwidget.py b/tests/functional/openlp_core_ui/test_listpreviewwidget.py index e4cd334d4..df0092452 100644 --- a/tests/functional/openlp_core_ui/test_listpreviewwidget.py +++ b/tests/functional/openlp_core_ui/test_listpreviewwidget.py @@ -33,7 +33,6 @@ from tests.functional import MagicMock, patch, call class TestListPreviewWidget(TestCase): - def setUp(self): """ Mock out stuff for all the tests @@ -42,7 +41,6 @@ class TestListPreviewWidget(TestCase): self.mocked_parent = self.parent_patcher.start() self.mocked_parent.width.return_value = 100 self.addCleanup(self.parent_patcher.stop) - def new_list_preview_widget_test(self): """ @@ -56,21 +54,19 @@ class TestListPreviewWidget(TestCase): # THEN: The object is not None, and the _setup() method was called. self.assertIsNotNone(list_preview_widget, 'The ListPreviewWidget object should not be None') self.assertEquals(list_preview_widget.screen_ratio, 1, 'Should not be called') - #self.mocked_setup.assert_called_with(1) - @patch(u'openlp.core.ui.listpreviewwidget.Settings') @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.viewport') @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.resizeRowsToContents') @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.setRowHeight') def replace_recalculate_layout_test_text(self, mocked_setRowHeight, mocked_resizeRowsToContents, - mocked_viewport, mocked_Settings): + mocked_viewport, mocked_Settings): """ - Test if "Max height for non-text slides in slide controller" enabled, text-based slides not affected in replace_service_item and __recalculate_layout. + Test if "Max height for non-text slides..." enabled, txt slides unchanged in replace_service_item & __recalc... """ # GIVEN: A setting to adjust "Max height for non-text slides in slide controller", # a text ServiceItem and a ListPreviewWidget. - + # Mock Settings().value('advanced/slide max height') mocked_Settings_obj = MagicMock() mocked_Settings_obj.value.return_value = 100 @@ -89,28 +85,27 @@ class TestListPreviewWidget(TestCase): list_preview_widget.replace_service_item(service_item, 200, 0) # Change viewport width before forcing a resize mocked_viewport_obj.width.return_value = 400 - + # WHEN: __recalculate_layout() is called (via resizeEvent) list_preview_widget.resizeEvent(None) - + # THEN: resizeRowsToContents should be called twice # (once each in __recalculate_layout and replace_service_item) self.assertEquals(mocked_resizeRowsToContents.call_count, 2, 'Should be called') self.assertEquals(mocked_setRowHeight.call_count, 0, 'Should not be called') - @patch(u'openlp.core.ui.listpreviewwidget.Settings') @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.viewport') @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.resizeRowsToContents') @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.setRowHeight') def replace_recalculate_layout_test_img(self, mocked_setRowHeight, mocked_resizeRowsToContents, - mocked_viewport, mocked_Settings): + mocked_viewport, mocked_Settings): """ - Test if "Max height for non-text slides in slide controller" disabled, image-based slides not resized to the max-height in replace_service_item and __recalculate_layout. + Test if "Max height for non-text slides..." disabled, img slides unchanged in replace_service_item & __recalc... """ # GIVEN: A setting to adjust "Max height for non-text slides in slide controller", # an image ServiceItem and a ListPreviewWidget. - + # Mock Settings().value('advanced/slide max height') mocked_Settings_obj = MagicMock() mocked_Settings_obj.value.return_value = 0 @@ -129,27 +124,26 @@ class TestListPreviewWidget(TestCase): list_preview_widget.replace_service_item(service_item, 200, 0) # Change viewport width before forcing a resize mocked_viewport_obj.width.return_value = 400 - + # WHEN: __recalculate_layout() is called (via resizeEvent) list_preview_widget.resizeEvent(None) - + # THEN: timer should have been started self.assertEquals(mocked_resizeRowsToContents.call_count, 0, 'Should not be called') self.assertEquals(mocked_setRowHeight.call_count, 4, 'Should be called twice for each slide') - calls = [call(0,200), call(1,200),call(0,400), call(1,400)] + calls = [call(0, 200), call(1, 200), call(0, 400), call(1, 400)] mocked_setRowHeight.assert_has_calls(calls) - @patch(u'openlp.core.ui.listpreviewwidget.Settings') @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.viewport') @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.resizeRowsToContents') @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.setRowHeight') def replace_recalculate_layout_test_img_max(self, mocked_setRowHeight, mocked_resizeRowsToContents, - mocked_viewport, mocked_Settings): + mocked_viewport, mocked_Settings): """ - Test if "Max height for non-text slides in slide controller" enabled, image-based slides are resized to the max-height in replace_service_item and __recalculate_layout. + Test if "Max height for non-text slides..." enabled, img slides resized in replace_service_item & __recalc... """ - + # GIVEN: A setting to adjust "Max height for non-text slides in slide controller", # an image ServiceItem and a ListPreviewWidget. # Mock Settings().value('advanced/slide max height') @@ -170,30 +164,29 @@ class TestListPreviewWidget(TestCase): list_preview_widget.replace_service_item(service_item, 200, 0) # Change viewport width before forcing a resize mocked_viewport_obj.width.return_value = 400 - + # WHEN: __recalculate_layout() is called (via resizeEvent) list_preview_widget.resizeEvent(None) - + # THEN: timer should have been started self.assertEquals(mocked_resizeRowsToContents.call_count, 0, 'Should not be called') self.assertEquals(mocked_setRowHeight.call_count, 4, 'Should be called twice for each slide') - calls = [call(0,100), call(1,100),call(0,100), call(1,100)] + calls = [call(0, 100), call(1, 100), call(0, 100), call(1, 100)] mocked_setRowHeight.assert_has_calls(calls) - @patch(u'openlp.core.ui.listpreviewwidget.Settings') @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.viewport') @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.resizeRowsToContents') @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.setRowHeight') @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.cellWidget') def row_resized_test_text(self, mocked_cellWidget, mocked_setRowHeight, mocked_resizeRowsToContents, - mocked_viewport, mocked_Settings): + mocked_viewport, mocked_Settings): """ - Test if "Max height for non-text slides in slide controller" enabled, text-based slides not affected in row_resized. + Test if "Max height for non-text slides..." enabled, text-based slides not affected in row_resized. """ # GIVEN: A setting to adjust "Max height for non-text slides in slide controller", # a text ServiceItem and a ListPreviewWidget. - + # Mock Settings().value('advanced/slide max height') mocked_Settings_obj = MagicMock() mocked_Settings_obj.value.return_value = 100 @@ -210,7 +203,7 @@ class TestListPreviewWidget(TestCase): # Mock self.cellWidget().children().setMaximumWidth() mocked_cellWidget_child = MagicMock() mocked_cellWidget_obj = MagicMock() - mocked_cellWidget_obj.children.return_value = [None,mocked_cellWidget_child] + mocked_cellWidget_obj.children.return_value = [None, mocked_cellWidget_child] mocked_cellWidget.return_value = mocked_cellWidget_obj # init ListPreviewWidget and load service item list_preview_widget = ListPreviewWidget(None, 1) @@ -218,24 +211,23 @@ class TestListPreviewWidget(TestCase): # WHEN: row_resized() is called list_preview_widget.row_resized(0, 100, 150) - + # THEN: self.cellWidget(row, 0).children()[1].setMaximumWidth() should not be called self.assertEquals(mocked_cellWidget_child.setMaximumWidth.call_count, 0, 'Should not be called') - @patch(u'openlp.core.ui.listpreviewwidget.Settings') @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.viewport') @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.resizeRowsToContents') @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.setRowHeight') @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.cellWidget') def row_resized_test_img(self, mocked_cellWidget, mocked_setRowHeight, mocked_resizeRowsToContents, - mocked_viewport, mocked_Settings): + mocked_viewport, mocked_Settings): """ - Test if "Max height for non-text slides in slide controller" disabled, image-based slides not affected in row_resized. + Test if "Max height for non-text slides..." disabled, image-based slides not affected in row_resized. """ # GIVEN: A setting to adjust "Max height for non-text slides in slide controller", # an image ServiceItem and a ListPreviewWidget. - + # Mock Settings().value('advanced/slide max height') mocked_Settings_obj = MagicMock() mocked_Settings_obj.value.return_value = 0 @@ -252,7 +244,7 @@ class TestListPreviewWidget(TestCase): # Mock self.cellWidget().children().setMaximumWidth() mocked_cellWidget_child = MagicMock() mocked_cellWidget_obj = MagicMock() - mocked_cellWidget_obj.children.return_value = [None,mocked_cellWidget_child] + mocked_cellWidget_obj.children.return_value = [None, mocked_cellWidget_child] mocked_cellWidget.return_value = mocked_cellWidget_obj # init ListPreviewWidget and load service item list_preview_widget = ListPreviewWidget(None, 1) @@ -260,24 +252,23 @@ class TestListPreviewWidget(TestCase): # WHEN: row_resized() is called list_preview_widget.row_resized(0, 100, 150) - + # THEN: self.cellWidget(row, 0).children()[1].setMaximumWidth() should not be called self.assertEquals(mocked_cellWidget_child.setMaximumWidth.call_count, 0, 'Should not be called') - @patch(u'openlp.core.ui.listpreviewwidget.Settings') @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.viewport') @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.resizeRowsToContents') @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.setRowHeight') @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.cellWidget') def row_resized_test_img_max(self, mocked_cellWidget, mocked_setRowHeight, mocked_resizeRowsToContents, - mocked_viewport, mocked_Settings): + mocked_viewport, mocked_Settings): """ - Test if "Max height for non-text slides in slide controller" enabled, image-based slides are scaled in row_resized. + Test if "Max height for non-text slides..." enabled, image-based slides are scaled in row_resized. """ # GIVEN: A setting to adjust "Max height for non-text slides in slide controller", # an image ServiceItem and a ListPreviewWidget. - + # Mock Settings().value('advanced/slide max height') mocked_Settings_obj = MagicMock() mocked_Settings_obj.value.return_value = 100 @@ -294,7 +285,7 @@ class TestListPreviewWidget(TestCase): # Mock self.cellWidget().children().setMaximumWidth() mocked_cellWidget_child = MagicMock() mocked_cellWidget_obj = MagicMock() - mocked_cellWidget_obj.children.return_value = [None,mocked_cellWidget_child] + mocked_cellWidget_obj.children.return_value = [None, mocked_cellWidget_child] mocked_cellWidget.return_value = mocked_cellWidget_obj # init ListPreviewWidget and load service item list_preview_widget = ListPreviewWidget(None, 1) @@ -302,6 +293,6 @@ class TestListPreviewWidget(TestCase): # WHEN: row_resized() is called list_preview_widget.row_resized(0, 100, 150) - + # THEN: self.cellWidget(row, 0).children()[1].setMaximumWidth() should be called mocked_cellWidget_child.setMaximumWidth.assert_called_once_with(150)