mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-12 04:29:00 +08:00
Fixed the upgraderFileRename test
CURA-3479
This commit is contained in:
parent
e6e442348b
commit
c815077278
@ -5,6 +5,7 @@ import os #To find the directory with test files and find the test files.
|
|||||||
import pytest #This module contains unit tests.
|
import pytest #This module contains unit tests.
|
||||||
import shutil #To copy files to make a temporary file.
|
import shutil #To copy files to make a temporary file.
|
||||||
import unittest.mock #To mock and monkeypatch stuff.
|
import unittest.mock #To mock and monkeypatch stuff.
|
||||||
|
import urllib.parse
|
||||||
|
|
||||||
from cura.Settings.CuraContainerRegistry import CuraContainerRegistry #The class we're testing.
|
from cura.Settings.CuraContainerRegistry import CuraContainerRegistry #The class we're testing.
|
||||||
from cura.Settings.ExtruderStack import ExtruderStack #Testing for returning the correct types of stacks.
|
from cura.Settings.ExtruderStack import ExtruderStack #Testing for returning the correct types of stacks.
|
||||||
@ -59,20 +60,32 @@ def test_loadTypes(filename, output_class, container_registry):
|
|||||||
## Tests whether loading a legacy file moves the upgraded file properly.
|
## Tests whether loading a legacy file moves the upgraded file properly.
|
||||||
def test_loadLegacyFileRenamed(container_registry):
|
def test_loadLegacyFileRenamed(container_registry):
|
||||||
#Create a temporary file for the registry to load.
|
#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")
|
stacks_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), "stacks")
|
||||||
temp_file_source = os.path.join(os.path.dirname(os.path.abspath(__file__)), "stacks", "MachineLegacy.stack.cfg")
|
temp_file = os.path.join(stacks_folder, "temporary.stack.cfg")
|
||||||
|
temp_file_source = os.path.join(stacks_folder, "MachineLegacy.stack.cfg")
|
||||||
shutil.copyfile(temp_file_source, temp_file)
|
shutil.copyfile(temp_file_source, temp_file)
|
||||||
|
|
||||||
#Mock some dependencies.
|
#Mock some dependencies.
|
||||||
UM.Settings.ContainerStack.setContainerRegistry(container_registry)
|
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.
|
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):
|
|
||||||
|
def findContainers(container_type = 0, id = None):
|
||||||
|
if id == "MachineLegacy":
|
||||||
|
return None
|
||||||
return [UM.Settings.ContainerRegistry._EmptyInstanceContainer(id)]
|
return [UM.Settings.ContainerRegistry._EmptyInstanceContainer(id)]
|
||||||
|
|
||||||
|
old_find_containers = container_registry.findContainers
|
||||||
container_registry.findContainers = findContainers
|
container_registry.findContainers = findContainers
|
||||||
|
|
||||||
with unittest.mock.patch("cura.Settings.GlobalStack.GlobalStack.findContainer"):
|
with unittest.mock.patch("cura.Settings.GlobalStack.GlobalStack.findContainer"):
|
||||||
container_registry.load()
|
container_registry.load()
|
||||||
|
|
||||||
|
container_registry.findContainers = old_find_containers
|
||||||
|
|
||||||
|
container_registry.saveAll()
|
||||||
|
print("all containers in registry", container_registry._containers)
|
||||||
assert not os.path.isfile(temp_file)
|
assert not os.path.isfile(temp_file)
|
||||||
new_filename = os.path.splitext(os.path.splitext(temp_file)[0])[0] + ".global.cfg"
|
mime_type = container_registry.getMimeTypeForContainer(GlobalStack)
|
||||||
assert os.path.isfile(new_filename)
|
file_name = urllib.parse.quote_plus("MachineLegacy") + "." + mime_type.preferredSuffix
|
||||||
|
path = Resources.getStoragePath(Resources.ContainerStacks, file_name)
|
||||||
|
assert os.path.isfile(path)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user