12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- from unittest.mock import MagicMock, patch
- import pytest
- from UM.Qt.QtApplication import QtApplication
- from cura.CuraApplication import CuraApplication
- from cura.Settings.ExtruderManager import ExtruderManager
- from cura.Settings.MachineManager import MachineManager
- from cura.UI.MachineActionManager import MachineActionManager
- from UM.Settings.ContainerRegistry import ContainerRegistry
- @pytest.fixture()
- def application() -> CuraApplication:
- app = MagicMock()
- return app
- @pytest.fixture()
- def machine_action_manager(application) -> MachineActionManager:
- return MachineActionManager(application)
- @pytest.fixture()
- def global_stack():
- return MagicMock(name="Global Stack")
- @pytest.fixture()
- def container_registry(application, global_stack) -> ContainerRegistry:
- result = MagicMock()
- result.findContainerStacks = MagicMock(return_value = [global_stack])
- application.getContainerRegistry = MagicMock(return_value = result)
- return result
- @pytest.fixture()
- def extruder_manager(application, container_registry) -> ExtruderManager:
- if ExtruderManager.getInstance() is not None:
-
- ExtruderManager._ExtruderManager__instance = None
- with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value=application)):
- with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value=container_registry)):
- manager = ExtruderManager()
- return manager
- @pytest.fixture()
- def machine_manager(application, extruder_manager, container_registry, global_stack) -> MachineManager:
- application.getExtruderManager = MagicMock(return_value = extruder_manager)
- application.getGlobalContainerStack = MagicMock(return_value = global_stack)
- with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value=container_registry)):
- manager = MachineManager(application)
- return manager
|