mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-06-04 03:04:23 +08:00
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.
This commit is contained in:
parent
24cd2046f8
commit
a399bacab3
@ -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
|
||||
|
||||
|
||||
|
@ -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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user