|
@@ -1,5 +1,7 @@
|
|
|
+import functools
|
|
|
|
|
|
from cura import PrintInformation
|
|
|
+from cura.Settings.MachineManager import MachineManager
|
|
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
from UM.Application import Application
|
|
@@ -11,14 +13,20 @@ def getPrintInformation(printer_name) -> PrintInformation:
|
|
|
mock_application = MagicMock()
|
|
|
|
|
|
global_container_stack = MagicMock()
|
|
|
- global_container_stack.definition.getName = MagicMock(return_value=printer_name)
|
|
|
- mock_application.getGlobalContainerStack = MagicMock(return_value=global_container_stack)
|
|
|
+ global_container_stack.definition.getName = MagicMock(return_value = printer_name)
|
|
|
+ mock_application.getGlobalContainerStack = MagicMock(return_value = global_container_stack)
|
|
|
|
|
|
- multiBuildPlateModel = MagicMock()
|
|
|
- multiBuildPlateModel.maxBuildPlate = 0
|
|
|
- mock_application.getMultiBuildPlateModel = MagicMock(return_value=multiBuildPlateModel)
|
|
|
+ multi_build_plate_model = MagicMock()
|
|
|
+ multi_build_plate_model.maxBuildPlate = 0
|
|
|
+ mock_application.getMultiBuildPlateModel = MagicMock(return_value = multi_build_plate_model)
|
|
|
|
|
|
- Application.getInstance = MagicMock(return_type=mock_application)
|
|
|
+ # Mock-up the entire machine manager except the function that needs to be tested: getAbbreviatedMachineName
|
|
|
+ original_get_abbreviated_name = MachineManager.getAbbreviatedMachineName
|
|
|
+ mock_machine_manager = MagicMock()
|
|
|
+ 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)
|
|
|
|
|
|
with patch("json.loads", lambda x: {}):
|
|
|
print_information = PrintInformation.PrintInformation(mock_application)
|
|
@@ -28,17 +36,17 @@ def getPrintInformation(printer_name) -> PrintInformation:
|
|
|
def setup_module():
|
|
|
MimeTypeDatabase.addMimeType(
|
|
|
MimeType(
|
|
|
- name="application/vnd.ms-package.3dmanufacturing-3dmodel+xml",
|
|
|
- comment="3MF",
|
|
|
- suffixes=["3mf"]
|
|
|
+ name = "application/vnd.ms-package.3dmanufacturing-3dmodel+xml",
|
|
|
+ comment = "3MF",
|
|
|
+ suffixes = ["3mf"]
|
|
|
)
|
|
|
)
|
|
|
|
|
|
MimeTypeDatabase.addMimeType(
|
|
|
MimeType(
|
|
|
- name="application/x-cura-gcode-file",
|
|
|
- comment="Cura GCode File",
|
|
|
- suffixes=["gcode"]
|
|
|
+ name = "application/x-cura-gcode-file",
|
|
|
+ comment = "Cura GCode File",
|
|
|
+ suffixes = ["gcode"]
|
|
|
)
|
|
|
)
|
|
|
|
|
@@ -49,42 +57,42 @@ def test_setProjectName():
|
|
|
print_information = getPrintInformation("ultimaker")
|
|
|
|
|
|
# Test simple name
|
|
|
- project_name = ["HelloWorld",".3mf"]
|
|
|
+ project_name = ["HelloWorld", ".3mf"]
|
|
|
print_information.setProjectName(project_name[0] + project_name[1])
|
|
|
assert "UM_" + project_name[0] == print_information._job_name
|
|
|
|
|
|
# Test the name with one dot
|
|
|
- project_name = ["Hello.World",".3mf"]
|
|
|
+ project_name = ["Hello.World", ".3mf"]
|
|
|
print_information.setProjectName(project_name[0] + project_name[1])
|
|
|
assert "UM_" + project_name[0] == print_information._job_name
|
|
|
|
|
|
# Test the name with two dot
|
|
|
- project_name = ["Hello.World.World",".3mf"]
|
|
|
+ project_name = ["Hello.World.World", ".3mf"]
|
|
|
print_information.setProjectName(project_name[0] + project_name[1])
|
|
|
assert "UM_" + project_name[0] == print_information._job_name
|
|
|
|
|
|
# Test the name with dot at the beginning
|
|
|
- project_name = [".Hello.World",".3mf"]
|
|
|
+ project_name = [".Hello.World", ".3mf"]
|
|
|
print_information.setProjectName(project_name[0] + project_name[1])
|
|
|
assert "UM_" + project_name[0] == print_information._job_name
|
|
|
|
|
|
# Test the name with underline
|
|
|
- project_name = ["Hello_World",".3mf"]
|
|
|
+ project_name = ["Hello_World", ".3mf"]
|
|
|
print_information.setProjectName(project_name[0] + project_name[1])
|
|
|
assert "UM_" + project_name[0] == print_information._job_name
|
|
|
|
|
|
# Test gcode extension
|
|
|
- project_name = ["Hello_World",".gcode"]
|
|
|
+ project_name = ["Hello_World", ".gcode"]
|
|
|
print_information.setProjectName(project_name[0] + project_name[1])
|
|
|
assert "UM_" + project_name[0] == print_information._job_name
|
|
|
|
|
|
# Test empty project name
|
|
|
- project_name = ["",""]
|
|
|
+ project_name = ["", ""]
|
|
|
print_information.setProjectName(project_name[0] + project_name[1])
|
|
|
assert print_information.UNTITLED_JOB_NAME == print_information._job_name
|
|
|
|
|
|
# Test wrong file extension
|
|
|
- project_name = ["Hello_World",".test"]
|
|
|
+ project_name = ["Hello_World", ".test"]
|
|
|
print_information.setProjectName(project_name[0] + project_name[1])
|
|
|
assert "UM_" + project_name[0] != print_information._job_name
|
|
|
|
|
@@ -93,7 +101,7 @@ def test_setJobName():
|
|
|
print_information = getPrintInformation("ultimaker")
|
|
|
|
|
|
print_information._abbr_machine = "UM"
|
|
|
- print_information.setJobName("UM_HelloWorld", is_user_specified_job_name=False)
|
|
|
+ print_information.setJobName("UM_HelloWorld", is_user_specified_job_name = False)
|
|
|
|
|
|
|
|
|
def test_defineAbbreviatedMachineName():
|
|
@@ -102,6 +110,6 @@ def test_defineAbbreviatedMachineName():
|
|
|
print_information = getPrintInformation(printer_name)
|
|
|
|
|
|
# Test not ultimaker printer, name suffix should have first letter from the printer name
|
|
|
- project_name = ["HelloWorld",".3mf"]
|
|
|
+ project_name = ["HelloWorld", ".3mf"]
|
|
|
print_information.setProjectName(project_name[0] + project_name[1])
|
|
|
assert printer_name[0] + "_" + project_name[0] == print_information._job_name
|