Add test for preferred material matching on submaterials

Done during Turbo Testing and Tooling.
This commit is contained in:
Ghostkeeper 2019-10-04 17:11:32 +02:00
parent a117e937b9
commit 54fcb38fe6
No known key found for this signature in database
GPG key ID: 86BEF881AE2CF276

View file

@ -116,6 +116,8 @@ def test_materialAdded_update(container_registry, machine_node, metadata, change
for key in changed_material_list:
assert original_material_nodes[key] != variant_node.materials[key]
## Tests the preferred material when the exact base file is available in the
# materials list for this node.
def test_preferredMaterialExactMatch():
container_registry = MagicMock(
findContainersMetadata = MagicMock(return_value = [{"name": "test variant name"}])
@ -131,4 +133,23 @@ def test_preferredMaterialExactMatch():
"preferred_material_base_file": MagicMock(getMetaDataEntry = lambda x: 3) # Exact match.
}
assert variant_node.preferredMaterial(approximate_diameter = 3) == variant_node.materials["preferred_material_base_file"], "It should match exactly on this one since it's the preferred material."
assert variant_node.preferredMaterial(approximate_diameter = 3) == variant_node.materials["preferred_material_base_file"], "It should match exactly on this one since it's the preferred material."
## Tests the preferred material when a submaterial is available in the
# materials list for this node.
def test_preferredMaterialSubmaterial():
container_registry = MagicMock(
findContainersMetadata = MagicMock(return_value = [{"name": "test variant name"}])
)
machine_node = MagicMock(preferred_material = "preferred_material_base_file")
# Construct our own variant node with certain materials available.
with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value = container_registry)):
with patch("cura.Machines.VariantNode.VariantNode._loadAll", MagicMock()):
variant_node = VariantNode("test_variant", machine_node)
variant_node.materials = {
"some_different_material": MagicMock(getMetaDataEntry = lambda x: 3),
"preferred_material_base_file_aa04": MagicMock(getMetaDataEntry = lambda x: 3) # This is a submaterial of the preferred material.
}
assert variant_node.preferredMaterial(approximate_diameter = 3) == variant_node.materials["preferred_material_base_file_aa04"], "It should match exactly on this one since it's the preferred material."