mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-20 19:09:12 +08:00
Add unit test for addDefaultMachineActions()
CURA-5812
This commit is contained in:
parent
cbd8c8739d
commit
89cb67017f
@ -145,13 +145,11 @@ class CuraContainerStack(ContainerStack):
|
||||
def setDefinition(self, new_definition: DefinitionContainerInterface) -> None:
|
||||
self.replaceContainer(_ContainerIndexes.Definition, new_definition)
|
||||
|
||||
## Get the definition container.
|
||||
#
|
||||
# \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:
|
||||
def getDefinition(self) -> "DefinitionContainer":
|
||||
return cast(DefinitionContainer, self._containers[_ContainerIndexes.Definition])
|
||||
|
||||
definition = pyqtProperty(QObject, fget = getDefinition, fset = setDefinition, notify = pyqtContainersChanged)
|
||||
|
||||
@override(ContainerStack)
|
||||
def getBottom(self) -> "DefinitionContainer":
|
||||
return self.definition
|
||||
|
@ -1,10 +1,24 @@
|
||||
# Copyright (c) 2018 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
from cura.MachineAction import MachineAction
|
||||
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:
|
||||
def __init__(self, key = ""):
|
||||
@ -13,6 +27,28 @@ class Machine:
|
||||
def getKey(self):
|
||||
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):
|
||||
|
||||
test_action = MachineAction(key = "test_action")
|
||||
|
@ -13,7 +13,6 @@ from cura.CuraApplication import CuraApplication
|
||||
from cura.MachineActionManager import MachineActionManager
|
||||
|
||||
|
||||
|
||||
# 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.
|
||||
@pytest.fixture()
|
||||
|
Loading…
x
Reference in New Issue
Block a user