mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 23:17:32 -06:00
Add tests for PrintJobOutputModel & PrinterOutputModel
This commit is contained in:
parent
338f9c0052
commit
369c64e1b6
4 changed files with 165 additions and 5 deletions
|
@ -12,6 +12,7 @@ if TYPE_CHECKING:
|
|||
from cura.PrinterOutput.PrinterOutputModel import PrinterOutputModel
|
||||
from cura.PrinterOutput.ConfigurationModel import ConfigurationModel
|
||||
|
||||
|
||||
class PrintJobOutputModel(QObject):
|
||||
stateChanged = pyqtSignal()
|
||||
timeTotalChanged = pyqtSignal()
|
||||
|
@ -44,7 +45,7 @@ class PrintJobOutputModel(QObject):
|
|||
@pyqtProperty("QStringList", notify=compatibleMachineFamiliesChanged)
|
||||
def compatibleMachineFamilies(self):
|
||||
# Hack; Some versions of cluster will return a family more than once...
|
||||
return set(self._compatible_machine_families)
|
||||
return list(set(self._compatible_machine_families))
|
||||
|
||||
def setCompatibleMachineFamilies(self, compatible_machine_families: List[str]) -> None:
|
||||
if self._compatible_machine_families != compatible_machine_families:
|
||||
|
|
|
@ -22,7 +22,7 @@ class PrinterOutputModel(QObject):
|
|||
nameChanged = pyqtSignal()
|
||||
headPositionChanged = pyqtSignal()
|
||||
keyChanged = pyqtSignal()
|
||||
printerTypeChanged = pyqtSignal()
|
||||
typeChanged = pyqtSignal()
|
||||
buildplateChanged = pyqtSignal()
|
||||
cameraUrlChanged = pyqtSignal()
|
||||
configurationChanged = pyqtSignal()
|
||||
|
@ -73,7 +73,7 @@ class PrinterOutputModel(QObject):
|
|||
def isPreheating(self) -> bool:
|
||||
return self._is_preheating
|
||||
|
||||
@pyqtProperty(str, notify = printerTypeChanged)
|
||||
@pyqtProperty(str, notify = typeChanged)
|
||||
def type(self) -> str:
|
||||
return self._printer_type
|
||||
|
||||
|
@ -81,7 +81,7 @@ class PrinterOutputModel(QObject):
|
|||
if self._printer_type != printer_type:
|
||||
self._printer_type = printer_type
|
||||
self._printer_configuration.printerType = self._printer_type
|
||||
self.printerTypeChanged.emit()
|
||||
self.typeChanged.emit()
|
||||
self.configurationChanged.emit()
|
||||
|
||||
@pyqtProperty(str, notify = buildplateChanged)
|
||||
|
@ -179,7 +179,6 @@ class PrinterOutputModel(QObject):
|
|||
return self._name
|
||||
|
||||
def setName(self, name: str) -> None:
|
||||
self._setName(name)
|
||||
self.updateName(name)
|
||||
|
||||
def updateName(self, name: str) -> None:
|
||||
|
|
78
tests/PrinterOutput/TestPrintJobOutputModel.py
Normal file
78
tests/PrinterOutput/TestPrintJobOutputModel.py
Normal file
|
@ -0,0 +1,78 @@
|
|||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from cura.PrinterOutput.ConfigurationModel import ConfigurationModel
|
||||
from cura.PrinterOutput.PrintJobOutputModel import PrintJobOutputModel
|
||||
from cura.PrinterOutput.PrinterOutputModel import PrinterOutputModel
|
||||
|
||||
test_validate_data_get_set = [
|
||||
{"attribute": "compatibleMachineFamilies", "value": ["yay"]},
|
||||
]
|
||||
|
||||
test_validate_data_get_update = [
|
||||
{"attribute": "configuration", "value": ConfigurationModel()},
|
||||
{"attribute": "owner", "value": "WHOO"},
|
||||
{"attribute": "assignedPrinter", "value": PrinterOutputModel(MagicMock())},
|
||||
{"attribute": "key", "value": "YAY"},
|
||||
{"attribute": "name", "value": "Turtles"},
|
||||
{"attribute": "timeTotal", "value": 10},
|
||||
{"attribute": "timeElapsed", "value": 20},
|
||||
{"attribute": "state", "value": "BANANNA!"},
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("data", test_validate_data_get_set)
|
||||
def test_getAndSet(data):
|
||||
model = PrintJobOutputModel(MagicMock())
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
@pytest.mark.parametrize("data", test_validate_data_get_update)
|
||||
def test_getAndUpdate(data):
|
||||
model = PrintJobOutputModel(MagicMock())
|
||||
|
||||
# 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, "update" + 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, "update" + attribute)(data["value"])
|
||||
# The signal should not fire again
|
||||
assert signal.emit.call_count == 1
|
82
tests/PrinterOutput/TestPrinterOutputModel.py
Normal file
82
tests/PrinterOutput/TestPrinterOutputModel.py
Normal file
|
@ -0,0 +1,82 @@
|
|||
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from cura.PrinterOutput.ConfigurationModel import ConfigurationModel
|
||||
from cura.PrinterOutput.PrintJobOutputModel import PrintJobOutputModel
|
||||
from cura.PrinterOutput.PrinterOutputModel import PrinterOutputModel
|
||||
|
||||
test_validate_data_get_set = [
|
||||
{"attribute": "name", "value": "YAY"},
|
||||
{"attribute": "targetBedTemperature", "value": 192},
|
||||
]
|
||||
|
||||
test_validate_data_get_update = [
|
||||
{"attribute": "isPreheating", "value": True},
|
||||
{"attribute": "type", "value": "WHOO"},
|
||||
{"attribute": "buildplate", "value": "NFHA"},
|
||||
{"attribute": "key", "value": "YAY"},
|
||||
{"attribute": "name", "value": "Turtles"},
|
||||
{"attribute": "bedTemperature", "value": 200},
|
||||
{"attribute": "targetBedTemperature", "value": 9001},
|
||||
{"attribute": "activePrintJob", "value": PrintJobOutputModel(MagicMock())},
|
||||
{"attribute": "state", "value": "BEEPBOOP"},
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("data", test_validate_data_get_set)
|
||||
def test_getAndSet(data):
|
||||
model = PrinterOutputModel(MagicMock())
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
@pytest.mark.parametrize("data", test_validate_data_get_update)
|
||||
def test_getAndUpdate(data):
|
||||
model = PrinterOutputModel(MagicMock())
|
||||
|
||||
# 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, "update" + 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, "update" + attribute)(data["value"])
|
||||
# The signal should not fire again
|
||||
assert signal.emit.call_count == 1
|
Loading…
Add table
Add a link
Reference in a new issue