1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
from unittest.mock import patch, MagicMock
import pytest
from UM.Settings.InstanceContainer import InstanceContainer
from cura.Machines.QualityGroup import QualityGroup
from cura.Settings.CuraStackBuilder import CuraStackBuilder
@pytest.fixture
def global_variant():
container = InstanceContainer(container_id="global_variant")
container.setMetaDataEntry("type", "variant")
return container
@pytest.fixture
def material_instance_container():
container = InstanceContainer(container_id="material container")
container.setMetaDataEntry("type", "material")
return container
@pytest.fixture
def quality_container():
container = InstanceContainer(container_id="quality container")
container.setMetaDataEntry("type", "quality")
return container
@pytest.fixture
def intent_container():
container = InstanceContainer(container_id="intent container")
container.setMetaDataEntry("type", "intent")
return container
@pytest.fixture
def quality_changes_container():
container = InstanceContainer(container_id="quality changes container")
container.setMetaDataEntry("type", "quality_changes")
return container
def test_createMachineWithUnknownDefinition(application, container_registry):
application.getContainerRegistry = MagicMock(return_value=container_registry)
with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value=application)):
with patch("UM.ConfigurationErrorMessage.ConfigurationErrorMessage.getInstance") as mocked_config_error:
assert CuraStackBuilder.createMachine("Whatever", "NOPE") is None
assert mocked_config_error.addFaultyContainers.called_with("NOPE")
def test_createMachine(application, container_registry, definition_container, global_variant, material_instance_container,
quality_container, intent_container, quality_changes_container):
global_variant_node = MagicMock(name = "global variant node")
global_variant_node.container = global_variant
quality_group = QualityGroup(name = "zomg", quality_type = "normal")
quality_group.node_for_global = MagicMock(name = "Node for global")
quality_group.node_for_global.container = quality_container
application.getContainerRegistry = MagicMock(return_value=container_registry)
application.empty_material_container = material_instance_container
application.empty_quality_container = quality_container
application.empty_intent_container = intent_container
application.empty_quality_changes_container = quality_changes_container
application.empty_variant_container = global_variant
metadata = definition_container.getMetaData()
metadata["machine_extruder_trains"] = {}
metadata["preferred_quality_type"] = "normal"
container_registry.addContainer(definition_container)
quality_node = MagicMock()
machine_node = MagicMock()
machine_node.preferredGlobalQuality = MagicMock(return_value = quality_node)
quality_node.container = quality_container
# Patch out the creation of MachineNodes since that isn't under test (and would require quite a bit of extra setup)
with patch("cura.Machines.ContainerTree.MachineNode", MagicMock(return_value = machine_node)):
with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value=application)):
machine = CuraStackBuilder.createMachine("Whatever", "Test Definition")
assert machine.quality == quality_container
assert machine.definition == definition_container
assert machine.variant == global_variant
def test_createExtruderStack(application, definition_container, global_variant, material_instance_container,
quality_container, intent_container, quality_changes_container):
application.empty_material_container = material_instance_container
application.empty_quality_container = quality_container
application.empty_intent_container = intent_container
application.empty_quality_changes_container = quality_changes_container
with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value = application)):
extruder_stack = CuraStackBuilder.createExtruderStack("Whatever", definition_container, "meh", 0, global_variant, material_instance_container, quality_container)
assert extruder_stack.variant == global_variant
assert extruder_stack.material == material_instance_container
assert extruder_stack.quality == quality_container
|