def test_addTools(application):
    controller = Controller(application)

    # Switch out the emits with a mock.
    controller.toolsChanged.emit = MagicMock()
    controller.activeToolChanged.emit = MagicMock()

    test_tool_1 = Tool()
    test_tool_1.setPluginId("test_tool_1")
    test_tool_1.event = MagicMock()
    test_tool_2 = Tool()
    test_tool_2.setPluginId("test_tool_2")

    controller.addTool(test_tool_1)
    assert controller.toolsChanged.emit.call_count == 1

    controller.addTool(test_tool_2)
    assert controller.toolsChanged.emit.call_count == 2

    controller.addTool(test_tool_1)
    assert controller.toolsChanged.emit.call_count == 2
    assert len(controller.getAllTools()) == 2

    # Set active tool with an unknown name.
    controller.setActiveTool("nope nope!")
    assert controller.getActiveTool() is None
    assert controller.activeToolChanged.emit.call_count == 0

    # Set active tool by reference
    controller.setActiveTool(test_tool_1)
    assert controller.getActiveTool() == test_tool_1
    assert controller.activeToolChanged.emit.call_count == 1
    # Check if the tool got notified that it's not active.
    assert test_tool_1.event.call_args_list[0][0][
        0].type == Event.ToolActivateEvent

    # Set active tool by ID, but the same as is already active.
    controller.setActiveTool("test_tool_1")
    assert controller.getActiveTool() == test_tool_1
    assert controller.activeToolChanged.emit.call_count == 1

    # Set active tool by ID
    controller.setActiveTool("test_tool_2")
    assert controller.getActiveTool() == test_tool_2
    assert controller.activeToolChanged.emit.call_count == 2
    # Check if the tool got notified that it's no longer active.
    assert test_tool_1.event.call_args_list[1][0][
        0].type == Event.ToolDeactivateEvent

    assert controller.getTool("ZOMG") is None
    assert controller.getTool("test_tool_1") == test_tool_1
    assert controller.getTool("test_tool_2") == test_tool_2
Exemple #2
0
def test_eventHandling(application):
    controller = Controller(application)

    selection_tool = Tool()
    selection_tool.setPluginId("selection_tool")
    selection_tool.event = MagicMock(return_value = True)

    camera_tool = Tool()
    camera_tool.setPluginId("camera_tool")
    camera_tool.event = MagicMock(return_value=True)

    random_tool = Tool()
    random_tool.setPluginId("random_tool")
    random_tool.event = MagicMock(return_value=True)

    event = Event(1)


    controller.setCameraTool(camera_tool)
    controller.event(event)
    # Only the camera tool should be called now.
    camera_tool.event.assert_called_once_with(event)

    controller.setActiveTool(random_tool)
    random_tool.event.reset_mock() #  We don't care about activation events.
    controller.event(event)
    # The camera tool should not get an extra call
    camera_tool.event.assert_called_once_with(event)
    # But the active tool should have gotten one
    random_tool.event.assert_called_once_with(event)

    controller.setSelectionTool(selection_tool)
    controller.event(event)
    # The camera tool should not get an extra call
    camera_tool.event.assert_called_once_with(event)
    # The active tool should not get an extra call
    random_tool.event.assert_called_once_with(event)
    # But the selection tool should have gotten one
    selection_tool.event.assert_called_once_with(event)
Exemple #3
0
def test_eventHandling(application):
    controller = Controller(application)

    selection_tool = Tool()
    selection_tool.setPluginId("selection_tool")
    selection_tool.event = MagicMock(return_value = True)

    camera_tool = Tool()
    camera_tool.setPluginId("camera_tool")
    camera_tool.event = MagicMock(return_value=True)

    random_tool = Tool()
    random_tool.setPluginId("random_tool")
    random_tool.event = MagicMock(return_value=True)

    event = Event(1)


    controller.setCameraTool(camera_tool)
    controller.event(event)
    # Only the camera tool should be called now.
    camera_tool.event.assert_called_once_with(event)

    controller.setActiveTool(random_tool)
    random_tool.event.reset_mock() #  We don't care about activation events.
    controller.event(event)
    # The camera tool should not get an extra call
    camera_tool.event.assert_called_once_with(event)
    # But the active tool should have gotten one
    random_tool.event.assert_called_once_with(event)

    controller.setSelectionTool(selection_tool)
    controller.event(event)
    # The camera tool should not get an extra call
    camera_tool.event.assert_called_once_with(event)
    # The active tool should not get an extra call
    random_tool.event.assert_called_once_with(event)
    # But the selection tool should have gotten one
    selection_tool.event.assert_called_once_with(event)
Exemple #4
0
def test_addTools(application):
    controller = Controller(application)

    # Switch out the emits with a mock.
    controller.toolsChanged.emit = MagicMock()
    controller.activeToolChanged.emit = MagicMock()

    test_tool_1 = Tool()
    test_tool_1.setPluginId("test_tool_1")
    test_tool_1.event = MagicMock()
    test_tool_2 = Tool()
    test_tool_2.setPluginId("test_tool_2")

    controller.addTool(test_tool_1)
    assert controller.toolsChanged.emit.call_count == 1

    controller.addTool(test_tool_2)
    assert controller.toolsChanged.emit.call_count == 2

    controller.addTool(test_tool_1)
    assert controller.toolsChanged.emit.call_count == 2
    assert len(controller.getAllTools()) == 2

    # Set active tool with an unknown name.
    controller.setActiveTool("nope nope!")
    assert controller.getActiveTool() is None
    assert controller.activeToolChanged.emit.call_count == 0

    # Set active tool by reference
    controller.setActiveTool(test_tool_1)
    assert controller.getActiveTool() == test_tool_1
    assert controller.activeToolChanged.emit.call_count == 1
    # Check if the tool got notified that it's not active.
    assert test_tool_1.event.call_args_list[0][0][0].type == Event.ToolActivateEvent

    # Set active tool by ID, but the same as is already active.
    controller.setActiveTool("test_tool_1")
    assert controller.getActiveTool() == test_tool_1
    assert controller.activeToolChanged.emit.call_count == 1

    # Set active tool by ID
    controller.setActiveTool("test_tool_2")
    assert controller.getActiveTool() == test_tool_2
    assert controller.activeToolChanged.emit.call_count == 2
    # Check if the tool got notified that it's no longer active.
    assert test_tool_1.event.call_args_list[1][0][0].type == Event.ToolDeactivateEvent

    assert controller.getTool("ZOMG") is None
    assert controller.getTool("test_tool_1") == test_tool_1
    assert controller.getTool("test_tool_2") == test_tool_2