Esempio n. 1
0
 def setUp(self):
     """
     Create the UI.
     """
     Registry.create()
     self.setup_application()
     self.main_window = QtWidgets.QMainWindow()
     self.image = QtGui.QImage(1, 1, QtGui.QImage.Format_RGB32)
     self.image_manager = MagicMock()
     self.image_manager.get_image.return_value = self.image
     Registry().register('image_manager', self.image_manager)
     self.preview_widget = ListPreviewWidget(self.main_window, 2)
Esempio n. 2
0
    def test_autoscroll_normal(self, mocked_slide_count, mocked_item,
                               mocked_scrollToItem, mocked_selectRow):
        """
        Test if 'advanced/autoscrolling' setting valid, autoscrolling called as expected.
        """
        # GIVEN: A setting for autoscrolling and a ListPreviewWidget.
        # Mock Settings().value('advanced/autoscrolling')
        self.mocked_Settings_obj.value.return_value = {'dist': -1, 'pos': 1}
        # Mocked returns
        mocked_slide_count.return_value = 3
        mocked_item.return_value = None
        # init ListPreviewWidget and load service item
        list_preview_widget = ListPreviewWidget(None, 1)

        # WHEN: change_slide() is called
        list_preview_widget.change_slide(1)
        self.mocked_Settings_obj.value.return_value = {'dist': 0, 'pos': 1}
        list_preview_widget.change_slide(1)
        self.mocked_Settings_obj.value.return_value = {'dist': 1, 'pos': 1}
        list_preview_widget.change_slide(1)

        # THEN: no further functions should be called
        assert mocked_slide_count.call_count == 3, 'Should be called'
        assert mocked_scrollToItem.call_count == 3, 'Should be called'
        assert mocked_selectRow.call_count == 3, 'Should be called'
        assert mocked_item.call_count == 3, 'Should be called'
        calls = [call(0, 0), call(1, 0), call(2, 0)]
        mocked_item.assert_has_calls(calls)
Esempio n. 3
0
 def setUp(self):
     """
     Create the UI.
     """
     Registry.create()
     self.setup_application()
     State().load_settings()
     State().add_service("media", 0)
     State().update_pre_conditions("media", True)
     State().flush_preconditions()
     self.main_window = QtWidgets.QMainWindow()
     self.image = QtGui.QImage(1, 1, QtGui.QImage.Format_RGB32)
     self.image_manager = MagicMock()
     self.image_manager.get_image.return_value = self.image
     Registry().register('image_manager', self.image_manager)
     self.preview_widget = ListPreviewWidget(self.main_window, 2)
     Registry().register('settings', Settings())
Esempio n. 4
0
    def test_new_list_preview_widget(self):
        """
        Test that creating an instance of ListPreviewWidget works
        """
        # GIVEN: A ListPreviewWidget class

        # WHEN: An object is created
        list_preview_widget = ListPreviewWidget(None, 1)

        # THEN: The object is not None, and the _setup() method was called.
        assert list_preview_widget is not None, 'The ListPreviewWidget object should not be None'
        assert list_preview_widget.screen_ratio == 1, 'Should not be called'
