diff --git a/tests/Settings/TestCuraContainerRegistry.py b/tests/Settings/TestCuraContainerRegistry.py index 20a723d2aa..5c551cf5a8 100644 --- a/tests/Settings/TestCuraContainerRegistry.py +++ b/tests/Settings/TestCuraContainerRegistry.py @@ -11,6 +11,7 @@ from cura.Settings.GlobalStack import GlobalStack #Testing for returning the cor from UM.Resources import Resources #Mocking some functions of this. import UM.Settings.ContainerRegistry #Making empty container stacks. import UM.Settings.ContainerStack #Setting the container registry here properly. +from UM.Settings.DefinitionContainer import DefinitionContainer #Checking against the DefinitionContainer class. ## Gives a fresh CuraContainerRegistry instance. @pytest.fixture() @@ -30,13 +31,17 @@ def test_loadTypes(filename, output_class, container_registry): UM.Settings.ContainerStack.setContainerRegistry(container_registry) Resources.getAllResourcesOfType = unittest.mock.MagicMock(return_value = [os.path.join(os.path.dirname(os.path.abspath(__file__)), "stacks", filename)]) #Return just this tested file. def findContainers(id, container_type = 0): - if id == "empty_material": + if id == "some_material" or id == "some_definition": return [UM.Settings.ContainerRegistry._EmptyInstanceContainer(id)] else: return [] container_registry.findContainers = findContainers + mock_definition = unittest.mock.MagicMock() + def findContainer(container_id = "*", container_type = None, type = "*", category = None): + return unittest.mock.MagicMock() - container_registry.load() + with unittest.mock.patch("cura.Settings.GlobalStack.GlobalStack.findContainer", findContainer): + container_registry.load() #Check whether the resulting type was correct. stack_id = filename.split(".")[0] diff --git a/tests/Settings/TestGlobalStack.py b/tests/Settings/TestGlobalStack.py new file mode 100644 index 0000000000..d808edd6f1 --- /dev/null +++ b/tests/Settings/TestGlobalStack.py @@ -0,0 +1,33 @@ +# Copyright (c) 2017 Ultimaker B.V. +# Cura is released under the terms of the AGPLv3 or higher. + +import os.path #To find the test files. +import pytest #This module contains unit tests. +import unittest.mock #To monkeypatch some mocks in place of dependencies. + +from cura.Settings.GlobalStack import GlobalStack #The module we're testing. +from UM.Settings.DefinitionContainer import DefinitionContainer #To test against the class DefinitionContainer. +import UM.Settings.ContainerRegistry + +## Tests whether the user changes are being read properly from a global stack. +@pytest.mark.parametrize("filename, user_changes_id", [ + ("Global.global.cfg", "empty"), + ("Global.stack.cfg", "empty"), + ("MachineLegacy.stack.cfg", "empty") +]) +def test_deserializeUserChanges(filename, user_changes_id): + with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "stacks", filename)) as file_handle: + serialized = file_handle.read() + stack = GlobalStack("TestStack") + + #Mock the loading of the instances. + def findContainer(container_id = "*", container_type = None, type = None, category = "*"): + if id == "some_material": + return UM.Settings.ContainerRegistry._EmptyInstanceContainer(id) + if container_type == DefinitionContainer: + return unittest.mock.MagicMock() + stack.findContainer = findContainer + + stack.deserialize(serialized) + + assert stack.userChanges.getId() == user_changes_id \ No newline at end of file diff --git a/tests/Settings/stacks/ExtruderLegacy.stack.cfg b/tests/Settings/stacks/ExtruderLegacy.stack.cfg index 59c4defe06..91d5a79b49 100644 --- a/tests/Settings/stacks/ExtruderLegacy.stack.cfg +++ b/tests/Settings/stacks/ExtruderLegacy.stack.cfg @@ -7,4 +7,5 @@ id = ExtruderLegacy type = extruder [containers] -0 = empty_material +3 = some_material +6 = some_definition diff --git a/tests/Settings/stacks/Global.global.cfg b/tests/Settings/stacks/Global.global.cfg index ae06e1cfe3..11ad8fa656 100644 --- a/tests/Settings/stacks/Global.global.cfg +++ b/tests/Settings/stacks/Global.global.cfg @@ -4,4 +4,5 @@ name = Global id = Global [containers] -0 = empty_material +3 = some_material +6 = some_definition diff --git a/tests/Settings/stacks/Global.stack.cfg b/tests/Settings/stacks/Global.stack.cfg index ae06e1cfe3..11ad8fa656 100644 --- a/tests/Settings/stacks/Global.stack.cfg +++ b/tests/Settings/stacks/Global.stack.cfg @@ -4,4 +4,5 @@ name = Global id = Global [containers] -0 = empty_material +3 = some_material +6 = some_definition diff --git a/tests/Settings/stacks/Left.extruder.cfg b/tests/Settings/stacks/Left.extruder.cfg index fff7afd3e8..3abe869a0e 100644 --- a/tests/Settings/stacks/Left.extruder.cfg +++ b/tests/Settings/stacks/Left.extruder.cfg @@ -4,4 +4,5 @@ name = Left id = Left [containers] -0 = empty_material +3 = some_material +6 = some_definition diff --git a/tests/Settings/stacks/MachineLegacy.stack.cfg b/tests/Settings/stacks/MachineLegacy.stack.cfg index 257aa633c5..0f2e77a82e 100644 --- a/tests/Settings/stacks/MachineLegacy.stack.cfg +++ b/tests/Settings/stacks/MachineLegacy.stack.cfg @@ -7,4 +7,5 @@ id = MachineLegacy type = machine [containers] -0 = empty_material +3 = some_material +6 = some_definition \ No newline at end of file