From 34c3a0474464f621fa5d35e7f5a9bbe09f4503ac Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Thu, 22 Aug 2019 14:24:19 +0200 Subject: [PATCH] Added missing tests for peripheral Not part of the ticket, but I'm boyscouting this. --- .../Models/PrinterOutputModel.py | 2 +- .../Models/TestPrinterOutputModel.py | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cura/PrinterOutput/Models/PrinterOutputModel.py b/cura/PrinterOutput/Models/PrinterOutputModel.py index ccdbb500b9..3927da0313 100644 --- a/cura/PrinterOutput/Models/PrinterOutputModel.py +++ b/cura/PrinterOutput/Models/PrinterOutputModel.py @@ -304,7 +304,7 @@ class PrinterOutputModel(QObject): @pyqtProperty(str, notify = peripheralsChanged) def peripherals(self) -> str: - return ", ".join(*[peripheral.name for peripheral in self._peripherals]) + return ", ".join([peripheral.name for peripheral in self._peripherals]) def addPeripheral(self, peripheral: Peripheral) -> None: self._peripherals.append(peripheral) diff --git a/tests/PrinterOutput/Models/TestPrinterOutputModel.py b/tests/PrinterOutput/Models/TestPrinterOutputModel.py index 577a27bd6f..8136e670b7 100644 --- a/tests/PrinterOutput/Models/TestPrinterOutputModel.py +++ b/tests/PrinterOutput/Models/TestPrinterOutputModel.py @@ -6,6 +6,7 @@ import pytest from cura.PrinterOutput.Models.PrintJobOutputModel import PrintJobOutputModel from cura.PrinterOutput.Models.PrinterOutputModel import PrinterOutputModel +from cura.PrinterOutput.Peripheral import Peripheral test_validate_data_get_set = [ {"attribute": "name", "value": "YAY"}, @@ -81,3 +82,24 @@ def test_getAndUpdate(data): getattr(model, "update" + attribute)(data["value"]) # The signal should not fire again assert signal.emit.call_count == 1 + + +def test_peripherals(): + model = PrinterOutputModel(MagicMock()) + model.peripheralsChanged = MagicMock() + + peripheral = MagicMock(spec=Peripheral) + peripheral.name = "test" + peripheral2 = MagicMock(spec=Peripheral) + peripheral2.name = "test2" + + model.addPeripheral(peripheral) + assert model.peripheralsChanged.emit.call_count == 1 + model.addPeripheral(peripheral2) + assert model.peripheralsChanged.emit.call_count == 2 + + assert model.peripherals == "test, test2" + + model.removePeripheral(peripheral) + assert model.peripheralsChanged.emit.call_count == 3 + assert model.peripherals == "test2"