Add container types to fallthrough tests

This checks exactly the same code as the global stack.

Contributes to issue CURA-3497.
This commit is contained in:
Ghostkeeper 2017-04-11 13:34:26 +02:00
parent b97ef58436
commit 8dc073f5c8
No known key found for this signature in database
GPG key ID: C5F96EE2BC0F7E75

View file

@ -257,34 +257,41 @@ def test_deserializeMoveDefinitionContainer(extruder_stack):
# containers. # containers.
def test_getPropertyFallThrough(extruder_stack): def test_getPropertyFallThrough(extruder_stack):
#A few instance container mocks to put in the stack. #A few instance container mocks to put in the stack.
layer_height_5 = unittest.mock.MagicMock() #Sets layer height to 5. mock_layer_heights = {} #For each container type, a mock container that defines layer height to something unique.
layer_height_5.getProperty = lambda key, property: 5 if (key == "layer_height" and property == "value") else None mock_no_settings = {} #For each container type, a mock container that has no settings at all.
layer_height_5.hasProperty = lambda key: key == "layer_height" container_indices = cura.Settings.CuraContainerStack._ContainerIndexes #Cache.
layer_height_10 = unittest.mock.MagicMock() #Sets layer height to 10. for type_id, type_name in container_indices.IndexTypeMap.items():
layer_height_10.getProperty = lambda key, property: 10 if (key == "layer_height" and property == "value") else None container = unittest.mock.MagicMock()
layer_height_10.hasProperty = lambda key: key == "layer_height" 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.
no_layer_height = unittest.mock.MagicMock() #No settings at all. container.hasProperty = lambda key, property: key == "layer_height"
no_layer_height.getProperty = lambda key, property: None container.getMetaDataEntry = unittest.mock.MagicMock(return_value = type_name)
no_layer_height.hasProperty = lambda key: False mock_layer_heights[type_id] = container
extruder_stack.userChanges = no_layer_height container = unittest.mock.MagicMock()
extruder_stack.qualityChanges = no_layer_height container.getProperty = unittest.mock.MagicMock(return_value = None) #Has no settings at all.
extruder_stack.quality = no_layer_height container.hasProperty = unittest.mock.MagicMock(return_value = False)
extruder_stack.material = no_layer_height container.getMetaDataEntry = unittest.mock.MagicMock(return_value = type_name)
extruder_stack.variant = no_layer_height mock_no_settings[type_id] = container
extruder_stack.definition = layer_height_5 #Here it is!
assert extruder_stack.getProperty("layer_height", "value") == 5 extruder_stack.userChanges = mock_no_settings[container_indices.UserChanges]
extruder_stack.variant = layer_height_10 extruder_stack.qualityChanges = mock_no_settings[container_indices.QualityChanges]
assert extruder_stack.getProperty("layer_height", "value") == 10 extruder_stack.quality = mock_no_settings[container_indices.Quality]
extruder_stack.material = layer_height_5 extruder_stack.material = mock_no_settings[container_indices.Material]
assert extruder_stack.getProperty("layer_height", "value") == 5 extruder_stack.variant = mock_no_settings[container_indices.Variant]
extruder_stack.quality = layer_height_10 with unittest.mock.patch("cura.Settings.CuraContainerStack.DefinitionContainer", unittest.mock.MagicMock): #To guard against the type checking.
assert extruder_stack.getProperty("layer_height", "value") == 10 extruder_stack.definition = mock_layer_heights[container_indices.Definition] #There's a layer height in here!
extruder_stack.qualityChanges = layer_height_5
assert extruder_stack.getProperty("layer_height", "value") == 5 assert extruder_stack.getProperty("layer_height", "value") == container_indices.Definition
extruder_stack.userChanges = layer_height_10 extruder_stack.variant = mock_layer_heights[container_indices.Variant]
assert extruder_stack.getProperty("layer_height", "value") == 10 assert extruder_stack.getProperty("layer_height", "value") == container_indices.Variant
extruder_stack.material = mock_layer_heights[container_indices.Material]
assert extruder_stack.getProperty("layer_height", "value") == container_indices.Material
extruder_stack.quality = mock_layer_heights[container_indices.Quality]
assert extruder_stack.getProperty("layer_height", "value") == container_indices.Quality
extruder_stack.qualityChanges = mock_layer_heights[container_indices.QualityChanges]
assert extruder_stack.getProperty("layer_height", "value") == container_indices.QualityChanges
extruder_stack.userChanges = mock_layer_heights[container_indices.UserChanges]
assert extruder_stack.getProperty("layer_height", "value") == container_indices.UserChanges
## Tests whether inserting a container is properly forbidden. ## Tests whether inserting a container is properly forbidden.
def test_insertContainer(extruder_stack): def test_insertContainer(extruder_stack):