mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-23 22:54:01 -06:00
Refactor: Move common fixtures to 'conftest'.
Part of CURA-6091.
This commit is contained in:
parent
96bb1e8915
commit
02516f0f47
3 changed files with 41 additions and 80 deletions
|
@ -3,7 +3,7 @@
|
|||
|
||||
# The purpose of this class is to create fixtures or methods that can be shared among all tests.
|
||||
|
||||
import unittest.mock
|
||||
from unittest.mock import MagicMock, patch
|
||||
import pytest
|
||||
|
||||
# Prevents error: "PyCapsule_GetPointer called with incorrect name" with conflicting SIP configurations between Arcus and PyQt: Import Arcus and Savitar first!
|
||||
|
@ -13,16 +13,51 @@ from UM.Qt.QtApplication import QtApplication # QtApplication import is require
|
|||
# Even though your IDE says these files are not used, don't believe it. It's lying. They need to be there.
|
||||
|
||||
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
|
||||
|
||||
# Create a CuraApplication object that will be shared among all tests. It needs to be initialized.
|
||||
# Since we need to use it more that once, we create the application the first time and use its instance afterwards.
|
||||
@pytest.fixture()
|
||||
def application() -> CuraApplication:
|
||||
app = unittest.mock.MagicMock()
|
||||
app = MagicMock()
|
||||
return app
|
||||
|
||||
# Returns a MachineActionManager instance.
|
||||
@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:
|
||||
# Reset the data
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue