diff --git a/tests/Settings/TestCuraContainerRegistry.py b/tests/Settings/TestCuraContainerRegistry.py index 97897fcd6d..89eba7b502 100644 --- a/tests/Settings/TestCuraContainerRegistry.py +++ b/tests/Settings/TestCuraContainerRegistry.py @@ -3,6 +3,7 @@ import os #To find the directory with test files and find the test files. import pytest #This module contains unit tests. +import shutil #To copy files to make a temporary file. import unittest.mock #To mock and monkeypatch stuff. from cura.Settings.CuraContainerRegistry import CuraContainerRegistry #The class we're testing. @@ -48,4 +49,25 @@ def test_loadTypes(filename, output_class, container_registry): assert type(container) == output_class break else: - assert False #Container stack with specified ID was not loaded. \ No newline at end of file + assert False #Container stack with specified ID was not loaded. + +## Tests whether loading a legacy file moves the upgraded file properly. +def test_loadLegacyFileRenamed(container_registry): + #Create a temporary file for the registry to load. + temp_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "stacks", "temporary.stack.cfg") + temp_file_source = os.path.join(os.path.dirname(os.path.abspath(__file__)), "stacks", "MachineLegacy.stack.cfg") + shutil.copyfile(temp_file_source, temp_file) + + #Mock some dependencies. + UM.Settings.ContainerStack.setContainerRegistry(container_registry) + Resources.getAllResourcesOfType = unittest.mock.MagicMock(return_value = [temp_file]) #Return a temporary file that we'll make for this test. + def findContainers(id, container_type = 0): + return [UM.Settings.ContainerRegistry._EmptyInstanceContainer(id)] + container_registry.findContainers = findContainers + + with unittest.mock.patch("cura.Settings.GlobalStack.GlobalStack.findContainer"): + container_registry.load() + + assert not os.path.isfile(temp_file) + new_filename = os.path.splitext(os.path.splitext(temp_file)[0])[0] + ".global.cfg" + assert os.path.isfile(new_filename) \ No newline at end of file