Esempio n. 1
0
    def on_clicked_same_color_test(self):
        """
        Test the on_click method when a new color has not been chosen
        """

        # GIVEN: An instance of ColorButton, and a set _color attribute
        widget = ColorButton()
        self.mocked_change_color.reset_mock()
        self.mocked_color_changed.reset_mock()
        widget._color = '#000000'

        # WHEN: The on_clicked method is called, and the color is valid, but the same as the existing color
        self.mocked_qt_gui.QColorDialog.getColor.return_value = MagicMock(
            **{
                'isValid.return_value': True,
                'name.return_value': '#000000'
            })
        widget.on_clicked()

        # THEN: change_color should not have been called and the colorChanged signal should not have been emitted
        self.assertEqual(
            self.mocked_change_color.call_count, 0,
            'change_color should not have been called when the color has not changed'
        )
        self.assertEqual(
            self.mocked_color_changed.emit.call_count, 0,
            'colorChange signal should not have been emitted when the color has not changed'
        )
Esempio n. 2
0
    def on_clicked_new_color_test(self):
        """
        Test the on_click method when a new color has been chosen and is valid
        """

        # GIVEN: An instance of ColorButton, and a set _color attribute
        widget = ColorButton()
        self.mocked_change_color.reset_mock()
        self.mocked_color_changed.reset_mock()
        widget._color = '#000000'

        # WHEN: The on_clicked method is called, and the color is valid, and different to the existing color
        self.mocked_qt_gui.QColorDialog.getColor.return_value = MagicMock(
            **{'isValid.return_value': True, 'name.return_value': '#ffffff'})
        widget.on_clicked()

        # THEN: change_color should have been called and the colorChanged signal should have been emitted
        self.mocked_change_color.assert_called_once_with('#ffffff')
        self.mocked_color_changed.emit.assert_called_once_with('#ffffff')
Esempio n. 3
0
    def on_clicked_invalid_color_test(self):
        """
        Test the on_click method when an invalid color has been supplied
        """

        # GIVEN: An instance of ColorButton, and a set _color attribute
        widget = ColorButton()
        self.mocked_change_color.reset_mock()
        self.mocked_color_changed.reset_mock()
        widget._color = '#000000'

        # WHEN: The on_clicked method is called, and the color is invalid
        self.mocked_qt_gui.QColorDialog.getColor.return_value = MagicMock(**{'isValid.return_value': False})
        widget.on_clicked()

        # THEN: change_color should not have been called and the colorChanged signal should not have been emitted
        self.assertEqual(
            self.mocked_change_color.call_count, 0, 'change_color should not have been called with an invalid color')
        self.assertEqual(
            self.mocked_color_changed.emit.call_count, 0,
            'colorChange signal should not have been emitted with an invalid color')
Esempio n. 4
0
    def on_clicked_new_color_test(self):
        """
        Test the on_click method when a new color has been chosen and is valid
        """

        # GIVEN: An instance of ColorButton, and a set _color attribute
        widget = ColorButton()
        self.mocked_change_color.reset_mock()
        self.mocked_color_changed.reset_mock()
        widget._color = '#000000'

        # WHEN: The on_clicked method is called, and the color is valid, and different to the existing color
        self.mocked_qt_gui.QColorDialog.getColor.return_value = MagicMock(
            **{
                'isValid.return_value': True,
                'name.return_value': '#ffffff'
            })
        widget.on_clicked()

        # THEN: change_color should have been called and the colorChanged signal should have been emitted
        self.mocked_change_color.assert_called_once_with('#ffffff')
        self.mocked_color_changed.emit.assert_called_once_with('#ffffff')
Esempio n. 5
0
    def on_clicked_same_color_test(self):
        """
        Test the on_click method when a new color has not been chosen
        """

        # GIVEN: An instance of ColorButton, and a set _color attribute
        widget = ColorButton()
        self.mocked_change_color.reset_mock()
        self.mocked_color_changed.reset_mock()
        widget._color = '#000000'

        # WHEN: The on_clicked method is called, and the color is valid, but the same as the existing color
        self.mocked_qt_gui.QColorDialog.getColor.return_value = MagicMock(
            **{'isValid.return_value': True, 'name.return_value': '#000000'})
        widget.on_clicked()

        # THEN: change_color should not have been called and the colorChanged signal should not have been emitted
        self.assertEqual(
            self.mocked_change_color.call_count, 0,
            'change_color should not have been called when the color has not changed')
        self.assertEqual(
            self.mocked_color_changed.emit.call_count, 0,
            'colorChange signal should not have been emitted when the color has not changed')
Esempio n. 6
0
    def on_clicked_invalid_color_test(self):
        """
        Test the on_click method when an invalid color has been supplied
        """

        # GIVEN: An instance of ColorButton, and a set _color attribute
        widget = ColorButton()
        self.mocked_change_color.reset_mock()
        self.mocked_color_changed.reset_mock()
        widget._color = '#000000'

        # WHEN: The on_clicked method is called, and the color is invalid
        self.mocked_qt_gui.QColorDialog.getColor.return_value = MagicMock(
            **{'isValid.return_value': False})
        widget.on_clicked()

        # THEN: change_color should not have been called and the colorChanged signal should not have been emitted
        self.assertEqual(
            self.mocked_change_color.call_count, 0,
            'change_color should not have been called with an invalid color')
        self.assertEqual(
            self.mocked_color_changed.emit.call_count, 0,
            'colorChange signal should not have been emitted with an invalid color'
        )