コード例 #1
0
    def test_on_default_radio_button_clicked_no_action(self):
        """
        Test that nothing happens when an action hasn't been selected and you click the default radio button
        """
        # GIVEN: Some mocked out methods, a current action, and some shortcuts
        with patch.object(self.form, '_current_item_action') as mocked_current_item_action, \
                patch.object(self.form, '_action_shortcuts') as mocked_action_shortcuts:
            mocked_current_item_action.return_value = None

            # WHEN: The default radio button is clicked
            self.form.on_default_radio_button_clicked(True)

            # THEN: The method should exit early (i.e. the rest of the methods are not called)
            mocked_current_item_action.assert_called_with()
            self.assertEqual(0, mocked_action_shortcuts.call_count)
コード例 #2
0
    def test_on_default_radio_button_clicked_no_action(self):
        """
        Test that nothing happens when an action hasn't been selected and you click the default radio button
        """
        # GIVEN: Some mocked out methods, a current action, and some shortcuts
        with patch.object(self.form, '_current_item_action') as mocked_current_item_action, \
                patch.object(self.form, '_action_shortcuts') as mocked_action_shortcuts:
            mocked_current_item_action.return_value = None

            # WHEN: The default radio button is clicked
            self.form.on_default_radio_button_clicked(True)

            # THEN: The method should exit early (i.e. the rest of the methods are not called)
            mocked_current_item_action.assert_called_with()
            self.assertEqual(0, mocked_action_shortcuts.call_count)
コード例 #3
0
    def test_primary_push_button_checked_key_press_event(self):
        """
        Test the keyPressEvent when the primary push button is checked
        """
        # GIVEN: The primary push button is checked
        with patch.object(self.form, 'keyReleaseEvent') as mocked_key_release_event, \
                patch.object(self.form.primary_push_button, 'isChecked') as mocked_is_checked:
            mocked_is_checked.return_value = True
            mocked_event = MagicMock()

            # WHEN: The event is handled
            self.form.keyPressEvent(mocked_event)

            # THEN: The key should be released
            mocked_key_release_event.assert_called_with(mocked_event)
            self.assertEqual(0, mocked_event.accept.call_count)
コード例 #4
0
    def test_primary_push_button_checked_key_press_event(self):
        """
        Test the keyPressEvent when the primary push button is checked
        """
        # GIVEN: The primary push button is checked
        with patch.object(self.form, 'keyReleaseEvent') as mocked_key_release_event, \
                patch.object(self.form.primary_push_button, 'isChecked') as mocked_is_checked:
            mocked_is_checked.return_value = True
            mocked_event = MagicMock()

            # WHEN: The event is handled
            self.form.keyPressEvent(mocked_event)

            # THEN: The key should be released
            mocked_key_release_event.assert_called_with(mocked_event)
            self.assertEqual(0, mocked_event.accept.call_count)
コード例 #5
0
    def test_on_custom_radio_button_not_toggled(self):
        """
        Test that the custom radio button method exits early when the button is not toggled
        """
        # GIVEN: A not-toggled custom radio button
        with patch.object(self.form, '_current_item_action') as mocked_current_item_action:

            # WHEN: The clicked method is called
            self.form.on_custom_radio_button_clicked(False)

            # THEN: The method should exit early (i.e. the rest of the methods are not called)
            self.assertEqual(0, mocked_current_item_action.call_count)
コード例 #6
0
    def test_on_custom_radio_button_clicked(self):
        """
        Test that the values are copied across correctly when the custom radio button is selected
        """
        # GIVEN: Some mocked out methods, a current action, and some shortcuts
        with patch.object(self.form, '_current_item_action') as mocked_current_item_action, \
                patch.object(self.form, '_action_shortcuts') as mocked_action_shortcuts, \
                patch.object(self.form, 'refresh_shortcut_list') as mocked_refresh_shortcut_list, \
                patch.object(self.form, 'get_shortcut_string') as mocked_get_shortcut_string, \
                patch.object(self.form.primary_push_button, 'setText') as mocked_set_text:
            mocked_action = MagicMock()
            mocked_current_item_action.return_value = mocked_action
            mocked_action_shortcuts.return_value = [QtCore.Qt.Key_Escape]
            mocked_get_shortcut_string.return_value = 'Esc'

            # WHEN: The custom radio button is clicked
            self.form.on_custom_radio_button_clicked(True)

            # THEN: The shorcuts should be copied across
            mocked_current_item_action.assert_called_with()
            mocked_action_shortcuts.assert_called_with(mocked_action)
            mocked_refresh_shortcut_list.assert_called_with()
            mocked_set_text.assert_called_with('Esc')
