mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-14 02:07:51 -06:00
Fix some test in the CuraContainerRegistry.
Delete a test that needs a ContainerProvider. We need to discuss if we want to add it back, depending if we are still keeping the providers. Contributes to CURA-5628.
This commit is contained in:
parent
b85950b128
commit
77c5a94db2
23 changed files with 36 additions and 231 deletions
|
@ -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.
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
import pytest
|
||||
|
||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||
from UM.Settings.ContainerStack import setContainerRegistry
|
||||
from UM.Settings.DefinitionContainer import DefinitionContainer #To provide definition containers in the registry fixtures.
|
||||
from UM.Settings.InstanceContainer import InstanceContainer
|
||||
from cura.Settings.CuraContainerRegistry import CuraContainerRegistry
|
||||
|
@ -15,29 +17,38 @@ import cura.Settings.CuraContainerStack
|
|||
# Returns the CuraContainerRegistry instance with some empty containers.
|
||||
@pytest.fixture()
|
||||
def container_registry(application) -> CuraContainerRegistry:
|
||||
return application.getContainerRegistry()
|
||||
ContainerRegistry._ContainerRegistry__instance= None # Need to reset since we only allow one instance
|
||||
registry = CuraContainerRegistry(application)
|
||||
setContainerRegistry(registry)
|
||||
return registry
|
||||
|
||||
# Gives an arbitrary definition container.
|
||||
@pytest.fixture()
|
||||
def definition_container() -> DefinitionContainer:
|
||||
return DefinitionContainer(container_id = "Test Definition")
|
||||
|
||||
#An empty global stack to test with.
|
||||
# Gives an arbitrary definition changes container.
|
||||
@pytest.fixture()
|
||||
def global_stack() -> GlobalStack:
|
||||
global_stack = GlobalStack("TestGlobalStack")
|
||||
# There is a restriction here that the definition changes cannot be an empty container. Added in CURA-5281
|
||||
definition_changes_container = InstanceContainer(container_id = "InstanceContainer")
|
||||
def definition_changes_container() -> InstanceContainer:
|
||||
definition_changes_container = InstanceContainer(container_id = "Test Definition Changes")
|
||||
definition_changes_container.setMetaDataEntry("type", "definition_changes")
|
||||
# Add current setting version to the instance container
|
||||
from cura.CuraApplication import CuraApplication
|
||||
definition_changes_container.getMetaData()["setting_version"] = CuraApplication.SettingVersion
|
||||
return definition_changes_container
|
||||
|
||||
# An empty global stack to test with.
|
||||
# There is a restriction here that the definition changes cannot be an empty container. Added in CURA-5281
|
||||
@pytest.fixture()
|
||||
def global_stack(definition_changes_container) -> GlobalStack:
|
||||
global_stack = GlobalStack("TestGlobalStack")
|
||||
global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.DefinitionChanges] = definition_changes_container
|
||||
return global_stack
|
||||
|
||||
## An empty extruder stack to test with.
|
||||
@pytest.fixture()
|
||||
def extruder_stack() -> ExtruderStack:
|
||||
extruder_stack= ExtruderStack("TestExtruderStack")
|
||||
# An empty extruder stack to test with.
|
||||
# There is a restriction here that the definition changes cannot be an empty container. Added in CURA-5281
|
||||
definition_changes_container = InstanceContainer(container_id = "InstanceContainer")
|
||||
definition_changes_container.setMetaDataEntry("type", "definition_changes")
|
||||
@pytest.fixture()
|
||||
def extruder_stack(definition_changes_container) -> ExtruderStack:
|
||||
extruder_stack= ExtruderStack("TestExtruderStack")
|
||||
extruder_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.DefinitionChanges] = definition_changes_container
|
||||
return extruder_stack
|
|
@ -1,12 +0,0 @@
|
|||
[general]
|
||||
version = 3
|
||||
name = Complete
|
||||
id = Complete
|
||||
|
||||
[containers]
|
||||
0 = some_user_changes
|
||||
1 = some_quality_changes
|
||||
2 = some_quality
|
||||
3 = some_material
|
||||
4 = some_variant
|
||||
5 = some_definition
|
|
@ -1,13 +0,0 @@
|
|||
[general]
|
||||
version = 3
|
||||
name = Complete
|
||||
id = Complete
|
||||
|
||||
[containers]
|
||||
0 = some_user_changes
|
||||
1 = some_quality_changes
|
||||
2 = some_quality
|
||||
3 = some_material
|
||||
4 = some_variant
|
||||
5 = some_definition_changes
|
||||
6 = some_definition
|
|
@ -1,11 +0,0 @@
|
|||
[general]
|
||||
version = 3
|
||||
name = Legacy Extruder Stack
|
||||
id = ExtruderLegacy
|
||||
|
||||
[metadata]
|
||||
type = extruder_train
|
||||
|
||||
[containers]
|
||||
3 = some_instance
|
||||
5 = some_definition
|
|
@ -1,8 +0,0 @@
|
|||
[general]
|
||||
version = 3
|
||||
name = Global
|
||||
id = Global
|
||||
|
||||
[containers]
|
||||
3 = some_instance
|
||||
6 = some_definition
|
|
@ -1,11 +0,0 @@
|
|||
[general]
|
||||
version = 3
|
||||
name = Global
|
||||
id = Global
|
||||
|
||||
[metadata]
|
||||
type = machine
|
||||
|
||||
[containers]
|
||||
3 = some_instance
|
||||
6 = some_definition
|
|
@ -1,8 +0,0 @@
|
|||
[general]
|
||||
version = 3
|
||||
name = Left
|
||||
id = Left
|
||||
|
||||
[containers]
|
||||
3 = some_instance
|
||||
5 = some_definition
|
|
@ -1,11 +0,0 @@
|
|||
[general]
|
||||
version = 3
|
||||
name = Legacy Global Stack
|
||||
id = MachineLegacy
|
||||
|
||||
[metadata]
|
||||
type = machine
|
||||
|
||||
[containers]
|
||||
3 = some_instance
|
||||
6 = some_definition
|
|
@ -1,7 +0,0 @@
|
|||
[general]
|
||||
version = 3
|
||||
name = Only Definition
|
||||
id = OnlyDefinition
|
||||
|
||||
[containers]
|
||||
5 = some_definition
|
|
@ -1,7 +0,0 @@
|
|||
[general]
|
||||
version = 3
|
||||
name = Only Definition
|
||||
id = OnlyDefinition
|
||||
|
||||
[containers]
|
||||
6 = some_definition
|
|
@ -1,8 +0,0 @@
|
|||
[general]
|
||||
version = 3
|
||||
name = Only Definition Changes
|
||||
id = OnlyDefinitionChanges
|
||||
|
||||
[containers]
|
||||
5 = some_instance
|
||||
6 = some_definition
|
|
@ -1,8 +0,0 @@
|
|||
[general]
|
||||
version = 3
|
||||
name = Only Material
|
||||
id = OnlyMaterial
|
||||
|
||||
[containers]
|
||||
3 = some_instance
|
||||
5 = some_definition
|
|
@ -1,8 +0,0 @@
|
|||
[general]
|
||||
version = 3
|
||||
name = Only Material
|
||||
id = OnlyMaterial
|
||||
|
||||
[containers]
|
||||
3 = some_instance
|
||||
6 = some_definition
|
|
@ -1,8 +0,0 @@
|
|||
[general]
|
||||
version = 3
|
||||
name = Only Quality
|
||||
id = OnlyQuality
|
||||
|
||||
[containers]
|
||||
2 = some_instance
|
||||
5 = some_definition
|
|
@ -1,8 +0,0 @@
|
|||
[general]
|
||||
version = 3
|
||||
name = Only Quality
|
||||
id = OnlyQuality
|
||||
|
||||
[containers]
|
||||
2 = some_instance
|
||||
6 = some_definition
|
|
@ -1,8 +0,0 @@
|
|||
[general]
|
||||
version = 3
|
||||
name = Only Quality Changes
|
||||
id = OnlyQualityChanges
|
||||
|
||||
[containers]
|
||||
1 = some_instance
|
||||
5 = some_definition
|
|
@ -1,8 +0,0 @@
|
|||
[general]
|
||||
version = 3
|
||||
name = Only Quality Changes
|
||||
id = OnlyQualityChanges
|
||||
|
||||
[containers]
|
||||
1 = some_instance
|
||||
6 = some_definition
|
|
@ -1,8 +0,0 @@
|
|||
[general]
|
||||
version = 3
|
||||
name = Only User
|
||||
id = OnlyUser
|
||||
|
||||
[containers]
|
||||
0 = some_instance
|
||||
5 = some_definition
|
|
@ -1,8 +0,0 @@
|
|||
[general]
|
||||
version = 3
|
||||
name = Only User
|
||||
id = OnlyUser
|
||||
|
||||
[containers]
|
||||
0 = some_instance
|
||||
6 = some_definition
|
|
@ -1,8 +0,0 @@
|
|||
[general]
|
||||
version = 3
|
||||
name = Only Variant
|
||||
id = OnlyVariant
|
||||
|
||||
[containers]
|
||||
4 = some_instance
|
||||
5 = some_definition
|
|
@ -1,8 +0,0 @@
|
|||
[general]
|
||||
version = 3
|
||||
name = Only Variant
|
||||
id = OnlyVariant
|
||||
|
||||
[containers]
|
||||
4 = some_instance
|
||||
6 = some_definition
|
|
@ -20,4 +20,4 @@ def application() -> CuraApplication:
|
|||
# Returns a MachineActionManager instance.
|
||||
@pytest.fixture()
|
||||
def machine_action_manager(application) -> MachineActionManager:
|
||||
return application.getMachineActionManager()
|
||||
return MachineActionManager(application)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue