TestPrinterConfigurationModel.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from unittest.mock import MagicMock
  2. import pytest
  3. from cura.PrinterOutput.Models.PrinterConfigurationModel import PrinterConfigurationModel
  4. from cura.PrinterOutput.Models.ExtruderConfigurationModel import ExtruderConfigurationModel
  5. test_validate_data_get_set = [
  6. {"attribute": "extruderConfigurations", "value": [ExtruderConfigurationModel()]},
  7. {"attribute": "buildplateConfiguration", "value": "BHDHAHHADAD"},
  8. {"attribute": "printerType", "value": ":(", "check_signal": False},
  9. ]
  10. @pytest.mark.parametrize("data", test_validate_data_get_set)
  11. def test_getAndSet(data):
  12. model = PrinterConfigurationModel()
  13. # Convert the first letter into a capital
  14. attribute = list(data["attribute"])
  15. attribute[0] = attribute[0].capitalize()
  16. attribute = "".join(attribute)
  17. # mock the correct emit
  18. model.configurationChanged = MagicMock()
  19. signal = model.configurationChanged
  20. # Attempt to set the value
  21. getattr(model, "set" + attribute)(data["value"])
  22. # Check if signal fired.
  23. if data.get("check_signal", True):
  24. assert signal.emit.call_count == 1
  25. # Ensure that the value got set
  26. assert getattr(model, data["attribute"]) == data["value"]
  27. # Attempt to set the value again
  28. getattr(model, "set" + attribute)(data["value"])
  29. # The signal should not fire again
  30. if data.get("check_signal", True):
  31. assert signal.emit.call_count == 1