コード例 #7
0
    def test_on_custom_radio_button_not_toggled(self):
        """
        Test that the custom radio button method exits early when the button is not toggled
        """
        # GIVEN: A not-toggled custom radio button
        with patch.object(
                self.form,
                '_current_item_action') as mocked_current_item_action:

            # WHEN: The clicked method is called
            self.form.on_custom_radio_button_clicked(False)

            # THEN: The method should exit early (i.e. the rest of the methods are not called)
            self.assertEqual(0, mocked_current_item_action.call_count)
コード例 #8
0
    def test_on_custom_radio_button_clicked(self):
        """
        Test that the values are copied across correctly when the custom radio button is selected
        """
        # GIVEN: Some mocked out methods, a current action, and some shortcuts
        with patch.object(self.form, '_current_item_action') as mocked_current_item_action, \
                patch.object(self.form, '_action_shortcuts') as mocked_action_shortcuts, \
                patch.object(self.form, 'refresh_shortcut_list') as mocked_refresh_shortcut_list, \
                patch.object(self.form, 'get_shortcut_string') as mocked_get_shortcut_string, \
                patch.object(self.form.primary_push_button, 'setText') as mocked_set_text:
            mocked_action = MagicMock()
            mocked_current_item_action.return_value = mocked_action
            mocked_action_shortcuts.return_value = [QtCore.Qt.Key_Escape]
            mocked_get_shortcut_string.return_value = 'Esc'

            # WHEN: The custom radio button is clicked
            self.form.on_custom_radio_button_clicked(True)

            # THEN: The shorcuts should be copied across
            mocked_current_item_action.assert_called_with()
            mocked_action_shortcuts.assert_called_with(mocked_action)
            mocked_refresh_shortcut_list.assert_called_with()
            mocked_set_text.assert_called_with('Esc')
コード例 #9
0
    def test_escape_key_press_event(self):
        """
        Test the keyPressEvent when the escape key was pressed
        """
        # GIVEN: A key event that is an escape
        mocked_event = MagicMock()
        mocked_event.key.return_value = QtCore.Qt.Key_Escape

        # WHEN: The event is handled
        with patch.object(self.form, 'close') as mocked_close:
            self.form.keyPressEvent(mocked_event)

            # THEN: The key should be released
            mocked_event.accept.assert_called_with()
            mocked_close.assert_called_with()
コード例 #10
0
    def test_space_key_press_event(self):
        """
        Test the keyPressEvent when the spacebar was pressed
        """
        # GIVEN: A key event that is a space
        mocked_event = MagicMock()
        mocked_event.key.return_value = QtCore.Qt.Key_Space

        # WHEN: The event is handled
        with patch.object(self.form, 'keyReleaseEvent') as mocked_key_release_event:
            self.form.keyPressEvent(mocked_event)

            # THEN: The key should be released
            mocked_key_release_event.assert_called_with(mocked_event)
            self.assertEqual(0, mocked_event.accept.call_count)
コード例 #11
0
    def test_escape_key_press_event(self):
        """
        Test the keyPressEvent when the escape key was pressed
        """
        # GIVEN: A key event that is an escape
        mocked_event = MagicMock()
        mocked_event.key.return_value = QtCore.Qt.Key_Escape

        # WHEN: The event is handled
        with patch.object(self.form, 'close') as mocked_close:
            self.form.keyPressEvent(mocked_event)

            # THEN: The key should be released
            mocked_event.accept.assert_called_with()
            mocked_close.assert_called_with()
コード例 #12
0
    def test_space_key_press_event(self):
        """
        Test the keyPressEvent when the spacebar was pressed
        """
        # GIVEN: A key event that is a space
        mocked_event = MagicMock()
        mocked_event.key.return_value = QtCore.Qt.Key_Space

        # WHEN: The event is handled
        with patch.object(self.form,
                          'keyReleaseEvent') as mocked_key_release_event:
            self.form.keyPressEvent(mocked_event)

            # THEN: The key should be released
            mocked_key_release_event.assert_called_with(mocked_event)
            self.assertEqual(0, mocked_event.accept.call_count)