TestExtruderManager.py 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. from unittest.mock import MagicMock
  2. def createMockedExtruder(extruder_id):
  3. extruder = MagicMock()
  4. extruder.getId = MagicMock(return_value = extruder_id)
  5. return extruder
  6. def test_getAllExtruderSettings(extruder_manager):
  7. extruder_1 = createMockedExtruder("extruder_1")
  8. extruder_1.getProperty = MagicMock(return_value ="beep")
  9. extruder_2 = createMockedExtruder("extruder_2")
  10. extruder_2.getProperty = MagicMock(return_value="zomg")
  11. extruder_manager.getActiveExtruderStacks = MagicMock(return_value = [extruder_1, extruder_2])
  12. assert extruder_manager.getAllExtruderSettings("whatever", "value") == ["beep", "zomg"]
  13. def test_registerExtruder(extruder_manager):
  14. extruder = createMockedExtruder("beep")
  15. extruder.getMetaDataEntry = MagicMock(return_value = "0") # because the extruder position gets called
  16. extruder_manager.extrudersChanged = MagicMock()
  17. extruder_manager.registerExtruder(extruder, "zomg")
  18. assert extruder_manager.extrudersChanged.emit.call_count == 1
  19. # Doing it again should not trigger anything
  20. extruder_manager.registerExtruder(extruder, "zomg")
  21. assert extruder_manager.extrudersChanged.emit.call_count == 1