mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-08-09 23:05:01 -06:00
Add test for type of loaded container stacks
This tests if container stacks, when loading, get implemented with the correct class: Either an extruder stack or a global stack. Contributes to issue CURA-3497.
This commit is contained in:
parent
411e3a3976
commit
c91765c1ae
6 changed files with 90 additions and 0 deletions
49
tests/Settings/TestCuraContainerRegistry.py
Normal file
49
tests/Settings/TestCuraContainerRegistry.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
# Copyright (c) 2017 Ultimaker B.V.
|
||||
# Cura is released under the terms of the AGPLv3 or higher.
|
||||
|
||||
import os #To find the directory with test files and find the test files.
|
||||
import pytest #This module contains unit tests.
|
||||
import unittest.mock #To mock and monkeypatch stuff.
|
||||
|
||||
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.GlobalStack import GlobalStack #Testing for returning the correct types of stacks.
|
||||
from UM.Resources import Resources #Mocking some functions of this.
|
||||
import UM.Settings.ContainerRegistry #Making empty container stacks.
|
||||
import UM.Settings.ContainerStack #Setting the container registry here properly.
|
||||
|
||||
## Gives a fresh CuraContainerRegistry instance.
|
||||
@pytest.fixture()
|
||||
def container_registry():
|
||||
return CuraContainerRegistry()
|
||||
|
||||
## 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.
|
||||
UM.Settings.ContainerStack.setContainerRegistry(container_registry)
|
||||
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(id, container_type = 0):
|
||||
if id == "empty_material":
|
||||
return [UM.Settings.ContainerRegistry._EmptyInstanceContainer(id)]
|
||||
else:
|
||||
return []
|
||||
container_registry.findContainers = findContainers
|
||||
|
||||
container_registry.load()
|
||||
|
||||
#Check whether the resulting type was correct.
|
||||
stack_id = filename.split(".")[0]
|
||||
for container in container_registry._containers: #Stupid ContainerRegistry class doesn't expose any way of getting at this except by prodding the privates.
|
||||
print(container.getId(), "==", stack_id)
|
||||
if container.getId() == 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.
|
10
tests/Settings/stacks/ExtruderLegacy.stack.cfg
Normal file
10
tests/Settings/stacks/ExtruderLegacy.stack.cfg
Normal file
|
@ -0,0 +1,10 @@
|
|||
[general]
|
||||
version = 3
|
||||
name = Legacy Extruder Stack
|
||||
id = ExtruderLegacy
|
||||
|
||||
[metadata]
|
||||
type = extruder
|
||||
|
||||
[containers]
|
||||
0 = empty_material
|
7
tests/Settings/stacks/Global.global.cfg
Normal file
7
tests/Settings/stacks/Global.global.cfg
Normal file
|
@ -0,0 +1,7 @@
|
|||
[general]
|
||||
version = 3
|
||||
name = Global
|
||||
id = Global
|
||||
|
||||
[containers]
|
||||
0 = empty_material
|
7
tests/Settings/stacks/Global.stack.cfg
Normal file
7
tests/Settings/stacks/Global.stack.cfg
Normal file
|
@ -0,0 +1,7 @@
|
|||
[general]
|
||||
version = 3
|
||||
name = Global
|
||||
id = Global
|
||||
|
||||
[containers]
|
||||
0 = empty_material
|
7
tests/Settings/stacks/Left.extruder.cfg
Normal file
7
tests/Settings/stacks/Left.extruder.cfg
Normal file
|
@ -0,0 +1,7 @@
|
|||
[general]
|
||||
version = 3
|
||||
name = Left
|
||||
id = Left
|
||||
|
||||
[containers]
|
||||
0 = empty_material
|
10
tests/Settings/stacks/MachineLegacy.stack.cfg
Normal file
10
tests/Settings/stacks/MachineLegacy.stack.cfg
Normal file
|
@ -0,0 +1,10 @@
|
|||
[general]
|
||||
version = 3
|
||||
name = Legacy Global Stack
|
||||
id = MachineLegacy
|
||||
|
||||
[metadata]
|
||||
type = machine
|
||||
|
||||
[containers]
|
||||
0 = empty_material
|
Loading…
Add table
Add a link
Reference in a new issue