From 810fee37eb39c52cdb42b705e35e8ffa85e81725 Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Fri, 28 Jun 2019 12:10:39 +0200 Subject: [PATCH] Start to test other IntentManager functions. Very rudimentary at the moment, need to split the method into 3, and make a class for the setup. This also uncovered that the currentAvailableIntents doesn't (unless the global stack is missing) retrun any default intents, while currentAvailableIntentCategories does do that. Since it's not clear how we're going to handle that right now, I made a TODO in the code, which of course will have to be fixed before this/these branch/es are merged. part of CURA-6091 --- cura/Settings/IntentManager.py | 4 +++- tests/TestIntentManager.py | 25 ++++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/cura/Settings/IntentManager.py b/cura/Settings/IntentManager.py index a5d71a918d..db7eb7b40a 100644 --- a/cura/Settings/IntentManager.py +++ b/cura/Settings/IntentManager.py @@ -71,9 +71,11 @@ class IntentManager(QObject): global_stack = application.getGlobalContainerStack() if global_stack is None: return [("default", "normal")] + # TODO: We now do this (return a default) if the global stack is missing, but not in the code below, + # even though there should always be defaults. The problem then is what to do with the quality_types. + # Currently _also_ inconsistent with 'currentAvailableIntentCategoreis', which _does_ return default. quality_groups = application.getQualityManager().getQualityGroups(global_stack) available_quality_types = {quality_group.quality_type for quality_group in quality_groups.values() if quality_group.node_for_global is not None} - # available_quality_types could just be 'quality_group.keys()', except for that the node_for_global may be None final_intent_ids = set() #type: Set[str] current_definition_id = global_stack.definition.getMetaDataEntry("id") diff --git a/tests/TestIntentManager.py b/tests/TestIntentManager.py index af5a2437c3..1012f8e2eb 100644 --- a/tests/TestIntentManager.py +++ b/tests/TestIntentManager.py @@ -50,6 +50,8 @@ def test_intentCategories(application, intent_manager, container_registry): def test_currentAvailableIntents(application, extruder_manager, quality_manager, intent_manager, container_registry, global_stack): + # This also tests 'currentAvailableIntentCategories' and 'selectIntent' since the methods are so similar + mocked_qualitygroup_metadata = { "normal": QualityGroup("um3_aa4_pla_normal", "normal"), "abnorm": QualityGroup("um3_aa4_pla_abnorm", "abnorm")} # type:Dict[str, QualityGroup] @@ -88,17 +90,22 @@ def test_currentAvailableIntents(application, extruder_manager, quality_manager, with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value=application)): with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value=container_registry)): with patch("cura.Settings.ExtruderManager.ExtruderManager.getInstance", MagicMock(return_value=extruder_manager)): + intents = intent_manager.currentAvailableIntents() assert ("smooth", "normal") in intents assert ("strong", "abnorm") in intents - assert len(intents) == 2 + #assert ("default", "normal") in intents # Pending to-do in 'IntentManager'. + #assert ("default", "abnorm") in intents # Pending to-do in 'IntentManager'. + assert len(intents) == 2 # Or 4? pending to-do in 'IntentManager'. + categories = intent_manager.currentAvailableIntentCategories() + assert "default" in categories # Currently inconsistent with 'currentAvailableIntents'! + assert "smooth" in categories + assert "strong" in categories + assert len(categories) == 3 -def test_currentAvailableIntentCategories(application, quality_manager, intent_manager, container_registry): - # def currentAvailableIntentCategories(self) -> List[str]: - pass - - -def test_selectIntent(application, intent_manager, container_registry): - # def selectIntent(self, intent_category, quality_type) -> None: - pass + for intent, quality in intents: + intent_manager.selectIntent(intent, quality) + assert extruder_stack_a.intent is not None + assert extruder_stack_b.intent is not None + # ... need MachineManager for this, split up methods anyway -> make into class, see examples others