mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-10 03:08:59 +08:00
Add test for duration messages for printInformation
This commit is contained in:
parent
f4a0b742cb
commit
75b185d462
@ -69,10 +69,8 @@ class PrintInformation(QObject):
|
||||
self._application.getInstance().getPreferences().preferenceChanged.connect(self._onPreferencesChanged)
|
||||
|
||||
self._multi_build_plate_model.activeBuildPlateChanged.connect(self._onActiveBuildPlateChanged)
|
||||
|
||||
self._onActiveMaterialsChanged()
|
||||
|
||||
self._material_amounts = [] # type: List[float]
|
||||
self._onActiveMaterialsChanged()
|
||||
|
||||
def initializeCuraMessagePrintTimeProperties(self) -> None:
|
||||
self._current_print_time = {} # type: Dict[int, Duration]
|
||||
@ -220,6 +218,7 @@ class PrintInformation(QObject):
|
||||
|
||||
material_guid = material.getMetaDataEntry("GUID")
|
||||
material_name = material.getName()
|
||||
|
||||
if material_guid in material_preference_values:
|
||||
material_values = material_preference_values[material_guid]
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
import functools
|
||||
|
||||
from UM.Qt.Duration import Duration
|
||||
from cura import PrintInformation
|
||||
from cura.Settings.MachineManager import MachineManager
|
||||
|
||||
@ -10,11 +11,22 @@ from UM.MimeTypeDatabase import MimeTypeDatabase, MimeType
|
||||
|
||||
def getPrintInformation(printer_name) -> PrintInformation:
|
||||
|
||||
mock_application = MagicMock()
|
||||
mock_application = MagicMock(name = "mock_application")
|
||||
mocked_preferences = MagicMock(name="mocked_preferences")
|
||||
mocked_extruder_stack = MagicMock()
|
||||
mocked_extruder_stack.getProperty = MagicMock(return_value = 3)
|
||||
mocked_material = MagicMock(name= "mocked material")
|
||||
mocked_material.getMetaDataEntry = MagicMock(return_value = "omgzomg")
|
||||
mocked_extruder_stack.material = mocked_material
|
||||
|
||||
mock_application.getInstance = MagicMock(return_value = mock_application)
|
||||
mocked_preferences.getValue = MagicMock(return_value = '{"omgzomg": {"spool_weight": 10, "spool_cost": 9}}')
|
||||
|
||||
global_container_stack = MagicMock()
|
||||
global_container_stack.extruders = {"0": mocked_extruder_stack}
|
||||
global_container_stack.definition.getName = MagicMock(return_value = printer_name)
|
||||
mock_application.getGlobalContainerStack = MagicMock(return_value = global_container_stack)
|
||||
mock_application.getPreferences = MagicMock(return_value = mocked_preferences)
|
||||
|
||||
multi_build_plate_model = MagicMock()
|
||||
multi_build_plate_model.maxBuildPlate = 0
|
||||
@ -26,13 +38,14 @@ def getPrintInformation(printer_name) -> PrintInformation:
|
||||
mock_machine_manager.getAbbreviatedMachineName = functools.partial(original_get_abbreviated_name, mock_machine_manager)
|
||||
mock_application.getMachineManager = MagicMock(return_value = mock_machine_manager)
|
||||
|
||||
Application.getInstance = MagicMock(return_type = mock_application)
|
||||
Application.getInstance = MagicMock(return_value = mock_application)
|
||||
|
||||
with patch("json.loads", lambda x: {}):
|
||||
print_information = PrintInformation.PrintInformation(mock_application)
|
||||
|
||||
return print_information
|
||||
|
||||
|
||||
def setup_module():
|
||||
MimeTypeDatabase.addMimeType(
|
||||
MimeType(
|
||||
@ -51,6 +64,21 @@ def setup_module():
|
||||
)
|
||||
|
||||
|
||||
def test_duration():
|
||||
print_information = getPrintInformation("ultimaker")
|
||||
|
||||
feature_print_times = print_information.getFeaturePrintTimes()
|
||||
assert int(feature_print_times["Travel"]) == int(Duration(None))
|
||||
|
||||
# Fake a print duration message
|
||||
print_information._onPrintDurationMessage(0, {"Travel": 20}, [10])
|
||||
|
||||
feature_print_times = print_information.getFeaturePrintTimes()
|
||||
assert int(feature_print_times["Travel"]) == 20
|
||||
|
||||
print_information.setToZeroPrintInformation()
|
||||
assert int(feature_print_times["Travel"]) == 0
|
||||
|
||||
|
||||
def test_setProjectName():
|
||||
|
||||
@ -96,6 +124,7 @@ def test_setProjectName():
|
||||
print_information.setProjectName(project_name[0] + project_name[1])
|
||||
assert "UM_" + project_name[0] != print_information._job_name
|
||||
|
||||
|
||||
def test_setJobName():
|
||||
|
||||
print_information = getPrintInformation("ultimaker")
|
||||
|
Loading…
x
Reference in New Issue
Block a user