mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-11 06:08:58 +08:00
Fix unit tests that were failing after adding the getAbbreviatedMachineName to the machine manager.
Contributes to CURA-5942.
This commit is contained in:
parent
72d972c8b4
commit
ebae4347a8
@ -1,5 +1,7 @@
|
|||||||
|
import functools
|
||||||
|
|
||||||
from cura import PrintInformation
|
from cura import PrintInformation
|
||||||
|
from cura.Settings.MachineManager import MachineManager
|
||||||
|
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
from UM.Application import Application
|
from UM.Application import Application
|
||||||
@ -11,14 +13,20 @@ def getPrintInformation(printer_name) -> PrintInformation:
|
|||||||
mock_application = MagicMock()
|
mock_application = MagicMock()
|
||||||
|
|
||||||
global_container_stack = MagicMock()
|
global_container_stack = MagicMock()
|
||||||
global_container_stack.definition.getName = MagicMock(return_value=printer_name)
|
global_container_stack.definition.getName = MagicMock(return_value = printer_name)
|
||||||
mock_application.getGlobalContainerStack = MagicMock(return_value=global_container_stack)
|
mock_application.getGlobalContainerStack = MagicMock(return_value = global_container_stack)
|
||||||
|
|
||||||
multiBuildPlateModel = MagicMock()
|
multi_build_plate_model = MagicMock()
|
||||||
multiBuildPlateModel.maxBuildPlate = 0
|
multi_build_plate_model.maxBuildPlate = 0
|
||||||
mock_application.getMultiBuildPlateModel = MagicMock(return_value=multiBuildPlateModel)
|
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: {}):
|
with patch("json.loads", lambda x: {}):
|
||||||
print_information = PrintInformation.PrintInformation(mock_application)
|
print_information = PrintInformation.PrintInformation(mock_application)
|
||||||
@ -28,17 +36,17 @@ def getPrintInformation(printer_name) -> PrintInformation:
|
|||||||
def setup_module():
|
def setup_module():
|
||||||
MimeTypeDatabase.addMimeType(
|
MimeTypeDatabase.addMimeType(
|
||||||
MimeType(
|
MimeType(
|
||||||
name="application/vnd.ms-package.3dmanufacturing-3dmodel+xml",
|
name = "application/vnd.ms-package.3dmanufacturing-3dmodel+xml",
|
||||||
comment="3MF",
|
comment = "3MF",
|
||||||
suffixes=["3mf"]
|
suffixes = ["3mf"]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
MimeTypeDatabase.addMimeType(
|
MimeTypeDatabase.addMimeType(
|
||||||
MimeType(
|
MimeType(
|
||||||
name="application/x-cura-gcode-file",
|
name = "application/x-cura-gcode-file",
|
||||||
comment="Cura GCode File",
|
comment = "Cura GCode File",
|
||||||
suffixes=["gcode"]
|
suffixes = ["gcode"]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -49,42 +57,42 @@ def test_setProjectName():
|
|||||||
print_information = getPrintInformation("ultimaker")
|
print_information = getPrintInformation("ultimaker")
|
||||||
|
|
||||||
# Test simple name
|
# Test simple name
|
||||||
project_name = ["HelloWorld",".3mf"]
|
project_name = ["HelloWorld", ".3mf"]
|
||||||
print_information.setProjectName(project_name[0] + project_name[1])
|
print_information.setProjectName(project_name[0] + project_name[1])
|
||||||
assert "UM_" + project_name[0] == print_information._job_name
|
assert "UM_" + project_name[0] == print_information._job_name
|
||||||
|
|
||||||
# Test the name with one dot
|
# 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])
|
print_information.setProjectName(project_name[0] + project_name[1])
|
||||||
assert "UM_" + project_name[0] == print_information._job_name
|
assert "UM_" + project_name[0] == print_information._job_name
|
||||||
|
|
||||||
# Test the name with two dot
|
# 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])
|
print_information.setProjectName(project_name[0] + project_name[1])
|
||||||
assert "UM_" + project_name[0] == print_information._job_name
|
assert "UM_" + project_name[0] == print_information._job_name
|
||||||
|
|
||||||
# Test the name with dot at the beginning
|
# 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])
|
print_information.setProjectName(project_name[0] + project_name[1])
|
||||||
assert "UM_" + project_name[0] == print_information._job_name
|
assert "UM_" + project_name[0] == print_information._job_name
|
||||||
|
|
||||||
# Test the name with underline
|
# Test the name with underline
|
||||||
project_name = ["Hello_World",".3mf"]
|
project_name = ["Hello_World", ".3mf"]
|
||||||
print_information.setProjectName(project_name[0] + project_name[1])
|
print_information.setProjectName(project_name[0] + project_name[1])
|
||||||
assert "UM_" + project_name[0] == print_information._job_name
|
assert "UM_" + project_name[0] == print_information._job_name
|
||||||
|
|
||||||
# Test gcode extension
|
# Test gcode extension
|
||||||
project_name = ["Hello_World",".gcode"]
|
project_name = ["Hello_World", ".gcode"]
|
||||||
print_information.setProjectName(project_name[0] + project_name[1])
|
print_information.setProjectName(project_name[0] + project_name[1])
|
||||||
assert "UM_" + project_name[0] == print_information._job_name
|
assert "UM_" + project_name[0] == print_information._job_name
|
||||||
|
|
||||||
# Test empty project name
|
# Test empty project name
|
||||||
project_name = ["",""]
|
project_name = ["", ""]
|
||||||
print_information.setProjectName(project_name[0] + project_name[1])
|
print_information.setProjectName(project_name[0] + project_name[1])
|
||||||
assert print_information.UNTITLED_JOB_NAME == print_information._job_name
|
assert print_information.UNTITLED_JOB_NAME == print_information._job_name
|
||||||
|
|
||||||
# Test wrong file extension
|
# Test wrong file extension
|
||||||
project_name = ["Hello_World",".test"]
|
project_name = ["Hello_World", ".test"]
|
||||||
print_information.setProjectName(project_name[0] + project_name[1])
|
print_information.setProjectName(project_name[0] + project_name[1])
|
||||||
assert "UM_" + project_name[0] != print_information._job_name
|
assert "UM_" + project_name[0] != print_information._job_name
|
||||||
|
|
||||||
@ -93,7 +101,7 @@ def test_setJobName():
|
|||||||
print_information = getPrintInformation("ultimaker")
|
print_information = getPrintInformation("ultimaker")
|
||||||
|
|
||||||
print_information._abbr_machine = "UM"
|
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():
|
def test_defineAbbreviatedMachineName():
|
||||||
@ -102,6 +110,6 @@ def test_defineAbbreviatedMachineName():
|
|||||||
print_information = getPrintInformation(printer_name)
|
print_information = getPrintInformation(printer_name)
|
||||||
|
|
||||||
# Test not ultimaker printer, name suffix should have first letter from the 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])
|
print_information.setProjectName(project_name[0] + project_name[1])
|
||||||
assert printer_name[0] + "_" + project_name[0] == print_information._job_name
|
assert printer_name[0] + "_" + project_name[0] == print_information._job_name
|
Loading…
x
Reference in New Issue
Block a user