mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-23 06:33:55 -06:00
Add test for preferred material with the happy flow
The exact preferred material is available. Pick that.
This commit is contained in:
parent
e5c0812acc
commit
a117e937b9
4 changed files with 29 additions and 1 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
# Copyright (c) 2019 Ultimaker B.V.
|
||||||
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
from unittest.mock import patch, MagicMock
|
from unittest.mock import patch, MagicMock
|
||||||
import pytest
|
import pytest
|
||||||
from UM.Settings.DefinitionContainer import DefinitionContainer
|
from UM.Settings.DefinitionContainer import DefinitionContainer
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
# Copyright (c) 2019 Ultimaker B.V.
|
||||||
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
from unittest.mock import patch, MagicMock
|
from unittest.mock import patch, MagicMock
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
# Copyright (c) 2019 Ultimaker B.V.
|
||||||
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
from unittest.mock import patch, MagicMock
|
from unittest.mock import patch, MagicMock
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
# Copyright (c) 2019 Ultimaker B.V.
|
||||||
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
from unittest.mock import patch, MagicMock
|
from unittest.mock import patch, MagicMock
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
@ -101,7 +104,7 @@ def test_materialAdded_update(container_registry, machine_node, metadata, change
|
||||||
variant_node = createVariantNode("machine_1", machine_node, container_registry)
|
variant_node = createVariantNode("machine_1", machine_node, container_registry)
|
||||||
original_material_nodes = copy.copy(variant_node.materials)
|
original_material_nodes = copy.copy(variant_node.materials)
|
||||||
|
|
||||||
with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value=container_registry)):
|
with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value = container_registry)):
|
||||||
with patch("cura.Machines.VariantNode.MaterialNode"): # We're not testing the material node here, so patch it out.
|
with patch("cura.Machines.VariantNode.MaterialNode"): # We're not testing the material node here, so patch it out.
|
||||||
with patch.dict(metadata_dict, metadata):
|
with patch.dict(metadata_dict, metadata):
|
||||||
mocked_container = createMockedInstanceContainer()
|
mocked_container = createMockedInstanceContainer()
|
||||||
|
@ -113,3 +116,19 @@ def test_materialAdded_update(container_registry, machine_node, metadata, change
|
||||||
for key in changed_material_list:
|
for key in changed_material_list:
|
||||||
assert original_material_nodes[key] != variant_node.materials[key]
|
assert original_material_nodes[key] != variant_node.materials[key]
|
||||||
|
|
||||||
|
def test_preferredMaterialExactMatch():
|
||||||
|
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": 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."
|
Loading…
Add table
Add a link
Reference in a new issue