mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-14 10:17:52 -06:00
Add test for is_available on resulting quality groups
Done during Turbo Testing and Tooling.
This commit is contained in:
parent
5ae248341b
commit
2671f12c21
1 changed files with 69 additions and 13 deletions
|
@ -23,6 +23,18 @@ def container_registry():
|
||||||
result.findContainersMetadata = MagicMock(return_value = [metadata_dict])
|
result.findContainersMetadata = MagicMock(return_value = [metadata_dict])
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
## Creates a machine node without anything underneath it. No sub-nodes.
|
||||||
|
#
|
||||||
|
# For testing stuff with machine nodes without testing _loadAll(). You'll need
|
||||||
|
# to add subnodes manually in your test.
|
||||||
|
@pytest.fixture
|
||||||
|
def empty_machine_node():
|
||||||
|
empty_container_registry = MagicMock()
|
||||||
|
empty_container_registry.findContainersMetadata = MagicMock(return_value = [metadata_dict]) # Still contain the MachineNode's own metadata for the constructor.
|
||||||
|
empty_container_registry.findInstanceContainersMetadata = MagicMock(return_value = [])
|
||||||
|
with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value = empty_container_registry)):
|
||||||
|
with patch("cura.Machines.MachineNode.MachineNode._loadAll", MagicMock()):
|
||||||
|
return MachineNode("machine_1")
|
||||||
|
|
||||||
def getMetadataEntrySideEffect(*args, **kwargs):
|
def getMetadataEntrySideEffect(*args, **kwargs):
|
||||||
return metadata_dict.get(args[0])
|
return metadata_dict.get(args[0])
|
||||||
|
@ -64,19 +76,11 @@ def test_metadataProperties(container_registry):
|
||||||
|
|
||||||
## Test getting quality groups when there are quality profiles available for
|
## Test getting quality groups when there are quality profiles available for
|
||||||
# the requested configurations on two extruders.
|
# the requested configurations on two extruders.
|
||||||
def test_getQualityGroupsBothExtrudersAvailable():
|
def test_getQualityGroupsBothExtrudersAvailable(empty_machine_node):
|
||||||
# Create a machine node without constructing the tree beneath it. We don't want to depend on that for this test.
|
|
||||||
empty_container_registry = MagicMock()
|
|
||||||
empty_container_registry.findContainersMetadata = MagicMock(return_value = [metadata_dict]) # Still contain the MachineNode's own metadata for the constructor.
|
|
||||||
empty_container_registry.findInstanceContainersMetadata = MagicMock(return_value = [])
|
|
||||||
with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value = empty_container_registry)):
|
|
||||||
with patch("cura.Machines.MachineNode.MachineNode._loadAll", MagicMock()):
|
|
||||||
machine_node = MachineNode("machine_1")
|
|
||||||
|
|
||||||
# Prepare a tree inside the machine node.
|
# Prepare a tree inside the machine node.
|
||||||
extruder_0_node = MagicMock(quality_type = "quality_type_1")
|
extruder_0_node = MagicMock(quality_type = "quality_type_1")
|
||||||
extruder_1_node = MagicMock(quality_type = "quality_type_1") # Same quality type, so this is the one that can be returned.
|
extruder_1_node = MagicMock(quality_type = "quality_type_1") # Same quality type, so this is the one that can be returned.
|
||||||
machine_node.variants = {
|
empty_machine_node.variants = {
|
||||||
"variant_1": MagicMock(
|
"variant_1": MagicMock(
|
||||||
materials = {
|
materials = {
|
||||||
"material_1": MagicMock(
|
"material_1": MagicMock(
|
||||||
|
@ -100,16 +104,68 @@ def test_getQualityGroupsBothExtrudersAvailable():
|
||||||
container = MagicMock(id = "global_quality_container"), # Needs to exist, otherwise it won't add this quality type.
|
container = MagicMock(id = "global_quality_container"), # Needs to exist, otherwise it won't add this quality type.
|
||||||
getMetaDataEntry = lambda _, __: "Global Quality Profile Name"
|
getMetaDataEntry = lambda _, __: "Global Quality Profile Name"
|
||||||
)
|
)
|
||||||
machine_node.global_qualities = {
|
empty_machine_node.global_qualities = {
|
||||||
"quality_type_1": global_node
|
"quality_type_1": global_node
|
||||||
}
|
}
|
||||||
|
|
||||||
# Request the quality groups for the variants in the machine tree.
|
# Request the quality groups for the variants in the machine tree.
|
||||||
result = machine_node.getQualityGroups(["variant_1", "variant_2"], ["material_1", "material_2"], [True, True])
|
result = empty_machine_node.getQualityGroups(["variant_1", "variant_2"], ["material_1", "material_2"], [True, True])
|
||||||
|
|
||||||
assert "quality_type_1" in result, "This quality type was available for both extruders."
|
assert "quality_type_1" in result, "This quality type was available for both extruders."
|
||||||
assert result["quality_type_1"].node_for_global == global_node
|
assert result["quality_type_1"].node_for_global == global_node
|
||||||
assert result["quality_type_1"].nodes_for_extruders[0] == extruder_0_node
|
assert result["quality_type_1"].nodes_for_extruders[0] == extruder_0_node
|
||||||
assert result["quality_type_1"].nodes_for_extruders[1] == extruder_1_node
|
assert result["quality_type_1"].nodes_for_extruders[1] == extruder_1_node
|
||||||
assert result["quality_type_1"].name == global_node.getMetaDataEntry("name", "Unnamed Profile")
|
assert result["quality_type_1"].name == global_node.getMetaDataEntry("name", "Unnamed Profile")
|
||||||
assert result["quality_type_1"].quality_type == "quality_type_1"
|
assert result["quality_type_1"].quality_type == "quality_type_1"
|
||||||
|
|
||||||
|
## Test the "is_available" flag on quality groups.
|
||||||
|
#
|
||||||
|
# If a profile is available for a quality type on an extruder but not on all
|
||||||
|
# extruders, there should be a quality group for it but it should not be made
|
||||||
|
# available.
|
||||||
|
def test_getQualityGroupsAvailability(empty_machine_node):
|
||||||
|
# Prepare a tree inside the machine node.
|
||||||
|
extruder_0_both = MagicMock(quality_type = "quality_type_both") # This quality type is available for both extruders.
|
||||||
|
extruder_1_both = MagicMock(quality_type = "quality_type_both")
|
||||||
|
extruder_0_exclusive = MagicMock(quality_type = "quality_type_0") # These quality types are only available on one of the extruders.
|
||||||
|
extruder_1_exclusive = MagicMock(quality_type = "quality_type_1")
|
||||||
|
empty_machine_node.variants = {
|
||||||
|
"variant_1": MagicMock(
|
||||||
|
materials = {
|
||||||
|
"material_1": MagicMock(
|
||||||
|
qualities = {
|
||||||
|
"quality_0_both": extruder_0_both,
|
||||||
|
"quality_0_exclusive": extruder_0_exclusive
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
),
|
||||||
|
"variant_2": MagicMock(
|
||||||
|
materials = {
|
||||||
|
"material_2": MagicMock(
|
||||||
|
qualities = {
|
||||||
|
"quality_1_both": extruder_1_both,
|
||||||
|
"quality_1_exclusive": extruder_1_exclusive
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
global_both = MagicMock(container = MagicMock(id = "global_quality_both"), getMetaDataEntry = lambda _, __: "Global Quality Both")
|
||||||
|
global_0 = MagicMock(container = MagicMock(id = "global_quality_0"), getMetaDataEntry = lambda _, __: "Global Quality 0 Exclusive")
|
||||||
|
global_1 = MagicMock(container = MagicMock(id = "global_quality_1"), getMetaDataEntry = lambda _, __: "Global Quality 1 Exclusive")
|
||||||
|
empty_machine_node.global_qualities = {
|
||||||
|
"quality_type_both": global_both,
|
||||||
|
"quality_type_0": global_0,
|
||||||
|
"quality_type_1": global_1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Request the quality groups for the variants in the machine tree.
|
||||||
|
result = empty_machine_node.getQualityGroups(["variant_1", "variant_2"], ["material_1", "material_2"], [True, True])
|
||||||
|
|
||||||
|
assert "quality_type_both" in result, "This quality type was available on both extruders."
|
||||||
|
assert result["quality_type_both"].is_available, "This quality type was available on both extruders and thus should be made available."
|
||||||
|
assert "quality_type_0" in result, "This quality type was available for one of the extruders, and so there must be a group for it (even though it's unavailable)."
|
||||||
|
assert not result["quality_type_0"].is_available, "This quality type was only available for one of the extruders and thus can't be activated."
|
||||||
|
assert "quality_type_1" in result, "This quality type was available for one of the extruders, and so there must be a group for it (even though it's unavailable)."
|
||||||
|
assert not result["quality_type_1"].is_available, "This quality type was only available for one of the extruders and thus can't be activated."
|
Loading…
Add table
Add a link
Reference in a new issue