Fix spacing

This commit is contained in:
Jaime van Kessel 2018-09-27 17:31:45 +02:00
parent 7310a677ce
commit f585afe77b
2 changed files with 42 additions and 2 deletions

View file

@ -23,6 +23,7 @@ from .CuraContainerStack import CuraContainerStack
if TYPE_CHECKING: if TYPE_CHECKING:
from cura.Settings.ExtruderStack import ExtruderStack from cura.Settings.ExtruderStack import ExtruderStack
## Represents the Global or Machine stack and its related containers. ## Represents the Global or Machine stack and its related containers.
# #
class GlobalStack(CuraContainerStack): class GlobalStack(CuraContainerStack):

View file

@ -15,6 +15,7 @@ import UM.Settings.SettingDefinition #To add settings to the definition.
from cura.Settings.cura_empty_instance_containers import empty_container from cura.Settings.cura_empty_instance_containers import empty_container
## Gets an instance container with a specified container type. ## Gets an instance container with a specified container type.
# #
# \param container_type The type metadata for the instance container. # \param container_type The type metadata for the instance container.
@ -24,22 +25,27 @@ def getInstanceContainer(container_type) -> InstanceContainer:
container.setMetaDataEntry("type", container_type) container.setMetaDataEntry("type", container_type)
return container return container
class DefinitionContainerSubClass(DefinitionContainer): class DefinitionContainerSubClass(DefinitionContainer):
def __init__(self): def __init__(self):
super().__init__(container_id = "SubDefinitionContainer") super().__init__(container_id = "SubDefinitionContainer")
class InstanceContainerSubClass(InstanceContainer): class InstanceContainerSubClass(InstanceContainer):
def __init__(self, container_type): def __init__(self, container_type):
super().__init__(container_id = "SubInstanceContainer") super().__init__(container_id = "SubInstanceContainer")
self.setMetaDataEntry("type", container_type) self.setMetaDataEntry("type", container_type)
#############################START OF TEST CASES################################ #############################START OF TEST CASES################################
## Tests whether adding a container is properly forbidden. ## Tests whether adding a container is properly forbidden.
def test_addContainer(global_stack): def test_addContainer(global_stack):
with pytest.raises(InvalidOperationError): with pytest.raises(InvalidOperationError):
global_stack.addContainer(unittest.mock.MagicMock()) global_stack.addContainer(unittest.mock.MagicMock())
## Tests adding extruders to the global stack. ## Tests adding extruders to the global stack.
def test_addExtruder(global_stack): def test_addExtruder(global_stack):
mock_definition = unittest.mock.MagicMock() mock_definition = unittest.mock.MagicMock()
@ -67,6 +73,7 @@ def test_addExtruder(global_stack):
# global_stack.addExtruder(unittest.mock.MagicMock()) # global_stack.addExtruder(unittest.mock.MagicMock())
assert len(global_stack.extruders) == 2 #Didn't add the faulty extruder. assert len(global_stack.extruders) == 2 #Didn't add the faulty extruder.
#Tests setting user changes profiles to invalid containers. #Tests setting user changes profiles to invalid containers.
@pytest.mark.parametrize("container", [ @pytest.mark.parametrize("container", [
getInstanceContainer(container_type = "wrong container type"), getInstanceContainer(container_type = "wrong container type"),
@ -77,6 +84,7 @@ def test_constrainUserChangesInvalid(container, global_stack):
with pytest.raises(InvalidContainerError): #Invalid container, should raise an error. with pytest.raises(InvalidContainerError): #Invalid container, should raise an error.
global_stack.userChanges = container global_stack.userChanges = container
#Tests setting user changes profiles. #Tests setting user changes profiles.
@pytest.mark.parametrize("container", [ @pytest.mark.parametrize("container", [
getInstanceContainer(container_type = "user"), getInstanceContainer(container_type = "user"),
@ -85,6 +93,7 @@ def test_constrainUserChangesInvalid(container, global_stack):
def test_constrainUserChangesValid(container, global_stack): def test_constrainUserChangesValid(container, global_stack):
global_stack.userChanges = container #Should not give an error. global_stack.userChanges = container #Should not give an error.
#Tests setting quality changes profiles to invalid containers. #Tests setting quality changes profiles to invalid containers.
@pytest.mark.parametrize("container", [ @pytest.mark.parametrize("container", [
getInstanceContainer(container_type = "wrong container type"), getInstanceContainer(container_type = "wrong container type"),
@ -95,6 +104,7 @@ def test_constrainQualityChangesInvalid(container, global_stack):
with pytest.raises(InvalidContainerError): #Invalid container, should raise an error. with pytest.raises(InvalidContainerError): #Invalid container, should raise an error.
global_stack.qualityChanges = container global_stack.qualityChanges = container
#Test setting quality changes profiles. #Test setting quality changes profiles.
@pytest.mark.parametrize("container", [ @pytest.mark.parametrize("container", [
getInstanceContainer(container_type = "quality_changes"), getInstanceContainer(container_type = "quality_changes"),
@ -103,6 +113,7 @@ def test_constrainQualityChangesInvalid(container, global_stack):
def test_constrainQualityChangesValid(container, global_stack): def test_constrainQualityChangesValid(container, global_stack):
global_stack.qualityChanges = container #Should not give an error. global_stack.qualityChanges = container #Should not give an error.
#Tests setting quality profiles to invalid containers. #Tests setting quality profiles to invalid containers.
@pytest.mark.parametrize("container", [ @pytest.mark.parametrize("container", [
getInstanceContainer(container_type = "wrong container type"), getInstanceContainer(container_type = "wrong container type"),
@ -113,6 +124,7 @@ def test_constrainQualityInvalid(container, global_stack):
with pytest.raises(InvalidContainerError): #Invalid container, should raise an error. with pytest.raises(InvalidContainerError): #Invalid container, should raise an error.
global_stack.quality = container global_stack.quality = container
#Test setting quality profiles. #Test setting quality profiles.
@pytest.mark.parametrize("container", [ @pytest.mark.parametrize("container", [
getInstanceContainer(container_type = "quality"), getInstanceContainer(container_type = "quality"),
@ -121,6 +133,7 @@ def test_constrainQualityInvalid(container, global_stack):
def test_constrainQualityValid(container, global_stack): def test_constrainQualityValid(container, global_stack):
global_stack.quality = container #Should not give an error. global_stack.quality = container #Should not give an error.
#Tests setting materials to invalid containers. #Tests setting materials to invalid containers.
@pytest.mark.parametrize("container", [ @pytest.mark.parametrize("container", [
getInstanceContainer(container_type = "wrong container type"), getInstanceContainer(container_type = "wrong container type"),
@ -131,6 +144,7 @@ def test_constrainMaterialInvalid(container, global_stack):
with pytest.raises(InvalidContainerError): #Invalid container, should raise an error. with pytest.raises(InvalidContainerError): #Invalid container, should raise an error.
global_stack.material = container global_stack.material = container
#Test setting materials. #Test setting materials.
@pytest.mark.parametrize("container", [ @pytest.mark.parametrize("container", [
getInstanceContainer(container_type = "material"), getInstanceContainer(container_type = "material"),
@ -139,6 +153,7 @@ def test_constrainMaterialInvalid(container, global_stack):
def test_constrainMaterialValid(container, global_stack): def test_constrainMaterialValid(container, global_stack):
global_stack.material = container #Should not give an error. global_stack.material = container #Should not give an error.
#Tests setting variants to invalid containers. #Tests setting variants to invalid containers.
@pytest.mark.parametrize("container", [ @pytest.mark.parametrize("container", [
getInstanceContainer(container_type = "wrong container type"), getInstanceContainer(container_type = "wrong container type"),
@ -149,6 +164,7 @@ def test_constrainVariantInvalid(container, global_stack):
with pytest.raises(InvalidContainerError): #Invalid container, should raise an error. with pytest.raises(InvalidContainerError): #Invalid container, should raise an error.
global_stack.variant = container global_stack.variant = container
#Test setting variants. #Test setting variants.
@pytest.mark.parametrize("container", [ @pytest.mark.parametrize("container", [
getInstanceContainer(container_type = "variant"), getInstanceContainer(container_type = "variant"),
@ -157,6 +173,7 @@ def test_constrainVariantInvalid(container, global_stack):
def test_constrainVariantValid(container, global_stack): def test_constrainVariantValid(container, global_stack):
global_stack.variant = container #Should not give an error. global_stack.variant = container #Should not give an error.
#Tests setting definition changes profiles to invalid containers. #Tests setting definition changes profiles to invalid containers.
@pytest.mark.parametrize("container", [ @pytest.mark.parametrize("container", [
getInstanceContainer(container_type = "wrong container type"), getInstanceContainer(container_type = "wrong container type"),
@ -167,6 +184,7 @@ def test_constrainDefinitionChangesInvalid(container, global_stack):
with pytest.raises(InvalidContainerError): #Invalid container, should raise an error. with pytest.raises(InvalidContainerError): #Invalid container, should raise an error.
global_stack.definitionChanges = container global_stack.definitionChanges = container
#Test setting definition changes profiles. #Test setting definition changes profiles.
@pytest.mark.parametrize("container", [ @pytest.mark.parametrize("container", [
getInstanceContainer(container_type = "definition_changes"), getInstanceContainer(container_type = "definition_changes"),
@ -175,6 +193,7 @@ def test_constrainDefinitionChangesInvalid(container, global_stack):
def test_constrainDefinitionChangesValid(container, global_stack): def test_constrainDefinitionChangesValid(container, global_stack):
global_stack.definitionChanges = container #Should not give an error. global_stack.definitionChanges = container #Should not give an error.
#Tests setting definitions to invalid containers. #Tests setting definitions to invalid containers.
@pytest.mark.parametrize("container", [ @pytest.mark.parametrize("container", [
getInstanceContainer(container_type = "wrong class"), getInstanceContainer(container_type = "wrong class"),
@ -184,6 +203,7 @@ def test_constrainDefinitionInvalid(container, global_stack):
with pytest.raises(InvalidContainerError): #Invalid container, should raise an error. with pytest.raises(InvalidContainerError): #Invalid container, should raise an error.
global_stack.definition = container global_stack.definition = container
#Test setting definitions. #Test setting definitions.
@pytest.mark.parametrize("container", [ @pytest.mark.parametrize("container", [
DefinitionContainer(container_id = "DefinitionContainer"), DefinitionContainer(container_id = "DefinitionContainer"),
@ -192,6 +212,7 @@ def test_constrainDefinitionInvalid(container, global_stack):
def test_constrainDefinitionValid(container, global_stack): def test_constrainDefinitionValid(container, global_stack):
global_stack.definition = container #Should not give an error. global_stack.definition = container #Should not give an error.
## Tests whether deserialising completes the missing containers with empty ones. The initial containers are just the ## Tests whether deserialising completes the missing containers with empty ones. The initial containers are just the
# definition and the definition_changes (that cannot be empty after CURA-5281) # definition and the definition_changes (that cannot be empty after CURA-5281)
def test_deserializeCompletesEmptyContainers(global_stack): def test_deserializeCompletesEmptyContainers(global_stack):
@ -207,6 +228,7 @@ def test_deserializeCompletesEmptyContainers(global_stack):
continue continue
assert global_stack.getContainer(container_type_index) == empty_container #All others need to be empty. assert global_stack.getContainer(container_type_index) == empty_container #All others need to be empty.
## Tests whether an instance container with the wrong type gets removed when deserialising. ## Tests whether an instance container with the wrong type gets removed when deserialising.
def test_deserializeRemovesWrongInstanceContainer(global_stack): def test_deserializeRemovesWrongInstanceContainer(global_stack):
global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Quality] = getInstanceContainer(container_type = "wrong type") global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Quality] = getInstanceContainer(container_type = "wrong type")
@ -217,6 +239,7 @@ def test_deserializeRemovesWrongInstanceContainer(global_stack):
assert global_stack.quality == global_stack._empty_instance_container #Replaced with empty. assert global_stack.quality == global_stack._empty_instance_container #Replaced with empty.
## Tests whether a container with the wrong class gets removed when deserialising. ## Tests whether a container with the wrong class gets removed when deserialising.
def test_deserializeRemovesWrongContainerClass(global_stack): def test_deserializeRemovesWrongContainerClass(global_stack):
global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Quality] = DefinitionContainer(container_id = "wrong class") global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Quality] = DefinitionContainer(container_id = "wrong class")
@ -227,6 +250,7 @@ def test_deserializeRemovesWrongContainerClass(global_stack):
assert global_stack.quality == global_stack._empty_instance_container #Replaced with empty. assert global_stack.quality == global_stack._empty_instance_container #Replaced with empty.
## Tests whether an instance container in the definition spot results in an error. ## Tests whether an instance container in the definition spot results in an error.
def test_deserializeWrongDefinitionClass(global_stack): def test_deserializeWrongDefinitionClass(global_stack):
global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Definition] = getInstanceContainer(container_type = "definition") #Correct type but wrong class. global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Definition] = getInstanceContainer(container_type = "definition") #Correct type but wrong class.
@ -235,6 +259,7 @@ def test_deserializeWrongDefinitionClass(global_stack):
with pytest.raises(UM.Settings.ContainerStack.InvalidContainerStackError): #Must raise an error that there is no definition container. with pytest.raises(UM.Settings.ContainerStack.InvalidContainerStackError): #Must raise an error that there is no definition container.
global_stack.deserialize("") global_stack.deserialize("")
## Tests whether an instance container with the wrong type is moved into the correct slot by deserialising. ## Tests whether an instance container with the wrong type is moved into the correct slot by deserialising.
def test_deserializeMoveInstanceContainer(global_stack): def test_deserializeMoveInstanceContainer(global_stack):
global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Quality] = getInstanceContainer(container_type = "material") #Not in the correct spot. global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Quality] = getInstanceContainer(container_type = "material") #Not in the correct spot.
@ -246,6 +271,7 @@ def test_deserializeMoveInstanceContainer(global_stack):
assert global_stack.quality == empty_container assert global_stack.quality == empty_container
assert global_stack.material != empty_container assert global_stack.material != empty_container
## Tests whether a definition container in the wrong spot is moved into the correct spot by deserialising. ## Tests whether a definition container in the wrong spot is moved into the correct spot by deserialising.
def test_deserializeMoveDefinitionContainer(global_stack): def test_deserializeMoveDefinitionContainer(global_stack):
global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Material] = DefinitionContainer(container_id = "some definition") #Not in the correct spot. global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Material] = DefinitionContainer(container_id = "some definition") #Not in the correct spot.
@ -256,6 +282,7 @@ def test_deserializeMoveDefinitionContainer(global_stack):
assert global_stack.material == empty_container assert global_stack.material == empty_container
assert global_stack.definition != empty_container assert global_stack.definition != empty_container
## Tests whether getProperty properly applies the stack-like behaviour on its containers. ## Tests whether getProperty properly applies the stack-like behaviour on its containers.
def test_getPropertyFallThrough(global_stack): def test_getPropertyFallThrough(global_stack):
#A few instance container mocks to put in the stack. #A few instance container mocks to put in the stack.
@ -298,6 +325,7 @@ def test_getPropertyFallThrough(global_stack):
global_stack.userChanges = mock_layer_heights[container_indexes.UserChanges] global_stack.userChanges = mock_layer_heights[container_indexes.UserChanges]
assert global_stack.getProperty("layer_height", "value") == container_indexes.UserChanges assert global_stack.getProperty("layer_height", "value") == container_indexes.UserChanges
## In definitions, test whether having no resolve allows us to find the value. ## In definitions, test whether having no resolve allows us to find the value.
def test_getPropertyNoResolveInDefinition(global_stack): def test_getPropertyNoResolveInDefinition(global_stack):
value = unittest.mock.MagicMock() #Just sets the value for bed temperature. value = unittest.mock.MagicMock() #Just sets the value for bed temperature.
@ -307,6 +335,7 @@ def test_getPropertyNoResolveInDefinition(global_stack):
global_stack.definition = value global_stack.definition = value
assert global_stack.getProperty("material_bed_temperature", "value") == 10 #No resolve, so fall through to value. assert global_stack.getProperty("material_bed_temperature", "value") == 10 #No resolve, so fall through to value.
## In definitions, when the value is asked and there is a resolve function, it must get the resolve first. ## In definitions, when the value is asked and there is a resolve function, it must get the resolve first.
def test_getPropertyResolveInDefinition(global_stack): def test_getPropertyResolveInDefinition(global_stack):
resolve_and_value = unittest.mock.MagicMock() #Sets the resolve and value for bed temperature. resolve_and_value = unittest.mock.MagicMock() #Sets the resolve and value for bed temperature.
@ -316,6 +345,7 @@ def test_getPropertyResolveInDefinition(global_stack):
global_stack.definition = resolve_and_value global_stack.definition = resolve_and_value
assert global_stack.getProperty("material_bed_temperature", "value") == 7.5 #Resolve wins in the definition. assert global_stack.getProperty("material_bed_temperature", "value") == 7.5 #Resolve wins in the definition.
## In instance containers, when the value is asked and there is a resolve function, it must get the value first. ## In instance containers, when the value is asked and there is a resolve function, it must get the value first.
def test_getPropertyResolveInInstance(global_stack): def test_getPropertyResolveInInstance(global_stack):
container_indices = cura.Settings.CuraContainerStack._ContainerIndexes container_indices = cura.Settings.CuraContainerStack._ContainerIndexes
@ -342,6 +372,7 @@ def test_getPropertyResolveInInstance(global_stack):
global_stack.userChanges = instance_containers[container_indices.UserChanges] global_stack.userChanges = instance_containers[container_indices.UserChanges]
assert global_stack.getProperty("material_bed_temperature", "value") == 5 assert global_stack.getProperty("material_bed_temperature", "value") == 5
## Tests whether the value in instances gets evaluated before the resolve in definitions. ## Tests whether the value in instances gets evaluated before the resolve in 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.
@ -356,6 +387,7 @@ def test_getPropertyInstancesBeforeResolve(global_stack):
assert global_stack.getProperty("material_bed_temperature", "value") == 10 assert global_stack.getProperty("material_bed_temperature", "value") == 10
## Tests whether the hasUserValue returns true for settings that are changed in the user-changes container. ## Tests whether the hasUserValue returns true for settings that are changed in the user-changes container.
def test_hasUserValueUserChanges(global_stack): def test_hasUserValueUserChanges(global_stack):
container = unittest.mock.MagicMock() container = unittest.mock.MagicMock()
@ -367,6 +399,7 @@ def test_hasUserValueUserChanges(global_stack):
assert not global_stack.hasUserValue("infill_sparse_density") assert not global_stack.hasUserValue("infill_sparse_density")
assert not global_stack.hasUserValue("") assert not global_stack.hasUserValue("")
## Tests whether the hasUserValue returns true for settings that are changed in the quality-changes container. ## Tests whether the hasUserValue returns true for settings that are changed in the quality-changes container.
def test_hasUserValueQualityChanges(global_stack): def test_hasUserValueQualityChanges(global_stack):
container = unittest.mock.MagicMock() container = unittest.mock.MagicMock()
@ -378,6 +411,7 @@ def test_hasUserValueQualityChanges(global_stack):
assert not global_stack.hasUserValue("infill_sparse_density") assert not global_stack.hasUserValue("infill_sparse_density")
assert not global_stack.hasUserValue("") assert not global_stack.hasUserValue("")
## Tests whether a container in some other place on the stack is correctly not recognised as user value. ## Tests whether a container in some other place on the stack is correctly not recognised as user value.
def test_hasNoUserValue(global_stack): def test_hasNoUserValue(global_stack):
container = unittest.mock.MagicMock() container = unittest.mock.MagicMock()
@ -387,21 +421,25 @@ def test_hasNoUserValue(global_stack):
assert not global_stack.hasUserValue("layer_height") #However this container is quality, so it's not a user value. assert not global_stack.hasUserValue("layer_height") #However this container is quality, so it's not a user value.
## Tests whether inserting a container is properly forbidden. ## Tests whether inserting a container is properly forbidden.
def test_insertContainer(global_stack): def test_insertContainer(global_stack):
with pytest.raises(InvalidOperationError): with pytest.raises(InvalidOperationError):
global_stack.insertContainer(0, unittest.mock.MagicMock()) global_stack.insertContainer(0, unittest.mock.MagicMock())
## Tests whether removing a container is properly forbidden. ## Tests whether removing a container is properly forbidden.
def test_removeContainer(global_stack): def test_removeContainer(global_stack):
with pytest.raises(InvalidOperationError): with pytest.raises(InvalidOperationError):
global_stack.removeContainer(unittest.mock.MagicMock()) global_stack.removeContainer(unittest.mock.MagicMock())
## Tests whether changing the next stack is properly forbidden. ## Tests whether changing the next stack is properly forbidden.
def test_setNextStack(global_stack): def test_setNextStack(global_stack):
with pytest.raises(InvalidOperationError): with pytest.raises(InvalidOperationError):
global_stack.setNextStack(unittest.mock.MagicMock()) global_stack.setNextStack(unittest.mock.MagicMock())
## Tests setting properties directly on the global stack. ## Tests setting properties directly on the global stack.
@pytest.mark.parametrize("key, property, value", [ @pytest.mark.parametrize("key, property, value", [
("layer_height", "value", 0.1337), ("layer_height", "value", 0.1337),
@ -417,4 +455,5 @@ def test_setPropertyUser(key, property, value, global_stack):
global_stack.setProperty(key, property, value) # The actual test. global_stack.setProperty(key, property, value) # The actual test.
global_stack.userChanges.setProperty.assert_called_once_with(key, property, value, None, False) #Make sure that the user container gets a setProperty call. # Make sure that the user container gets a setProperty call.
global_stack.userChanges.setProperty.assert_called_once_with(key, property, value, None, False)