diff options
author | Lipu Fei <lipu.fei815@gmail.com> | 2019-03-20 11:41:03 +0300 |
---|---|---|
committer | Lipu Fei <lipu.fei815@gmail.com> | 2019-03-20 11:43:09 +0300 |
commit | 2b39d6422c63d0863c1ae4115197b25468f8e321 (patch) | |
tree | f4add2160be48d8eea63dc7122b0949e63188590 /tests/PrinterOutput | |
parent | e30104ff7fa541f10ac333ae9df684acf6784656 (diff) |
Move PrinterOutputDevice into cura.PrinterOutput module
Diffstat (limited to 'tests/PrinterOutput')
-rw-r--r-- | tests/PrinterOutput/TestNetworkedPrinterOutputDevice.py | 2 | ||||
-rw-r--r-- | tests/PrinterOutput/TestPrinterOutputDevice.py | 37 |
2 files changed, 38 insertions, 1 deletions
diff --git a/tests/PrinterOutput/TestNetworkedPrinterOutputDevice.py b/tests/PrinterOutput/TestNetworkedPrinterOutputDevice.py index b3f7277051..da3ce66ac4 100644 --- a/tests/PrinterOutput/TestNetworkedPrinterOutputDevice.py +++ b/tests/PrinterOutput/TestNetworkedPrinterOutputDevice.py @@ -4,7 +4,7 @@ from unittest.mock import MagicMock from PyQt5.QtNetwork import QNetworkAccessManager from PyQt5.QtCore import QUrl from cura.PrinterOutput.NetworkedPrinterOutputDevice import NetworkedPrinterOutputDevice, AuthState -from cura.PrinterOutputDevice import ConnectionState +from cura.PrinterOutput.PrinterOutputDevice import ConnectionState def test_properties(): diff --git a/tests/PrinterOutput/TestPrinterOutputDevice.py b/tests/PrinterOutput/TestPrinterOutputDevice.py new file mode 100644 index 0000000000..4c12a34859 --- /dev/null +++ b/tests/PrinterOutput/TestPrinterOutputDevice.py @@ -0,0 +1,37 @@ +from unittest.mock import MagicMock + +import pytest +from cura.PrinterOutput.PrinterOutputDevice import PrinterOutputDevice + +test_validate_data_get_set = [ + {"attribute": "connectionText", "value": "yay"}, + {"attribute": "connectionState", "value": 1}, +] + + +@pytest.mark.parametrize("data", test_validate_data_get_set) +def test_getAndSet(data): + model = PrinterOutputDevice("whatever") + + # Convert the first letter into a capital + attribute = list(data["attribute"]) + attribute[0] = attribute[0].capitalize() + attribute = "".join(attribute) + + # mock the correct emit + setattr(model, data["attribute"] + "Changed", MagicMock()) + + # Attempt to set the value + getattr(model, "set" + attribute)(data["value"]) + + # Check if signal fired. + signal = getattr(model, data["attribute"] + "Changed") + assert signal.emit.call_count == 1 + + # Ensure that the value got set + assert getattr(model, data["attribute"]) == data["value"] + + # Attempt to set the value again + getattr(model, "set" + attribute)(data["value"]) + # The signal should not fire again + assert signal.emit.call_count == 1 |