1# Copyright (c) 2017 Ultimaker B.V. 2# Uranium is released under the terms of the LGPLv3 or higher. 3 4from unittest.mock import patch 5 6import pytest 7 8from UM.Math.Plane import Plane 9from UM.Scene.SceneNode import SceneNode 10from UM.Scene.Selection import Selection 11from UM.Scene.ToolHandle import ToolHandle 12from UM.Tool import Tool 13 14 15def test_exposedProperties(): 16 17 test_tool_1 = Tool() 18 test_tool_1.setPluginId("test_tool_1") 19 20 test_tool_1.setExposedProperties("bla", "omg", "zomg") 21 assert test_tool_1.getExposedProperties() == ["bla", "omg", "zomg"] 22 23 24test_validate_data = [ 25 {"attribute": "DragPlane", "value": Plane()}, 26 {"attribute": "Handle", "value": None} 27] 28 29 30@pytest.mark.parametrize("data", test_validate_data) 31def test_getAndSet(data): 32 test_tool = Tool() 33 # Attempt to set the value 34 getattr(test_tool, "set" + data["attribute"])(data["value"]) 35 36 # Ensure that the value got set 37 assert getattr(test_tool, "get" + data["attribute"])() == data["value"] 38 39 40def test_toolEnabledChanged(): 41 test_tool_1 = Tool() 42 test_tool_1.setPluginId("test_tool_1") 43 assert test_tool_1.getEnabled() 44 45 # Fake the signal from the controller 46 test_tool_1._onToolEnabledChanged("SomeOtherTOol", True) 47 assert test_tool_1.getEnabled() 48 # Fake the signal from the controller, but this time it's a signal that should force the tool to change. 49 test_tool_1._onToolEnabledChanged("test_tool_1", False) 50 assert not test_tool_1.getEnabled() 51 52 53def test_getShortcutKey(): 54 test_tool_1 = Tool() 55 # Test coverage is magic. It should be None by default. 56 assert test_tool_1.getShortcutKey() is None 57 58 59def test_getDragVector(): 60 test_tool_1 = Tool() 61 test_tool_1.setPluginId("test_tool_1") 62 63 # No drag plane set 64 assert test_tool_1.getDragVector(0, 0) is None 65 test_tool_1.setDragPlane(Plane()) 66 # No drag start 67 assert test_tool_1.getDragVector(0, 0) is None 68 69 70def test_getDragStart(): 71 test_tool_1 = Tool() 72 # Test coverage is magic. It should be None by default. 73 assert test_tool_1.getDragStart() is None 74 75 76def test_getController(): 77 test_tool_1 = Tool() 78 # Test coverage is magic. It should not be None by default, since the application provided one 79 assert test_tool_1.getController() is not None 80 81def test_setLockedAxis(): 82 test_tool_1 = Tool() 83 test_tool_handle_1 = ToolHandle() 84 test_tool_handle_1._enabled = True 85 test_tool_handle_1._auto_scale = False 86 # Pretend like the toolhandle actually got rendered at least once 87 with patch("UM.View.GL.OpenGL.OpenGL.getInstance"): 88 test_tool_handle_1.render(None) 89 90 # Needs to start out with Nothing locked 91 assert test_tool_1.getLockedAxis() == ToolHandle.NoAxis 92 93 # Just the vanilla changing. 94 test_tool_1.setLockedAxis(ToolHandle.XAxis) 95 assert test_tool_1.getLockedAxis() == ToolHandle.XAxis 96 97 test_tool_1.setHandle(test_tool_handle_1) 98 test_tool_1.setLockedAxis(ToolHandle.YAxis) 99 assert test_tool_1.getLockedAxis() == ToolHandle.YAxis 100 assert test_tool_handle_1.getActiveAxis() == ToolHandle.YAxis 101 102 103def test_getSelectedObjectsWithoutSelectedAncestors(): 104 scene_node_1 = SceneNode() 105 Selection.add(scene_node_1) 106 test_tool_1 = Tool() 107 assert test_tool_1._getSelectedObjectsWithoutSelectedAncestors() == [scene_node_1] 108 109 110