Esempio n. 5
0
    def test_replace_recalculate_layout_img_auto(self, mocked_setRowHeight,
                                                 mocked_resizeRowsToContents):
        """
        Test if "Max height for non-text slides..." auto, 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')
        self.mocked_Settings_obj.value.return_value = -4
        # Mock self.viewport().width()
        self.mocked_viewport_obj.width.return_value = 200
        self.mocked_viewport_obj.height.return_value = 600
        # Mock image service item
        service_item = MagicMock()
        service_item.is_text.return_value = False
        service_item.is_capable.return_value = False
        service_item.get_frames.return_value = [{
            'title': None,
            'path': None,
            'image': None
        }, {
            'title': None,
            'path': None,
            'image': None
        }]
        # init ListPreviewWidget and load service item
        list_preview_widget = ListPreviewWidget(None, 1)
        list_preview_widget.replace_service_item(service_item, 200, 0)
        # Change viewport width before forcing a resize
        self.mocked_viewport_obj.width.return_value = 400

        # WHEN: __recalculate_layout() is called (via screen_size_changed)
        list_preview_widget.screen_size_changed(1)
        self.mocked_viewport_obj.height.return_value = 200
        list_preview_widget.screen_size_changed(1)

        # THEN: resizeRowsToContents() should not be called, while setRowHeight() should be called
        #       twice for each slide.
        assert mocked_resizeRowsToContents.call_count == 0, 'Should not be called'
        assert mocked_setRowHeight.call_count == 6, 'Should be called 3 times for each slide'
        calls = [
            call(0, 100),
            call(1, 100),
            call(0, 150),
            call(1, 150),
            call(0, 100),
            call(1, 100)
        ]
        mocked_setRowHeight.assert_has_calls(calls)
Esempio n. 6
0
    def test_replace_service_item_thumbs(self, mocked_setRowHeight,
                                         mocked_resizeRowsToContents,
                                         mocked_image_manager):
        """
        Test that thubmails for different slides are loaded properly in replace_service_item.
        """
        # GIVEN: A setting to adjust "Max height for non-text slides in slide controller",
        #        different ServiceItem(s), an ImageManager, and a ListPreviewWidget.

        # Mock Settings().value('advanced/slide max height')
        self.mocked_Settings_obj.value.return_value = 0
        # Mock self.viewport().width()
        self.mocked_viewport_obj.width.return_value = 200
        # Mock Image service item
        mocked_img_service_item = MagicMock()
        mocked_img_service_item.is_text.return_value = False
        mocked_img_service_item.is_media.return_value = False
        mocked_img_service_item.is_command.return_value = False
        mocked_img_service_item.is_capable.return_value = False
        mocked_img_service_item.get_frames.return_value = [{
            'title': None,
            'path': 'TEST1',
            'image': 'FAIL'
        }, {
            'title': None,
            'path': 'TEST2',
            'image': 'FAIL'
        }]
        # Mock Command service item
        mocked_cmd_service_item = MagicMock()
        mocked_cmd_service_item.is_text.return_value = False
        mocked_cmd_service_item.is_media.return_value = False
        mocked_cmd_service_item.is_command.return_value = True
        mocked_cmd_service_item.is_capable.return_value = True
        mocked_cmd_service_item.get_frames.return_value = [{
            'title': None,
            'path': 'FAIL',
            'image': 'TEST3'
        }, {
            'title': None,
            'path': 'FAIL',
            'image': 'TEST4'
        }]
        # Mock image_manager
        mocked_image_manager.get_image.return_value = QtGui.QImage()

        # init ListPreviewWidget and load service item
        list_preview_widget = ListPreviewWidget(None, 1)

        # WHEN: replace_service_item is called
        list_preview_widget.replace_service_item(mocked_img_service_item, 200,
                                                 0)
        list_preview_widget.replace_service_item(mocked_cmd_service_item, 200,
                                                 0)
Esempio n. 7
0
    def test_row_resized_img(self, mocked_cellWidget, mocked_setRowHeight,
                             mocked_resizeRowsToContents):
        """
        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')
        self.mocked_Settings_obj.value.return_value = 0
        # Mock self.viewport().width()
        self.mocked_viewport_obj.width.return_value = 200
        # Mock image service item
        service_item = MagicMock()
        service_item.is_text.return_value = False
        service_item.is_capable.return_value = False
        service_item.get_frames.return_value = [{
            'title': None,
            'path': None,
            'image': CLAPPERBOARD
        }, {
            'title': None,
            'path': None,
            'image': CLAPPERBOARD
        }]
        # 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.return_value = mocked_cellWidget_obj
        # init ListPreviewWidget and load service item
        list_preview_widget = ListPreviewWidget(None, 1)
        list_preview_widget.replace_service_item(service_item, 200, 0)

        # WHEN: row_resized() is called
        list_preview_widget.row_resized(0, 100, 150)
        self.mocked_Settings_obj.value.return_value = None
        list_preview_widget.row_resized(0, 100, 150)

        # THEN: self.cellWidget(row, 0).children()[1].setMaximumWidth() should not be called
        assert mocked_cellWidget_child.setMaximumWidth.call_count == 0, 'Should not be called'
