From a399bacab380ff016d4377e372b22eb92d9a92d9 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Wed, 13 Oct 2021 10:34:59 +0200 Subject: [PATCH] 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. --- .../TestNetworkedPrinterOutputDevice.py | 13 ++++++++----- 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")