|
@@ -4,6 +4,7 @@
|
|
|
import os #To find the directory with test files and find the test files.
|
|
|
import unittest.mock #To mock and monkeypatch stuff.
|
|
|
|
|
|
+from UM.Settings.DefinitionContainer import DefinitionContainer
|
|
|
from cura.Settings.ExtruderStack import ExtruderStack #Testing for returning the correct types of stacks.
|
|
|
from cura.Settings.GlobalStack import GlobalStack #Testing for returning the correct types of stacks.
|
|
|
import UM.Settings.InstanceContainer #Creating instance containers to register.
|
|
@@ -17,36 +18,40 @@ def teardown():
|
|
|
os.remove(temporary_file)
|
|
|
|
|
|
## Tests whether addContainer properly converts to ExtruderStack.
|
|
|
-def test_addContainerExtruderStack(container_registry, definition_container):
|
|
|
+def test_addContainerExtruderStack(container_registry, definition_container, definition_changes_container):
|
|
|
container_registry.addContainer(definition_container)
|
|
|
+ container_registry.addContainer(definition_changes_container)
|
|
|
|
|
|
container_stack = UM.Settings.ContainerStack.ContainerStack(stack_id = "Test Extruder Stack") #A container we're going to convert.
|
|
|
container_stack.setMetaDataEntry("type", "extruder_train") #This is now an extruder train.
|
|
|
container_stack.insertContainer(0, definition_container) #Add a definition to it so it doesn't complain.
|
|
|
+ container_stack.insertContainer(1, definition_changes_container)
|
|
|
|
|
|
mock_super_add_container = unittest.mock.MagicMock() #Takes the role of the Uranium-ContainerRegistry where the resulting containers get registered.
|
|
|
with unittest.mock.patch("UM.Settings.ContainerRegistry.ContainerRegistry.addContainer", mock_super_add_container):
|
|
|
container_registry.addContainer(container_stack)
|
|
|
|
|
|
- assert len(mock_super_add_container.call_args_list) == 2 #Called only once.
|
|
|
- assert len(mock_super_add_container.call_args_list[1][0]) == 1 #Called with one parameter.
|
|
|
- assert type(mock_super_add_container.call_args_list[1][0][0]) == ExtruderStack
|
|
|
+ assert len(mock_super_add_container.call_args_list) == 1 #Called only once.
|
|
|
+ assert len(mock_super_add_container.call_args_list[0][0]) == 1 #Called with one parameter.
|
|
|
+ assert type(mock_super_add_container.call_args_list[0][0][0]) == ExtruderStack
|
|
|
|
|
|
## Tests whether addContainer properly converts to GlobalStack.
|
|
|
-def test_addContainerGlobalStack(container_registry, definition_container):
|
|
|
+def test_addContainerGlobalStack(container_registry, definition_container, definition_changes_container):
|
|
|
container_registry.addContainer(definition_container)
|
|
|
+ container_registry.addContainer(definition_changes_container)
|
|
|
|
|
|
container_stack = UM.Settings.ContainerStack.ContainerStack(stack_id = "Test Global Stack") #A container we're going to convert.
|
|
|
container_stack.setMetaDataEntry("type", "machine") #This is now a global stack.
|
|
|
container_stack.insertContainer(0, definition_container) #Must have a definition.
|
|
|
+ container_stack.insertContainer(1, definition_changes_container) #Must have a definition changes.
|
|
|
|
|
|
mock_super_add_container = unittest.mock.MagicMock() #Takes the role of the Uranium-ContainerRegistry where the resulting containers get registered.
|
|
|
with unittest.mock.patch("UM.Settings.ContainerRegistry.ContainerRegistry.addContainer", mock_super_add_container):
|
|
|
container_registry.addContainer(container_stack)
|
|
|
|
|
|
- assert len(mock_super_add_container.call_args_list) == 2 #Called only once.
|
|
|
- assert len(mock_super_add_container.call_args_list[1][0]) == 1 #Called with one parameter.
|
|
|
- assert type(mock_super_add_container.call_args_list[1][0][0]) == GlobalStack
|
|
|
+ assert len(mock_super_add_container.call_args_list) == 1 #Called only once.
|
|
|
+ assert len(mock_super_add_container.call_args_list[0][0]) == 1 #Called with one parameter.
|
|
|
+ assert type(mock_super_add_container.call_args_list[0][0][0]) == GlobalStack
|
|
|
|
|
|
def test_addContainerGoodSettingVersion(container_registry, definition_container):
|
|
|
from cura.CuraApplication import CuraApplication
|
|
@@ -92,38 +97,3 @@ def test_addContainerBadSettingVersion(container_registry, definition_container)
|
|
|
container_registry.addContainer(instance)
|
|
|
|
|
|
mock_super_add_container.assert_not_called() #Should not get passed on to UM.Settings.ContainerRegistry.addContainer, because the setting_version doesn't match its definition!
|
|
|
-
|
|
|
-## Tests whether loading gives objects of the correct type.
|
|
|
-# @pytest.mark.parametrize("filename, output_class", [
|
|
|
-# ("ExtruderLegacy.stack.cfg", ExtruderStack),
|
|
|
-# ("MachineLegacy.stack.cfg", GlobalStack),
|
|
|
-# ("Left.extruder.cfg", ExtruderStack),
|
|
|
-# ("Global.global.cfg", GlobalStack),
|
|
|
-# ("Global.stack.cfg", GlobalStack)
|
|
|
-# ])
|
|
|
-# def test_loadTypes(filename, output_class, container_registry):
|
|
|
-# #Mock some dependencies.
|
|
|
-# 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(container_type = 0, id = None):
|
|
|
-# if id == "some_instance":
|
|
|
-# return [UM.Settings.ContainerRegistry._EmptyInstanceContainer(id)]
|
|
|
-# elif id == "some_definition":
|
|
|
-# return [DefinitionContainer(container_id = id)]
|
|
|
-# else:
|
|
|
-# return []
|
|
|
-#
|
|
|
-# container_registry.findContainers = findContainers
|
|
|
-#
|
|
|
-# with unittest.mock.patch("cura.Settings.GlobalStack.GlobalStack.findContainer"):
|
|
|
-# with unittest.mock.patch("os.remove"):
|
|
|
-# container_registry.load()
|
|
|
-#
|
|
|
-# #Check whether the resulting type was correct.
|
|
|
-# stack_id = filename.split(".")[0]
|
|
|
-# for container_id, container in container_registry._containers.items(): #Stupid ContainerRegistry class doesn't expose any way of getting at this except by prodding the privates.
|
|
|
-# if container_id == stack_id: #This is the one we're testing.
|
|
|
-# assert type(container) == output_class
|
|
|
-# break
|
|
|
-# else:
|
|
|
-# assert False #Container stack with specified ID was not loaded.
|