Esempio n. 8
0
    def test_replace_recalculate_layout_img(self, mocked_setRowHeight,
                                            mocked_resizeRowsToContents):
        """
        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')
        self.mocked_Settings_obj.value.return_value = 0
        # Mock self.viewport().width()
        self.mocked_viewport_obj.width.return_value = 200
        # Mock image service item
        service_item = MagicMock()
        service_item.is_text.return_value = False
        service_item.is_capable.return_value = False
        service_item.get_frames.return_value = [{
            'title': None,
            'path': None,
            'image': CLAPPERBOARD
        }, {
            'title': None,
            'path': None,
            'image': CLAPPERBOARD
        }]
        # init ListPreviewWidget and load service item
        list_preview_widget = ListPreviewWidget(None, 1)
        list_preview_widget.replace_service_item(service_item, 200, 0)
        # Change viewport width before forcing a resize
        self.mocked_viewport_obj.width.return_value = 400

        # WHEN: __recalculate_layout() is called (via resizeEvent)
        list_preview_widget.resizeEvent(None)
        self.mocked_Settings_obj.value.return_value = None
        list_preview_widget.resizeEvent(None)

        # THEN: resizeRowsToContents() should not be called, while setRowHeight() should be called
        #       twice for each slide.
        assert mocked_resizeRowsToContents.call_count == 0, 'Should not be called'
        assert mocked_setRowHeight.call_count == 0, 'Should not be called'
Esempio n. 9
0
    def test_row_resized_setting_changed(self, mocked_cellWidget,
                                         mocked_setRowHeight,
                                         mocked_resizeRowsToContents):
        """
        Test if "Max height for non-text slides..." enabled while item live, program doesn't crash on 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')
        self.mocked_Settings_obj.value.return_value = 0
        # Mock self.viewport().width()
        self.mocked_viewport_obj.width.return_value = 200
        # Mock image service item
        service_item = MagicMock()
        service_item.is_text.return_value = False
        service_item.is_capable.return_value = False
        service_item.get_frames.return_value = [{
            'title': None,
            'path': None,
            'image': CLAPPERBOARD
        }, {
            'title': None,
            'path': None,
            'image': CLAPPERBOARD
        }]
        # Mock self.cellWidget().children()
        mocked_cellWidget_obj = MagicMock()
        mocked_cellWidget_obj.children.return_value = None
        mocked_cellWidget.return_value = mocked_cellWidget_obj
        # init ListPreviewWidget and load service item
        list_preview_widget = ListPreviewWidget(None, 1)
        list_preview_widget.replace_service_item(service_item, 200, 0)
        self.mocked_Settings_obj.value.return_value = 100

        # WHEN: row_resized() is called
        list_preview_widget.row_resized(0, 100, 150)

        # THEN: self.cellWidget(row, 0).children()[1].setMaximumWidth() should fail
        self.assertRaises(Exception)
Esempio n. 10
0
    def test_replace_recalculate_layout_text(self, mocked_setRowHeight,
                                             mocked_resizeRowsToContents):
        """
        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')
        self.mocked_Settings_obj.value.return_value = 100
        # Mock self.viewport().width()
        self.mocked_viewport_obj.width.return_value = 200
        # Mock text service item
        service_item = MagicMock()
        service_item.is_text.return_value = True
        service_item.get_frames.return_value = [{
            'title': None,
            'text': None,
            'verseTag': None
        }, {
            'title': None,
            'text': None,
            'verseTag': None
        }]
        # init ListPreviewWidget and load service item
        list_preview_widget = ListPreviewWidget(None, 1)
        list_preview_widget.replace_service_item(service_item, 200, 0)
        # Change viewport width before forcing a resize
        self.mocked_viewport_obj.width.return_value = 400

        # WHEN: __recalculate_layout() is called (via resizeEvent)
        list_preview_widget.resizeEvent(None)

        # THEN: setRowHeight() should not be called, while resizeRowsToContents() should be called twice
        #       (once each in __recalculate_layout and replace_service_item)
        assert mocked_resizeRowsToContents.call_count == 2, 'Should be called'
        assert mocked_setRowHeight.call_count == 0, 'Should not be called'
Esempio n. 11
0
class TestListPreviewWidget(TestCase, TestMixin):
    def setUp(self):
        """
        Create the UI.
        """
        Registry.create()
        self.setup_application()
        State().load_settings()
        State().add_service("media", 0)
        State().update_pre_conditions("media", True)
        State().flush_preconditions()
        self.main_window = QtWidgets.QMainWindow()
        self.image = QtGui.QImage(1, 1, QtGui.QImage.Format_RGB32)
        self.image_manager = MagicMock()
        self.image_manager.get_image.return_value = self.image
        Registry().register('image_manager', self.image_manager)
        self.preview_widget = ListPreviewWidget(self.main_window, 2)
        Registry().register('settings', Settings())

    def tearDown(self):
        """
        Delete all the C++ objects at the end so that we don't have a segfault.
        """
        del self.preview_widget
        del self.main_window

    def test_initial_slide_count(self):
        """
        Test the initial slide count .
        """
        # GIVEN: A new ListPreviewWidget instance.
        # WHEN: No SlideItem has been added yet.
        # THEN: The count of items should be zero.
        assert self.preview_widget.slide_count(
        ) == 0, 'The slide list should be empty.'

    def test_initial_slide_number(self):
        """
        Test the initial current slide number.
        """
        # GIVEN: A new ListPreviewWidget instance.
        # WHEN: No SlideItem has been added yet.
        # THEN: The number of the current item should be -1.
        assert self.preview_widget.current_slide_number(
        ) == -1, 'The slide number should be -1.'

    def test_replace_service_item(self):
        """
        Test item counts and current number with a service item.
        """
        # GIVEN: A ServiceItem with two frames.
        service_item = ServiceItem(None)
        service = read_service_from_file('serviceitem_image_3.osj')
        with patch('os.path.exists'):
            service_item.set_from_service(service[0])
        # WHEN: Added to the preview widget.
        self.preview_widget.replace_service_item(service_item, 1, 1)
        # THEN: The slide count and number should fit.
        assert self.preview_widget.slide_count(
        ) == 2, 'The slide count should be 2.'
        assert self.preview_widget.current_slide_number(
        ) == 1, 'The current slide number should  be 1.'

    def test_change_slide(self):
        """
        Test the change_slide method.
        """
        # GIVEN: A ServiceItem with two frames content.
        service_item = ServiceItem(None)
        service = read_service_from_file('serviceitem_image_3.osj')
        with patch('os.path.exists'):
            service_item.set_from_service(service[0])
        # WHEN: Added to the preview widget and switched to the second frame.
        self.preview_widget.replace_service_item(service_item, 1, 0)
        self.preview_widget.change_slide(1)
        # THEN: The current_slide_number should reflect the change.
        assert self.preview_widget.current_slide_number(
        ) == 1, 'The current slide number should  be 1.'
Esempio n. 12
0
    def test_autoscroll_setting_invalid(self, mocked_slide_count, mocked_item,
                                        mocked_scrollToItem, mocked_selectRow):
        """
        Test if 'advanced/autoscrolling' setting None or invalid, that no autoscrolling occurs on change_slide().
        """
        # GIVEN: A setting for autoscrolling and a ListPreviewWidget.
        # Mock Settings().value('advanced/autoscrolling')
        self.mocked_Settings_obj.value.return_value = None
        # Mocked returns
        mocked_slide_count.return_value = 1
        mocked_item.return_value = None
        # init ListPreviewWidget and load service item
        list_preview_widget = ListPreviewWidget(None, 1)

        # WHEN: change_slide() is called
        list_preview_widget.change_slide(0)
        self.mocked_Settings_obj.value.return_value = 1
        list_preview_widget.change_slide(0)
        self.mocked_Settings_obj.value.return_value = {'fail': 1}
        list_preview_widget.change_slide(0)
        self.mocked_Settings_obj.value.return_value = {'dist': 1, 'fail': 1}
        list_preview_widget.change_slide(0)
        self.mocked_Settings_obj.value.return_value = {
            'dist': 'fail',
            'pos': 1
        }
        list_preview_widget.change_slide(0)
        self.mocked_Settings_obj.value.return_value = {
            'dist': 1,
            'pos': 'fail'
        }
        list_preview_widget.change_slide(0)

        # THEN: no further functions should be called
        assert mocked_slide_count.call_count == 0, 'Should not be called'
        assert mocked_scrollToItem.call_count == 0, 'Should not be called'
        assert mocked_selectRow.call_count == 0, 'Should not be called'
        assert mocked_item.call_count == 0, 'Should not be called'