mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-20 13:17:51 -06:00
Add some property tests for MachineManager
This commit is contained in:
parent
1affc345b9
commit
87fb495e07
2 changed files with 53 additions and 18 deletions
|
@ -337,7 +337,7 @@ class MachineManager(QObject):
|
||||||
# that situation will be fixed (and not occur again, since it switches it out to the preferred variant or
|
# that situation will be fixed (and not occur again, since it switches it out to the preferred variant or
|
||||||
# variant instead!)
|
# variant instead!)
|
||||||
machine_node = ContainerTree.getInstance().machines[global_stack.definition.getId()]
|
machine_node = ContainerTree.getInstance().machines[global_stack.definition.getId()]
|
||||||
for extruder in global_stack.extruderList:
|
for extruder in self._global_container_stack.extruderList:
|
||||||
variant_name = extruder.variant.getName()
|
variant_name = extruder.variant.getName()
|
||||||
variant_node = machine_node.variants.get(variant_name)
|
variant_node = machine_node.variants.get(variant_name)
|
||||||
if variant_node is None:
|
if variant_node is None:
|
||||||
|
@ -588,14 +588,14 @@ class MachineManager(QObject):
|
||||||
|
|
||||||
@pyqtProperty(str, notify = activeQualityGroupChanged)
|
@pyqtProperty(str, notify = activeQualityGroupChanged)
|
||||||
def activeQualityType(self) -> str:
|
def activeQualityType(self) -> str:
|
||||||
global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
global_stack = self._application.getGlobalContainerStack()
|
||||||
if not global_stack:
|
if not global_stack:
|
||||||
return ""
|
return ""
|
||||||
return global_stack.quality.getMetaDataEntry("quality_type")
|
return global_stack.quality.getMetaDataEntry("quality_type")
|
||||||
|
|
||||||
@pyqtProperty(bool, notify = activeQualityGroupChanged)
|
@pyqtProperty(bool, notify = activeQualityGroupChanged)
|
||||||
def isActiveQualitySupported(self) -> bool:
|
def isActiveQualitySupported(self) -> bool:
|
||||||
global_container_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
global_container_stack = self._application.getGlobalContainerStack()
|
||||||
if not global_container_stack:
|
if not global_container_stack:
|
||||||
return False
|
return False
|
||||||
active_quality_group = self.activeQualityGroup()
|
active_quality_group = self.activeQualityGroup()
|
||||||
|
@ -603,9 +603,10 @@ class MachineManager(QObject):
|
||||||
return False
|
return False
|
||||||
return active_quality_group.is_available
|
return active_quality_group.is_available
|
||||||
|
|
||||||
|
|
||||||
@pyqtProperty(bool, notify = activeQualityGroupChanged)
|
@pyqtProperty(bool, notify = activeQualityGroupChanged)
|
||||||
def isActiveQualityExperimental(self) -> bool:
|
def isActiveQualityExperimental(self) -> bool:
|
||||||
global_container_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
global_container_stack = self._application.getGlobalContainerStack()
|
||||||
if not global_container_stack:
|
if not global_container_stack:
|
||||||
return False
|
return False
|
||||||
active_quality_group = self.activeQualityGroup()
|
active_quality_group = self.activeQualityGroup()
|
||||||
|
@ -615,7 +616,7 @@ class MachineManager(QObject):
|
||||||
|
|
||||||
@pyqtProperty(str, notify = activeIntentChanged)
|
@pyqtProperty(str, notify = activeIntentChanged)
|
||||||
def activeIntentCategory(self) -> str:
|
def activeIntentCategory(self) -> str:
|
||||||
global_container_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
global_container_stack = self._application.getGlobalContainerStack()
|
||||||
|
|
||||||
if not global_container_stack:
|
if not global_container_stack:
|
||||||
return ""
|
return ""
|
||||||
|
@ -624,7 +625,7 @@ class MachineManager(QObject):
|
||||||
# Provies a list of extruder positions that have a different intent from the active one.
|
# Provies a list of extruder positions that have a different intent from the active one.
|
||||||
@pyqtProperty("QStringList", notify=activeIntentChanged)
|
@pyqtProperty("QStringList", notify=activeIntentChanged)
|
||||||
def extruderPositionsWithNonActiveIntent(self):
|
def extruderPositionsWithNonActiveIntent(self):
|
||||||
global_container_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
global_container_stack = _application.getGlobalContainerStack()
|
||||||
|
|
||||||
if not global_container_stack:
|
if not global_container_stack:
|
||||||
return []
|
return []
|
||||||
|
@ -693,7 +694,7 @@ class MachineManager(QObject):
|
||||||
|
|
||||||
:returns: DefinitionID (string) if found, empty string otherwise
|
:returns: DefinitionID (string) if found, empty string otherwise
|
||||||
"""
|
"""
|
||||||
global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
global_stack = self._application.getGlobalContainerStack()
|
||||||
if not global_stack:
|
if not global_stack:
|
||||||
return ""
|
return ""
|
||||||
return ContainerTree.getInstance().machines[global_stack.definition.getId()].quality_definition
|
return ContainerTree.getInstance().machines[global_stack.definition.getId()].quality_definition
|
||||||
|
@ -1118,7 +1119,7 @@ class MachineManager(QObject):
|
||||||
if quality_group is None:
|
if quality_group is None:
|
||||||
self._fixQualityChangesGroupToNotSupported(quality_changes_group)
|
self._fixQualityChangesGroupToNotSupported(quality_changes_group)
|
||||||
|
|
||||||
container_registry = cura.CuraApplication.CuraApplication.getInstance().getContainerRegistry()
|
container_registry = self._application.getContainerRegistry()
|
||||||
quality_changes_container = empty_quality_changes_container
|
quality_changes_container = empty_quality_changes_container
|
||||||
quality_container = empty_quality_container # type: InstanceContainer
|
quality_container = empty_quality_container # type: InstanceContainer
|
||||||
if quality_changes_group.metadata_for_global:
|
if quality_changes_group.metadata_for_global:
|
||||||
|
@ -1200,7 +1201,7 @@ class MachineManager(QObject):
|
||||||
def _updateQualityWithMaterial(self, *args: Any) -> None:
|
def _updateQualityWithMaterial(self, *args: Any) -> None:
|
||||||
"""Update current quality type and machine after setting material"""
|
"""Update current quality type and machine after setting material"""
|
||||||
|
|
||||||
global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
global_stack = self._application.getGlobalContainerStack()
|
||||||
if global_stack is None:
|
if global_stack is None:
|
||||||
return
|
return
|
||||||
Logger.log("d", "Updating quality/quality_changes due to material change")
|
Logger.log("d", "Updating quality/quality_changes due to material change")
|
||||||
|
@ -1242,7 +1243,7 @@ class MachineManager(QObject):
|
||||||
def _updateIntentWithQuality(self):
|
def _updateIntentWithQuality(self):
|
||||||
"""Update the current intent after the quality changed"""
|
"""Update the current intent after the quality changed"""
|
||||||
|
|
||||||
global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
global_stack = self._application.getGlobalContainerStack()
|
||||||
if global_stack is None:
|
if global_stack is None:
|
||||||
return
|
return
|
||||||
Logger.log("d", "Updating intent due to quality change")
|
Logger.log("d", "Updating intent due to quality change")
|
||||||
|
@ -1555,7 +1556,7 @@ class MachineManager(QObject):
|
||||||
# - "my_profile - Engineering - Fine" (based on an intent)
|
# - "my_profile - Engineering - Fine" (based on an intent)
|
||||||
@pyqtProperty("QVariantMap", notify = activeQualityDisplayNameChanged)
|
@pyqtProperty("QVariantMap", notify = activeQualityDisplayNameChanged)
|
||||||
def activeQualityDisplayNameMap(self) -> Dict[str, str]:
|
def activeQualityDisplayNameMap(self) -> Dict[str, str]:
|
||||||
global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
global_stack = self._application.getGlobalContainerStack()
|
||||||
if global_stack is None:
|
if global_stack is None:
|
||||||
return {"main": "",
|
return {"main": "",
|
||||||
"suffix": ""}
|
"suffix": ""}
|
||||||
|
@ -1592,7 +1593,7 @@ class MachineManager(QObject):
|
||||||
:param intent_category: The intent category to change to.
|
:param intent_category: The intent category to change to.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
global_stack = self._application.getGlobalContainerStack()
|
||||||
if global_stack is None:
|
if global_stack is None:
|
||||||
return
|
return
|
||||||
container_tree = ContainerTree.getInstance()
|
container_tree = ContainerTree.getInstance()
|
||||||
|
@ -1631,7 +1632,7 @@ class MachineManager(QObject):
|
||||||
:return: The currently active quality group.
|
:return: The currently active quality group.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
global_stack = self._application.getGlobalContainerStack()
|
||||||
if not global_stack or global_stack.quality == empty_quality_container:
|
if not global_stack or global_stack.quality == empty_quality_container:
|
||||||
return None
|
return None
|
||||||
return ContainerTree.getInstance().getCurrentQualityGroups().get(self.activeQualityType)
|
return ContainerTree.getInstance().getCurrentQualityGroups().get(self.activeQualityType)
|
||||||
|
@ -1668,7 +1669,7 @@ class MachineManager(QObject):
|
||||||
|
|
||||||
@pyqtProperty(QObject, fset = setQualityChangesGroup, notify = activeQualityChangesGroupChanged)
|
@pyqtProperty(QObject, fset = setQualityChangesGroup, notify = activeQualityChangesGroupChanged)
|
||||||
def activeQualityChangesGroup(self) -> Optional["QualityChangesGroup"]:
|
def activeQualityChangesGroup(self) -> Optional["QualityChangesGroup"]:
|
||||||
global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
global_stack = self._application.getGlobalContainerStack()
|
||||||
if global_stack is None or global_stack.qualityChanges == empty_quality_changes_container:
|
if global_stack is None or global_stack.qualityChanges == empty_quality_changes_container:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -1683,12 +1684,12 @@ class MachineManager(QObject):
|
||||||
|
|
||||||
@pyqtProperty(bool, notify = activeQualityChangesGroupChanged)
|
@pyqtProperty(bool, notify = activeQualityChangesGroupChanged)
|
||||||
def hasCustomQuality(self) -> bool:
|
def hasCustomQuality(self) -> bool:
|
||||||
global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
global_stack = self._application.getGlobalContainerStack()
|
||||||
return global_stack is None or global_stack.qualityChanges != empty_quality_changes_container
|
return global_stack is None or global_stack.qualityChanges != empty_quality_changes_container
|
||||||
|
|
||||||
@pyqtProperty(str, notify = activeQualityGroupChanged)
|
@pyqtProperty(str, notify = activeQualityGroupChanged)
|
||||||
def activeQualityOrQualityChangesName(self) -> str:
|
def activeQualityOrQualityChangesName(self) -> str:
|
||||||
global_container_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
global_container_stack = self._application.getGlobalContainerStack()
|
||||||
if not global_container_stack:
|
if not global_container_stack:
|
||||||
return empty_quality_container.getName()
|
return empty_quality_container.getName()
|
||||||
if global_container_stack.qualityChanges != empty_quality_changes_container:
|
if global_container_stack.qualityChanges != empty_quality_changes_container:
|
||||||
|
@ -1697,12 +1698,12 @@ class MachineManager(QObject):
|
||||||
|
|
||||||
@pyqtProperty(bool, notify = activeQualityGroupChanged)
|
@pyqtProperty(bool, notify = activeQualityGroupChanged)
|
||||||
def hasNotSupportedQuality(self) -> bool:
|
def hasNotSupportedQuality(self) -> bool:
|
||||||
global_container_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
global_container_stack = self._application.getGlobalContainerStack()
|
||||||
return (not global_container_stack is None) and global_container_stack.quality == empty_quality_container and global_container_stack.qualityChanges == empty_quality_changes_container
|
return (not global_container_stack is None) and global_container_stack.quality == empty_quality_container and global_container_stack.qualityChanges == empty_quality_changes_container
|
||||||
|
|
||||||
@pyqtProperty(bool, notify = activeQualityGroupChanged)
|
@pyqtProperty(bool, notify = activeQualityGroupChanged)
|
||||||
def isActiveQualityCustom(self) -> bool:
|
def isActiveQualityCustom(self) -> bool:
|
||||||
global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
global_stack = self._application.getGlobalContainerStack()
|
||||||
if global_stack is None:
|
if global_stack is None:
|
||||||
return False
|
return False
|
||||||
return global_stack.qualityChanges != empty_quality_changes_container
|
return global_stack.qualityChanges != empty_quality_changes_container
|
||||||
|
|
|
@ -192,6 +192,7 @@ def test_setInvalidActiveMachine(machine_manager):
|
||||||
# Notification stuff should happen now!
|
# Notification stuff should happen now!
|
||||||
configuration_error_message.addFaultyContainers.assert_called_once_with("InvalidMachine")
|
configuration_error_message.addFaultyContainers.assert_called_once_with("InvalidMachine")
|
||||||
|
|
||||||
|
|
||||||
def test_clearUserSettingsAllCurrentStacks(machine_manager, application):
|
def test_clearUserSettingsAllCurrentStacks(machine_manager, application):
|
||||||
global_stack = application.getGlobalContainerStack()
|
global_stack = application.getGlobalContainerStack()
|
||||||
extruder_1 = createMockedExtruder("extruder_1")
|
extruder_1 = createMockedExtruder("extruder_1")
|
||||||
|
@ -220,3 +221,36 @@ def test_clearUserSettingsAllCurrentStacksLinkedSetting(machine_manager, applica
|
||||||
instance_container.removeInstance.assert_not_called()
|
instance_container.removeInstance.assert_not_called()
|
||||||
instance_container_global.removeInstance.assert_called_once_with("some_setting", postpone_emit = True)
|
instance_container_global.removeInstance.assert_called_once_with("some_setting", postpone_emit = True)
|
||||||
|
|
||||||
|
|
||||||
|
def test_isActiveQualityExperimental(machine_manager):
|
||||||
|
quality_group = MagicMock(is_experimental = True)
|
||||||
|
machine_manager.activeQualityGroup = MagicMock(return_value = quality_group)
|
||||||
|
assert machine_manager.isActiveQualityExperimental
|
||||||
|
|
||||||
|
|
||||||
|
def test_isActiveQualityNotExperimental(machine_manager):
|
||||||
|
quality_group = MagicMock(is_experimental = False)
|
||||||
|
machine_manager.activeQualityGroup = MagicMock(return_value = quality_group)
|
||||||
|
assert not machine_manager.isActiveQualityExperimental
|
||||||
|
|
||||||
|
|
||||||
|
def test_isActiveQualityNotExperimental_noQualityGroup(machine_manager):
|
||||||
|
machine_manager.activeQualityGroup = MagicMock(return_value=None)
|
||||||
|
assert not machine_manager.isActiveQualityExperimental
|
||||||
|
|
||||||
|
|
||||||
|
def test_isActiveQualitySupported(machine_manager):
|
||||||
|
quality_group = MagicMock(is_available=True)
|
||||||
|
machine_manager.activeQualityGroup = MagicMock(return_value=quality_group)
|
||||||
|
assert machine_manager.isActiveQualitySupported
|
||||||
|
|
||||||
|
|
||||||
|
def test_isActiveQualityNotSupported(machine_manager):
|
||||||
|
quality_group = MagicMock(is_available=False)
|
||||||
|
machine_manager.activeQualityGroup = MagicMock(return_value=quality_group)
|
||||||
|
assert not machine_manager.isActiveQualitySupported
|
||||||
|
|
||||||
|
|
||||||
|
def test_isActiveQualityNotSupported_noQualityGroup(machine_manager):
|
||||||
|
machine_manager.activeQualityGroup = MagicMock(return_value=None)
|
||||||
|
assert not machine_manager.isActiveQualitySupported
|
Loading…
Add table
Add a link
Reference in a new issue