TestCuraStackBuilder.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. mocked_config_error = MagicMock()
  35. with patch("UM.ConfigurationErrorMessage.ConfigurationErrorMessage.getInstance", MagicMock(return_value=mocked_config_error)):
  36. assert CuraStackBuilder.createMachine("Whatever", "NOPE") is None
  37. mocked_config_error.addFaultyContainers.assert_called_once_with("NOPE")
  38. def test_createMachine(application, container_registry, definition_container, global_variant, material_instance_container,
  39. quality_container, intent_container, quality_changes_container):
  40. global_variant_node = MagicMock(name = "global variant node")
  41. global_variant_node.container = global_variant
  42. quality_group = QualityGroup(name = "zomg", quality_type = "normal")
  43. quality_group.node_for_global = MagicMock(name = "Node for global")
  44. quality_group.node_for_global.container = quality_container
  45. application.getContainerRegistry = MagicMock(return_value=container_registry)
  46. application.empty_material_container = material_instance_container
  47. application.empty_quality_container = quality_container
  48. application.empty_intent_container = intent_container
  49. application.empty_quality_changes_container = quality_changes_container
  50. application.empty_variant_container = global_variant
  51. metadata = definition_container.getMetaData()
  52. metadata["machine_extruder_trains"] = {}
  53. metadata["preferred_quality_type"] = "normal"
  54. container_registry.addContainer(definition_container)
  55. quality_node = MagicMock()
  56. machine_node = MagicMock()
  57. machine_node.preferredGlobalQuality = MagicMock(return_value = quality_node)
  58. quality_node.container = quality_container
  59. # Patch out the creation of MachineNodes since that isn't under test (and would require quite a bit of extra setup)
  60. with patch("cura.Machines.ContainerTree.MachineNode", MagicMock(return_value = machine_node)):
  61. with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value=application)):
  62. machine = CuraStackBuilder.createMachine("Whatever", "Test Definition")
  63. assert machine.quality == quality_container
  64. assert machine.definition == definition_container
  65. assert machine.variant == global_variant
  66. def test_createExtruderStack(application, definition_container, global_variant, material_instance_container,
  67. quality_container, intent_container, quality_changes_container):
  68. application.empty_material_container = material_instance_container
  69. application.empty_quality_container = quality_container
  70. application.empty_intent_container = intent_container
  71. application.empty_quality_changes_container = quality_changes_container
  72. with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value = application)):
  73. extruder_stack = CuraStackBuilder.createExtruderStack("Whatever", definition_container, "meh", 0, global_variant, material_instance_container, quality_container)
  74. assert extruder_stack.variant == global_variant
  75. assert extruder_stack.material == material_instance_container
  76. assert extruder_stack.quality == quality_container