예제 #1
0
    def test_set_threshold_invalid(self, mocker):
        """
        Test setting the threshold with an invalid value.

        Args:
            mocker: The mocker interface

        Test Condition:
            The threshold property is still 0
            The patch threshold is still 0
        """

        thresh_tool = ThresholdTool(MagicMock(), event_logger=MagicMock())

        patch_mock = MagicMock()
        patch_mock.threshold = 0

        thresh_tool._patch = patch_mock

        thresh_tool.threshold = 7

        assert thresh_tool.threshold == 0
        assert thresh_tool.patch.threshold == 0

        thresh_tool.threshold += 7

        assert thresh_tool.threshold == 0
        assert thresh_tool.patch.threshold == 0
예제 #2
0
    def test_set_threshold_valid(self, mocker):
        """
        Test setting the threshold with a valid value

        Args:
            mocker: The mocker interface

        Test Condition:
            The threshold property has the correct value
            The threshold value for the patch is set to the same value
        """

        thresh_tool = ThresholdTool(MagicMock(), event_logger=MagicMock())

        mock_patch = MagicMock()
        mock_patch.threshold = -1

        thresh_tool.patch = mock_patch
        thresh_tool._new_patch = False
        thresh_tool.threshold = 0.5

        assert thresh_tool.threshold == 0.5
        assert thresh_tool.patch.threshold == 0.5

        thresh_tool.threshold += 0.1

        assert thresh_tool.threshold == 0.6
        assert thresh_tool.patch.threshold == 0.6
예제 #3
0
    def test_set_increment(self):
        """
        Test setting the increment.


        Test Condition:
            The increment is set.
        """

        thresh_tool = ThresholdTool(MagicMock(), event_logger=MagicMock())

        thresh_tool.increment = 76

        assert thresh_tool.increment == 76
예제 #4
0
    def test_set_patch(self):
        """
        Test setting the patch.


        Test Condition:
            The patch is set to the given patch
            The threshold is set to the patches threshold
        """

        thresh_tool = ThresholdTool(MagicMock(), event_logger=MagicMock())

        mock_patch = MagicMock()
        mock_patch.threshold = 0.5

        thresh_tool.patch = mock_patch

        assert thresh_tool._patch == mock_patch
        assert thresh_tool.threshold == 0.5
예제 #5
0
    def test_adjust_threshold_down(self):
        """
        Test decreasing the threshold value.


        Test Condition:
            The threshold is incremented by the increment value.
        """

        thresh_tool = ThresholdTool(MagicMock(), event_logger=MagicMock())
        thresh_tool._patch = MagicMock()
        thresh_tool._patch.mock_patch.threshold.return_value = 0.5

        thresh_tool.threshold = 0.3

        old_thresh = thresh_tool.threshold

        thresh_tool._adjust_threshold(-1)

        assert thresh_tool.threshold == (old_thresh + thresh_tool.increment)
예제 #6
0
    def _init_tools(self):
        """
        Create all the required tools.


        Returns:
            None

        Postconditions:
            self._image_tools will be created as a dictionary of id, tool pairs
        """

        image_tools = {}

        thresh_tool = ThresholdTool(self._undo_manager,
                                    event_logger=self._event_logger)
        image_tools[thresh_tool.id] = thresh_tool

        self._default_tool = thresh_tool.id

        add_reg_tool = AddRegionTool(self._undo_manager,
                                     event_logger=self._event_logger)

        add_reg_tool.bind_brush(self._brush_size_callback)

        image_tools[add_reg_tool.id] = add_reg_tool

        rem_reg_tool = RemoveRegionTool(self._undo_manager,
                                        event_logger=self._event_logger)

        rem_reg_tool.bind_brush(self._brush_size_callback)
        image_tools[rem_reg_tool.id] = rem_reg_tool

        flood_add_tool = FloodAddTool(self._undo_manager,
                                      event_logger=self._event_logger)

        image_tools[flood_add_tool.id] = flood_add_tool

        flood_rem_tool = FloodRemoveTool(self._undo_manager,
                                         event_logger=self._event_logger)

        image_tools[flood_rem_tool.id] = flood_rem_tool

        no_root_tool = NoRootTool(self._undo_manager,
                                  self._next_patch_callback,
                                  event_logger=self._event_logger)

        image_tools[no_root_tool.id] = no_root_tool

        prev_patch_tool = PreviousPatchTool(self._undo_manager,
                                            self._prev_patch_callback,
                                            event_logger=self._event_logger)

        image_tools[prev_patch_tool.id] = prev_patch_tool

        next_patch_tool = NextPatchTool(self._undo_manager,
                                        self._next_patch_callback,
                                        event_logger=self._event_logger)

        image_tools[next_patch_tool.id] = next_patch_tool

        undo_tool = UndoTool(self._undo_manager,
                             self._undo_callback,
                             event_logger=self._event_logger)

        image_tools[undo_tool.id] = undo_tool
        self._undo_id = undo_tool.id

        redo_tool = RedoTool(self._undo_manager,
                             self._redo_callback,
                             event_logger=self._event_logger)

        image_tools[redo_tool.id] = redo_tool
        self._redo_id = redo_tool.id

        for id in image_tools.keys():
            image_tools[id].bind_to(self._display_current_patch)

        self._image_tools = image_tools