mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-16 03:07:53 -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
|
@ -2,50 +2,8 @@ from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
|
||||||
from cura.Settings.ExtruderManager import ExtruderManager
|
|
||||||
from cura.Settings.MachineManager import MachineManager
|
|
||||||
from cura.Settings.IntentManager import IntentManager
|
from cura.Settings.IntentManager import IntentManager
|
||||||
|
|
||||||
@pytest.fixture()
|
|
||||||
def global_stack():
|
|
||||||
return MagicMock(name="Global Stack")
|
|
||||||
|
|
||||||
@pytest.fixture()
|
|
||||||
def container_registry(application, global_stack) -> ContainerRegistry:
|
|
||||||
result = MagicMock()
|
|
||||||
mocked_metadata = [{"id": "um3_aa4_pla_smooth", "GUID": "abcxyz", "definition": "ultimaker3", "variant": "AA 0.4", "material_id": "generic_pla", "intent_category": "smooth"},
|
|
||||||
{"id": "um3_aa4_pla_strong", "GUID": "defqrs", "definition": "ultimaker3", "variant": "AA 0.4", "material_id": "generic_pla", "intent_category": "strong"}]
|
|
||||||
result.findContainersMetadata = MagicMock(return_value = mocked_metadata)
|
|
||||||
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
|
|
||||||
|
|
||||||
# TODO: maybe put some definitions above in common file because they copy the ones in TestMachineManager (also there).
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def intent_manager(application, extruder_manager, machine_manager, container_registry, global_stack) -> IntentManager:
|
def intent_manager(application, extruder_manager, machine_manager, container_registry, global_stack) -> IntentManager:
|
||||||
application.getExtruderManager = MagicMock(return_value = extruder_manager)
|
application.getExtruderManager = MagicMock(return_value = extruder_manager)
|
||||||
|
@ -58,6 +16,10 @@ def intent_manager(application, extruder_manager, machine_manager, container_reg
|
||||||
return manager
|
return manager
|
||||||
|
|
||||||
def test_intentCategories(application, intent_manager, container_registry):
|
def test_intentCategories(application, intent_manager, container_registry):
|
||||||
|
mocked_metadata = [{"id": "um3_aa4_pla_smooth", "GUID": "abcxyz", "definition": "ultimaker3", "variant": "AA 0.4", "material_id": "generic_pla", "intent_category": "smooth"},
|
||||||
|
{"id": "um3_aa4_pla_strong", "GUID": "defqrs", "definition": "ultimaker3", "variant": "AA 0.4", "material_id": "generic_pla", "intent_category": "strong"}]
|
||||||
|
container_registry.findContainersMetadata = MagicMock(return_value=mocked_metadata)
|
||||||
|
|
||||||
with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value=application)):
|
with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value=application)):
|
||||||
with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value=container_registry)):
|
with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value=container_registry)):
|
||||||
categories = intent_manager.intentCategories("ultimaker3", "AA 0.4", "generic_pla") # type:List[str]
|
categories = intent_manager.intentCategories("ultimaker3", "AA 0.4", "generic_pla") # type:List[str]
|
||||||
|
|
|
@ -2,42 +2,6 @@ from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
|
||||||
from cura.Settings.ExtruderManager import ExtruderManager
|
|
||||||
from cura.Settings.MachineManager import MachineManager
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
|
||||||
def global_stack():
|
|
||||||
return MagicMock(name="Global Stack")
|
|
||||||
|
|
||||||
@pytest.fixture()
|
|
||||||
def container_registry() -> ContainerRegistry:
|
|
||||||
return MagicMock(name = "ContainerRegistry")
|
|
||||||
|
|
||||||
|
|
||||||
@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("cura.Settings.CuraContainerRegistry.CuraContainerRegistry.getInstance", MagicMock(return_value=container_registry)):
|
|
||||||
manager = MachineManager(application)
|
|
||||||
|
|
||||||
return manager
|
|
||||||
|
|
||||||
|
|
||||||
def test_setActiveMachine(machine_manager):
|
def test_setActiveMachine(machine_manager):
|
||||||
registry = MagicMock()
|
registry = MagicMock()
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
# The purpose of this class is to create fixtures or methods that can be shared among all tests.
|
# 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
|
import pytest
|
||||||
|
|
||||||
# Prevents error: "PyCapsule_GetPointer called with incorrect name" with conflicting SIP configurations between Arcus and PyQt: Import Arcus and Savitar first!
|
# 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.
|
# 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.CuraApplication import CuraApplication
|
||||||
|
from cura.Settings.ExtruderManager import ExtruderManager
|
||||||
|
from cura.Settings.MachineManager import MachineManager
|
||||||
from cura.UI.MachineActionManager import MachineActionManager
|
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.
|
# 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.
|
# Since we need to use it more that once, we create the application the first time and use its instance afterwards.
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def application() -> CuraApplication:
|
def application() -> CuraApplication:
|
||||||
app = unittest.mock.MagicMock()
|
app = MagicMock()
|
||||||
return app
|
return app
|
||||||
|
|
||||||
# Returns a MachineActionManager instance.
|
# Returns a MachineActionManager instance.
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def machine_action_manager(application) -> MachineActionManager:
|
def machine_action_manager(application) -> MachineActionManager:
|
||||||
return MachineActionManager(application)
|
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