Beispiel #1
0
    def test_autoscroll_dist_bounds(self, mocked_slide_count, mocked_item,
                                    mocked_scrollToItem, mocked_selectRow):
        """
        Test if 'advanced/autoscrolling' setting asks to scroll beyond list bounds, that it does not beyond.
        """
        # 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 = 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 = {'dist': 1, 'pos': 1}
        list_preview_widget.change_slide(0)

        # THEN: no further functions should be called
        assert mocked_slide_count.call_count == 3, 'Should be called'
        assert mocked_scrollToItem.call_count == 2, 'Should be called'
        assert mocked_selectRow.call_count == 2, 'Should be called'
        assert mocked_item.call_count == 2, 'Should be called'
        calls = [call(0, 0), call(0, 0)]
        mocked_item.assert_has_calls(calls)
Beispiel #2
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.'
Beispiel #3
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'