mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-11-26 20:31:35 -07:00
Add unit test for addDefaultMachineActions()
CURA-5812
This commit is contained in:
parent
cbd8c8739d
commit
89cb67017f
3 changed files with 39 additions and 6 deletions
|
|
@ -145,13 +145,11 @@ class CuraContainerStack(ContainerStack):
|
||||||
def setDefinition(self, new_definition: DefinitionContainerInterface) -> None:
|
def setDefinition(self, new_definition: DefinitionContainerInterface) -> None:
|
||||||
self.replaceContainer(_ContainerIndexes.Definition, new_definition)
|
self.replaceContainer(_ContainerIndexes.Definition, new_definition)
|
||||||
|
|
||||||
## Get the definition container.
|
def getDefinition(self) -> "DefinitionContainer":
|
||||||
#
|
|
||||||
# \return The definition container. Should always be a valid container, but can be equal to the empty InstanceContainer.
|
|
||||||
@pyqtProperty(QObject, fset = setDefinition, notify = pyqtContainersChanged)
|
|
||||||
def definition(self) -> DefinitionContainer:
|
|
||||||
return cast(DefinitionContainer, self._containers[_ContainerIndexes.Definition])
|
return cast(DefinitionContainer, self._containers[_ContainerIndexes.Definition])
|
||||||
|
|
||||||
|
definition = pyqtProperty(QObject, fget = getDefinition, fset = setDefinition, notify = pyqtContainersChanged)
|
||||||
|
|
||||||
@override(ContainerStack)
|
@override(ContainerStack)
|
||||||
def getBottom(self) -> "DefinitionContainer":
|
def getBottom(self) -> "DefinitionContainer":
|
||||||
return self.definition
|
return self.definition
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,24 @@
|
||||||
# Copyright (c) 2018 Ultimaker B.V.
|
# Copyright (c) 2018 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from cura.MachineAction import MachineAction
|
from cura.MachineAction import MachineAction
|
||||||
from cura.MachineActionManager import NotUniqueMachineActionError, UnknownMachineActionError
|
from cura.MachineActionManager import NotUniqueMachineActionError, UnknownMachineActionError
|
||||||
|
from cura.Settings.GlobalStack import GlobalStack
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def global_stack():
|
||||||
|
gs = GlobalStack("test_global_stack")
|
||||||
|
gs._metadata = {"supported_actions": ["supported_action_1", "supported_action_2"],
|
||||||
|
"required_actions": ["required_action_1", "required_action_2"],
|
||||||
|
"first_start_actions": ["first_start_actions_1", "first_start_actions_2"]
|
||||||
|
}
|
||||||
|
return gs
|
||||||
|
|
||||||
|
|
||||||
class Machine:
|
class Machine:
|
||||||
def __init__(self, key = ""):
|
def __init__(self, key = ""):
|
||||||
|
|
@ -13,6 +27,28 @@ class Machine:
|
||||||
def getKey(self):
|
def getKey(self):
|
||||||
return self._key
|
return self._key
|
||||||
|
|
||||||
|
|
||||||
|
def test_addDefaultMachineActions(machine_action_manager, global_stack):
|
||||||
|
all_actions = []
|
||||||
|
for action_key_list in global_stack._metadata.values():
|
||||||
|
for key in action_key_list:
|
||||||
|
all_actions.append(MachineAction(key = key))
|
||||||
|
for action in all_actions:
|
||||||
|
machine_action_manager.addMachineAction(action)
|
||||||
|
|
||||||
|
machine_action_manager.addDefaultMachineActions(global_stack)
|
||||||
|
definition_id = global_stack.getDefinition().getId()
|
||||||
|
|
||||||
|
support_action_keys = [a.getKey() for a in machine_action_manager.getSupportedActions(definition_id)]
|
||||||
|
assert support_action_keys == global_stack.getMetaDataEntry("supported_actions")
|
||||||
|
|
||||||
|
required_action_keys = [a.getKey() for a in machine_action_manager.getRequiredActions(definition_id)]
|
||||||
|
assert required_action_keys == global_stack.getMetaDataEntry("required_actions")
|
||||||
|
|
||||||
|
first_start_action_keys = [a.getKey() for a in machine_action_manager.getFirstStartActions(definition_id)]
|
||||||
|
assert first_start_action_keys == global_stack.getMetaDataEntry("first_start_actions")
|
||||||
|
|
||||||
|
|
||||||
def test_addMachineAction(machine_action_manager):
|
def test_addMachineAction(machine_action_manager):
|
||||||
|
|
||||||
test_action = MachineAction(key = "test_action")
|
test_action = MachineAction(key = "test_action")
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ from cura.CuraApplication import CuraApplication
|
||||||
from cura.MachineActionManager import MachineActionManager
|
from cura.MachineActionManager import MachineActionManager
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Create a CuraApplication object that will be shared among all tests. It needs to be initialized.
|
# Create a CuraApplication object that will be shared among all tests. It needs to be initialized.
|
||||||
# Since we need to use it more that once, we create the application the first time and use its instance afterwards.
|
# Since we need to use it more that once, we create the application the first time and use its instance afterwards.
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue