From 54fcb38fe60afe3fa21f14ef4746d0fe597091b8 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 4 Oct 2019 17:11:32 +0200 Subject: [PATCH] Add test for preferred material matching on submaterials Done during Turbo Testing and Tooling. --- tests/Machines/TestVariantNode.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/Machines/TestVariantNode.py b/tests/Machines/TestVariantNode.py index 1af5d274f9..d7ee822ea3 100644 --- a/tests/Machines/TestVariantNode.py +++ b/tests/Machines/TestVariantNode.py @@ -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." \ No newline at end of file + 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." \ No newline at end of file