diff options
author | Remco Burema <r.burema@ultimaker.com> | 2019-06-21 15:58:55 +0300 |
---|---|---|
committer | Remco Burema <r.burema@ultimaker.com> | 2019-06-21 15:58:55 +0300 |
commit | 02516f0f477e5c4bf1da16c7698b3df2616b6bc2 (patch) | |
tree | 7506cf31087372cbd31cca33b8d86e7da487dcae /tests/TestIntentManager.py | |
parent | 96bb1e8915f010e701445872d2762ab470b7a06d (diff) |
Refactor: Move common fixtures to 'conftest'.
Part of CURA-6091.
Diffstat (limited to 'tests/TestIntentManager.py')
-rw-r--r-- | tests/TestIntentManager.py | 46 |
1 files changed, 4 insertions, 42 deletions
diff --git a/tests/TestIntentManager.py b/tests/TestIntentManager.py index 519fa49994..01f8cb310b 100644 --- a/tests/TestIntentManager.py +++ b/tests/TestIntentManager.py @@ -2,51 +2,9 @@ from unittest.mock import MagicMock, patch 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 @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() def intent_manager(application, extruder_manager, machine_manager, container_registry, global_stack) -> IntentManager: application.getExtruderManager = MagicMock(return_value = extruder_manager) application.getGlobalContainerStack = MagicMock(return_value = global_stack) @@ -58,6 +16,10 @@ def intent_manager(application, extruder_manager, machine_manager, container_reg return manager 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("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value=container_registry)): categories = intent_manager.intentCategories("ultimaker3", "AA 0.4", "generic_pla") # type:List[str] |