TestCuraStackBuilder.py 4.5 KB

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