TestCuraStackBuilder.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 quality_changes_container():
  23. container = InstanceContainer(container_id="quality changes container")
  24. container.setMetaDataEntry("type", "quality_changes")
  25. return container
  26. def test_createMachineWithUnknownDefinition(application, container_registry):
  27. application.getContainerRegistry = MagicMock(return_value=container_registry)
  28. with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value=application)):
  29. with patch("UM.ConfigurationErrorMessage.ConfigurationErrorMessage.getInstance") as mocked_config_error:
  30. assert CuraStackBuilder.createMachine("Whatever", "NOPE") is None
  31. assert mocked_config_error.addFaultyContainers.called_with("NOPE")
  32. def test_createMachine(application, container_registry, definition_container, global_variant, material_instance_container, quality_container, quality_changes_container):
  33. variant_manager = MagicMock(name = "Variant Manager")
  34. quality_manager = MagicMock(name = "Quality Manager")
  35. global_variant_node = MagicMock( name = "global variant node")
  36. global_variant_node.getContainer = MagicMock(return_value = global_variant)
  37. variant_manager.getDefaultVariantNode = MagicMock(return_value = global_variant_node)
  38. quality_group = QualityGroup(name = "zomg", quality_type = "normal")
  39. quality_group.node_for_global = MagicMock(name = "Node for global")
  40. quality_group.node_for_global.getContainer = MagicMock(return_value = quality_container)
  41. quality_manager.getQualityGroups = MagicMock(return_value = {"normal": quality_group})
  42. application.getContainerRegistry = MagicMock(return_value=container_registry)
  43. application.getVariantManager = MagicMock(return_value = variant_manager)
  44. application.getQualityManager = MagicMock(return_value = quality_manager)
  45. application.empty_material_container = material_instance_container
  46. application.empty_quality_container = quality_container
  47. application.empty_quality_changes_container = quality_changes_container
  48. metadata = definition_container.getMetaData()
  49. metadata["machine_extruder_trains"] = {}
  50. metadata["preferred_quality_type"] = "normal"
  51. container_registry.addContainer(definition_container)
  52. with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value=application)):
  53. machine = CuraStackBuilder.createMachine("Whatever", "Test Definition")
  54. assert machine.quality == quality_container
  55. assert machine.definition == definition_container
  56. assert machine.variant == global_variant
  57. def test_createExtruderStack(application, definition_container, global_variant, material_instance_container, quality_container, quality_changes_container):
  58. application.empty_material_container = material_instance_container
  59. application.empty_quality_container = quality_container
  60. application.empty_quality_changes_container = quality_changes_container
  61. with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value=application)):
  62. extruder_stack = CuraStackBuilder.createExtruderStack("Whatever", definition_container, "meh", 0, global_variant, material_instance_container, quality_container)
  63. assert extruder_stack.variant == global_variant
  64. assert extruder_stack.material == material_instance_container
  65. assert extruder_stack.quality == quality_container