TestPrinterOutputDevice.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from unittest.mock import MagicMock
  2. import pytest
  3. from cura.PrinterOutput.PrinterOutputDevice import PrinterOutputDevice
  4. test_validate_data_get_set = [
  5. {"attribute": "connectionText", "value": "yay"},
  6. {"attribute": "connectionState", "value": 1},
  7. ]
  8. @pytest.mark.parametrize("data", test_validate_data_get_set)
  9. def test_getAndSet(data):
  10. model = PrinterOutputDevice("whatever")
  11. # Convert the first letter into a capital
  12. attribute = list(data["attribute"])
  13. attribute[0] = attribute[0].capitalize()
  14. attribute = "".join(attribute)
  15. # mock the correct emit
  16. setattr(model, data["attribute"] + "Changed", MagicMock())
  17. # Attempt to set the value
  18. getattr(model, "set" + attribute)(data["value"])
  19. # Check if signal fired.
  20. signal = getattr(model, data["attribute"] + "Changed")
  21. assert signal.emit.call_count == 1
  22. # Ensure that the value got set
  23. assert getattr(model, data["attribute"]) == data["value"]
  24. # Attempt to set the value again
  25. getattr(model, "set" + attribute)(data["value"])
  26. # The signal should not fire again
  27. assert signal.emit.call_count == 1