mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-08-07 05:53:59 -06:00
Add test for registring containers
This test tests adding container stacks and seeing if they convert well. Contributes to issue CURA-3427.
This commit is contained in:
parent
adefbaf72e
commit
e50b0884f0
1 changed files with 22 additions and 1 deletions
|
@ -11,6 +11,7 @@ from cura.Settings.CuraContainerRegistry import CuraContainerRegistry #The class
|
|||
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.
|
||||
from UM.Resources import Resources #Mocking some functions of this.
|
||||
import UM.Settings.InstanceContainer #Creating instance containers to register.
|
||||
import UM.Settings.ContainerRegistry #Making empty container stacks.
|
||||
import UM.Settings.ContainerStack #Setting the container registry here properly.
|
||||
from UM.Settings.DefinitionContainer import DefinitionContainer
|
||||
|
@ -18,7 +19,10 @@ from UM.Settings.DefinitionContainer import DefinitionContainer
|
|||
## Gives a fresh CuraContainerRegistry instance.
|
||||
@pytest.fixture()
|
||||
def container_registry():
|
||||
return CuraContainerRegistry()
|
||||
registry = CuraContainerRegistry()
|
||||
UM.Settings.InstanceContainer.setContainerRegistry(registry)
|
||||
UM.Settings.ContainerStack.setContainerRegistry(registry)
|
||||
return registry
|
||||
|
||||
def teardown():
|
||||
#If the temporary file for the legacy file rename test still exists, remove it.
|
||||
|
@ -26,6 +30,23 @@ def teardown():
|
|||
if os.path.isfile(temporary_file):
|
||||
os.remove(temporary_file)
|
||||
|
||||
## Tests whether the addContainer function properly converts ContainerStacks.
|
||||
def test_addContainerExtruderStack(container_registry):
|
||||
definition = DefinitionContainer(container_id = "Test Definition") #Need some definition first to be able to register stacks.
|
||||
container_registry.addContainer(definition)
|
||||
|
||||
container_stack = UM.Settings.ContainerStack.ContainerStack(stack_id = "Test Container Stack") #A container we're going to convert.
|
||||
container_stack.addMetaDataEntry("type", "extruder_train") #This is now an extruder train.
|
||||
container_stack.insertContainer(0, definition) #Add a definition to it so it doesn't complain.
|
||||
|
||||
mock_super_add_container = unittest.mock.MagicMock()
|
||||
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) == 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 loading gives objects of the correct type.
|
||||
@pytest.mark.parametrize("filename, output_class", [
|
||||
("ExtruderLegacy.stack.cfg", ExtruderStack),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue