diff options
author | Ghostkeeper <rubend@tutanota.com> | 2021-10-13 11:34:59 +0300 |
---|---|---|
committer | Ghostkeeper <rubend@tutanota.com> | 2021-10-13 11:34:59 +0300 |
commit | a399bacab380ff016d4377e372b22eb92d9a92d9 (patch) | |
tree | 4a5eaab0be883cedcddb75849449fc579a423358 /tests | |
parent | 24cd2046f8e936fc1d30bea46df8a59e2859a125 (diff) |
Patch CuraApplication away while running tests for output devices
It needs CuraApplication because it wants to set metadata on the printer. But this is not relevant for the tests.
Contributes to issue CURA-8609.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/PrinterOutput/TestNetworkedPrinterOutputDevice.py | 13 | ||||
-rw-r--r-- | tests/PrinterOutput/TestPrinterOutputDevice.py | 8 |
2 files changed, 13 insertions, 8 deletions
diff --git a/tests/PrinterOutput/TestNetworkedPrinterOutputDevice.py b/tests/PrinterOutput/TestNetworkedPrinterOutputDevice.py index 84ad7f0473..2a5cc8a2d5 100644 --- a/tests/PrinterOutput/TestNetworkedPrinterOutputDevice.py +++ b/tests/PrinterOutput/TestNetworkedPrinterOutputDevice.py @@ -1,3 +1,6 @@ +# Copyright (c) 2021 Ultimaker B.V. +# Cura is released under the terms of the LGPLv3 or higher. + import time from unittest.mock import MagicMock, patch @@ -122,8 +125,9 @@ def test_put(): def test_timeout(): with patch("UM.Qt.QtApplication.QtApplication.getInstance"): - output_device = NetworkedPrinterOutputDevice(device_id="test", address="127.0.0.1", properties={}) - output_device.setConnectionState(ConnectionState.Connected) + output_device = NetworkedPrinterOutputDevice(device_id = "test", address = "127.0.0.1", properties = {}) + with patch("cura.CuraApplication.CuraApplication.getInstance"): + output_device.setConnectionState(ConnectionState.Connected) assert output_device.connectionState == ConnectionState.Connected output_device._update() @@ -131,9 +135,8 @@ def test_timeout(): output_device._last_response_time = time.time() - 15 # But we did recently ask for a response! output_device._last_request_time = time.time() - 5 - output_device._update() + with patch("cura.CuraApplication.CuraApplication.getInstance"): + output_device._update() # The connection should now be closed, since it went into timeout. assert output_device.connectionState == ConnectionState.Closed - - diff --git a/tests/PrinterOutput/TestPrinterOutputDevice.py b/tests/PrinterOutput/TestPrinterOutputDevice.py index 7a9e4e2cc5..7913e156b0 100644 --- a/tests/PrinterOutput/TestPrinterOutputDevice.py +++ b/tests/PrinterOutput/TestPrinterOutputDevice.py @@ -1,7 +1,8 @@ -from unittest.mock import MagicMock +# Copyright (c) 2021 Ultimaker B.V. +# Cura is released under the terms of the LGPLv3 or higher. import pytest -from unittest.mock import patch +from unittest.mock import MagicMock, patch from cura.PrinterOutput.Models.ExtruderConfigurationModel import ExtruderConfigurationModel from cura.PrinterOutput.Models.MaterialOutputModel import MaterialOutputModel @@ -33,7 +34,8 @@ def test_getAndSet(data, printer_output_device): setattr(model, data["attribute"] + "Changed", MagicMock()) # Attempt to set the value - getattr(model, "set" + attribute)(data["value"]) + with patch("cura.CuraApplication.CuraApplication.getInstance"): + getattr(model, "set" + attribute)(data["value"]) # Check if signal fired. signal = getattr(model, data["attribute"] + "Changed") |