Merge branch 'transparent_limit_to_extruder' of github.com:ultimaker/Cura into transparent_limit_to_extruder

* 'transparent_limit_to_extruder' of github.com:ultimaker/Cura:
  Removed unused imports
  Fixed type hinting for Extruder stack
  Fixed two remaining failing unit tests
  Fixes unit fallthrough unit test
This commit is contained in:
Arjen Hiemstra 2017-05-16 13:41:13 +02:00
commit c4e6336828
3 changed files with 13 additions and 9 deletions

View File

@ -1,22 +1,21 @@
# Copyright (c) 2017 Ultimaker B.V. # Copyright (c) 2017 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher. # Cura is released under the terms of the AGPLv3 or higher.
from typing import Any from typing import Any, TYPE_CHECKING, Optional
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot
from UM.Decorators import override from UM.Decorators import override
from UM.MimeTypeDatabase import MimeType, MimeTypeDatabase from UM.MimeTypeDatabase import MimeType, MimeTypeDatabase
from UM.Settings.ContainerStack import ContainerStack, InvalidContainerStackError from UM.Settings.ContainerStack import ContainerStack
from UM.Settings.ContainerRegistry import ContainerRegistry from UM.Settings.ContainerRegistry import ContainerRegistry
from UM.Settings.InstanceContainer import InstanceContainer
from UM.Settings.DefinitionContainer import DefinitionContainer
from UM.Settings.Interfaces import ContainerInterface from UM.Settings.Interfaces import ContainerInterface
from . import Exceptions from . import Exceptions
from .CuraContainerStack import CuraContainerStack from .CuraContainerStack import CuraContainerStack
from .ExtruderManager import ExtruderManager from .ExtruderManager import ExtruderManager
if TYPE_CHECKING:
from cura.Settings.GlobalStack import GlobalStack
## Represents an Extruder and its related containers. ## Represents an Extruder and its related containers.
# #
# #
@ -38,6 +37,10 @@ class ExtruderStack(CuraContainerStack):
# For backward compatibility: Register the extruder with the Extruder Manager # For backward compatibility: Register the extruder with the Extruder Manager
ExtruderManager.getInstance().registerExtruder(self, stack.id) ExtruderManager.getInstance().registerExtruder(self, stack.id)
@override(ContainerStack)
def getNextStack(self) -> Optional["GlobalStack"]:
return super().getNextStack()
@classmethod @classmethod
def getLoadingPriority(cls) -> int: def getLoadingPriority(cls) -> int:
return 3 return 3

View File

@ -250,7 +250,8 @@ def test_getPropertyFallThrough(extruder_stack):
container_indices = cura.Settings.CuraContainerStack._ContainerIndexes #Cache. container_indices = cura.Settings.CuraContainerStack._ContainerIndexes #Cache.
for type_id, type_name in container_indices.IndexTypeMap.items(): for type_id, type_name in container_indices.IndexTypeMap.items():
container = unittest.mock.MagicMock() container = unittest.mock.MagicMock()
container.getProperty = lambda key, property, type_id = type_id: type_id if (key == "layer_height" and property == "value") else None #Returns the container type ID as layer height, in order to identify it. # Return type_id when asking for value and -1 when asking for limit_to_extruder
container.getProperty = lambda key, property, type_id = type_id: type_id if (key == "layer_height" and property == "value") else (None if property != "limit_to_extruder" else "-1") #Returns the container type ID as layer height, in order to identify it.
container.hasProperty = lambda key, property: key == "layer_height" container.hasProperty = lambda key, property: key == "layer_height"
container.getMetaDataEntry = unittest.mock.MagicMock(return_value = type_name) container.getMetaDataEntry = unittest.mock.MagicMock(return_value = type_name)
mock_layer_heights[type_id] = container mock_layer_heights[type_id] = container

View File

@ -350,7 +350,7 @@ def test_getPropertyResolveInInstance(global_stack):
instance_containers = {} instance_containers = {}
for container_type in container_indices.IndexTypeMap: for container_type in container_indices.IndexTypeMap:
instance_containers[container_type] = unittest.mock.MagicMock() #Sets the resolve and value for bed temperature. instance_containers[container_type] = unittest.mock.MagicMock() #Sets the resolve and value for bed temperature.
instance_containers[container_type].getProperty = lambda key, property: (7.5 if property == "resolve" else (InstanceState.User if property == "state" else 5)) if (key == "material_bed_temperature") else None #7.5 resolve, 5 value. instance_containers[container_type].getProperty = lambda key, property: (7.5 if property == "resolve" else (InstanceState.User if property == "state" else (5 if property != "limit_to_extruder" else "-1"))) if (key == "material_bed_temperature") else None #7.5 resolve, 5 value.
instance_containers[container_type].getMetaDataEntry = unittest.mock.MagicMock(return_value = container_indices.IndexTypeMap[container_type]) #Make queries for the type return the desired type. instance_containers[container_type].getMetaDataEntry = unittest.mock.MagicMock(return_value = container_indices.IndexTypeMap[container_type]) #Make queries for the type return the desired type.
instance_containers[container_indices.Definition].getProperty = lambda key, property: 10 if (key == "material_bed_temperature" and property == "value") else None #Definition only has value. instance_containers[container_indices.Definition].getProperty = lambda key, property: 10 if (key == "material_bed_temperature" and property == "value") else None #Definition only has value.
with unittest.mock.patch("cura.Settings.CuraContainerStack.DefinitionContainer", unittest.mock.MagicMock): #To guard against the type checking. with unittest.mock.patch("cura.Settings.CuraContainerStack.DefinitionContainer", unittest.mock.MagicMock): #To guard against the type checking.
@ -374,7 +374,7 @@ def test_getPropertyResolveInInstance(global_stack):
# definitions. # definitions.
def test_getPropertyInstancesBeforeResolve(global_stack): def test_getPropertyInstancesBeforeResolve(global_stack):
value = unittest.mock.MagicMock() #Sets just the value. value = unittest.mock.MagicMock() #Sets just the value.
value.getProperty = lambda key, property: (10 if property == "value" else InstanceState.User) if key == "material_bed_temperature" else None value.getProperty = lambda key, property: (10 if property == "value" else (InstanceState.User if property != "limit_to_extruder" else "-1")) if key == "material_bed_temperature" else None
value.getMetaDataEntry = unittest.mock.MagicMock(return_value = "quality") value.getMetaDataEntry = unittest.mock.MagicMock(return_value = "quality")
resolve = unittest.mock.MagicMock() #Sets just the resolve. resolve = unittest.mock.MagicMock() #Sets just the resolve.
resolve.getProperty = lambda key, property: 7.5 if (key == "material_bed_temperature" and property == "resolve") else None resolve.getProperty = lambda key, property: 7.5 if (key == "material_bed_temperature" and property == "resolve") else None