mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 23:17:32 -06:00
Move models around again
- Move machine related models to cura.Machines.Models - Move printer device related models to cura.PrinterOutput.Models - Other UI/GUI related modules in cura.UI
This commit is contained in:
parent
85b28a0c90
commit
4a171eebf6
48 changed files with 99 additions and 101 deletions
78
tests/PrinterOutput/Models/TestPrintJobOutputModel.py
Normal file
78
tests/PrinterOutput/Models/TestPrintJobOutputModel.py
Normal file
|
@ -0,0 +1,78 @@
|
|||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from cura.PrinterOutput.Models.PrinterConfigurationModel import PrinterConfigurationModel
|
||||
from cura.PrinterOutput.Models.PrintJobOutputModel import PrintJobOutputModel
|
||||
from cura.PrinterOutput.Models.PrinterOutputModel import PrinterOutputModel
|
||||
|
||||
test_validate_data_get_set = [
|
||||
{"attribute": "compatibleMachineFamilies", "value": ["yay"]},
|
||||
]
|
||||
|
||||
test_validate_data_get_update = [
|
||||
{"attribute": "configuration", "value": PrinterConfigurationModel()},
|
||||
{"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
|
Loading…
Add table
Add a link
Reference in a new issue