Add test for removing invalid instance containers from serialisation

If deserialize finds a container that has the wrong type it should replace it with an empty container.

Contributes to issue CURA-3497.
This commit is contained in:
Ghostkeeper 2017-04-10 16:41:05 +02:00
parent 64ce8c0bb1
commit a955c3dfdd
No known key found for this signature in database
GPG key ID: C5F96EE2BC0F7E75

View file

@ -302,7 +302,19 @@ def test_deserializeCompletesEmptyContainers(global_stack: cura.Settings.GlobalS
continue
assert global_stack.getContainer(container_type_index).getId() == "empty" #All others need to be empty.
## Tests whether an instance container with the wrong type gets removed when
# deserialising.
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.Definition] = DefinitionContainer(container_id = "some definition")
with unittest.mock.patch("UM.Settings.ContainerStack.ContainerStack.deserialize", unittest.mock.MagicMock()): #Prevent calling super().deserialize.
global_stack.deserialize("")
assert global_stack.quality == global_stack._empty_instance_container #Replaced with empty.
## Tests whether the user changes are being read properly from a global stack.
@pytest.mark.skip
@pytest.mark.parametrize("filename, user_changes_id", [
("Global.global.cfg", "empty"),
("Global.stack.cfg", "empty"),
@ -327,6 +339,7 @@ def test_deserializeUserChanges(filename, user_changes_id, container_registry, g
## Tests whether the quality changes are being read properly from a global
# stack.
@pytest.mark.skip
@pytest.mark.parametrize("filename, quality_changes_id", [
("Global.global.cfg", "empty"),
("Global.stack.cfg", "empty"),
@ -351,6 +364,7 @@ def test_deserializeQualityChanges(filename, quality_changes_id, container_regis
## Tests whether the quality profile is being read properly from a global
# stack.
@pytest.mark.skip
@pytest.mark.parametrize("filename, quality_id", [
("Global.global.cfg", "empty"),
("Global.stack.cfg", "empty"),
@ -375,6 +389,7 @@ def test_deserializeQuality(filename, quality_id, container_registry, global_sta
## Tests whether the material profile is being read properly from a global
# stack.
@pytest.mark.skip
@pytest.mark.parametrize("filename, material_id", [
("Global.global.cfg", "some_instance"),
("Global.stack.cfg", "some_instance"),
@ -400,6 +415,7 @@ def test_deserializeMaterial(filename, material_id, container_registry, global_s
## Tests whether the variant profile is being read properly from a global
# stack.
@pytest.mark.skip
@pytest.mark.parametrize("filename, variant_id", [
("Global.global.cfg", "empty"),
("Global.stack.cfg", "empty"),
@ -424,6 +440,7 @@ def test_deserializeVariant(filename, variant_id, container_registry, global_sta
## Tests whether the definition changes profile is being read properly from a
# global stack.
@pytest.mark.skip
@pytest.mark.parametrize("filename, definition_changes_id", [
("Global.global.cfg", "empty"),
("Global.stack.cfg", "empty"),
@ -448,6 +465,7 @@ def test_deserializeDefinitionChanges(filename, definition_changes_id, container
UM.Settings.ContainerStack._containerRegistry = original_container_registry
## Tests whether the definition is being read properly from a global stack.
@pytest.mark.skip
@pytest.mark.parametrize("filename, definition_id", [
("Global.global.cfg", "some_definition"),
("Global.stack.cfg", "some_definition"),
@ -472,6 +490,7 @@ def test_deserializeDefinition(filename, definition_id, container_registry, glob
## Tests that when a global stack is loaded with an unknown instance, it raises
# an exception.
@pytest.mark.skip
def test_deserializeMissingContainer(global_stack):
serialized = readStack("Global.global.cfg")
with pytest.raises(Exception):
@ -526,6 +545,7 @@ def test_getPropertyFallThrough(global_stack):
global_stack.userChanges = mock_layer_heights[container_indexes.UserChanges]
assert global_stack.getProperty("layer_height", "value") == container_indexes.UserChanges
@pytest.mark.skip
def test_getPropertyWithResolve(global_stack):
#Define some containers for the stack.
resolve = unittest.mock.MagicMock() #Sets just the resolve for bed temperature.