Merge branch 'master' of github.com:Ultimaker/Cura into CURA-7038

This commit is contained in:
Dimitriovski 2019-12-30 17:38:31 +01:00
commit ea1896fe6b
No known key found for this signature in database
GPG Key ID: 4E62757E2B0D304D
11 changed files with 88 additions and 40 deletions

View File

@ -508,14 +508,14 @@ class CuraApplication(QtApplication):
self.getController().contextMenuRequested.connect(self._onContextMenuRequested) self.getController().contextMenuRequested.connect(self._onContextMenuRequested)
self.getCuraSceneController().activeBuildPlateChanged.connect(self.updatePlatformActivityDelayed) self.getCuraSceneController().activeBuildPlateChanged.connect(self.updatePlatformActivityDelayed)
self.showSplashMessage(self._i18n_catalog.i18nc("@info:progress", "Loading machines...")) self._setLoadingHint(self._i18n_catalog.i18nc("@info:progress", "Loading machines..."))
self._container_registry.allMetadataLoaded.connect(ContainerRegistry.getInstance) self._container_registry.allMetadataLoaded.connect(ContainerRegistry.getInstance)
with self._container_registry.lockFile(): with self._container_registry.lockFile():
self._container_registry.loadAllMetadata() self._container_registry.loadAllMetadata()
self.showSplashMessage(self._i18n_catalog.i18nc("@info:progress", "Setting up preferences...")) self._setLoadingHint(self._i18n_catalog.i18nc("@info:progress", "Setting up preferences..."))
# Set the setting version for Preferences # Set the setting version for Preferences
preferences = self.getPreferences() preferences = self.getPreferences()
preferences.addPreference("metadata/setting_version", 0) preferences.addPreference("metadata/setting_version", 0)
@ -637,6 +637,7 @@ class CuraApplication(QtApplication):
@override(Application) @override(Application)
def setGlobalContainerStack(self, stack: "GlobalStack") -> None: def setGlobalContainerStack(self, stack: "GlobalStack") -> None:
self._setLoadingHint(self._i18n_catalog.i18nc("@info:progress", "Initializing Active Machine..."))
super().setGlobalContainerStack(stack) super().setGlobalContainerStack(stack)
## A reusable dialogbox ## A reusable dialogbox
@ -741,18 +742,30 @@ class CuraApplication(QtApplication):
self._plugins_loaded = True self._plugins_loaded = True
## Set a short, user-friendly hint about current loading status.
# The way this message is displayed depends on application state
def _setLoadingHint(self, hint: str):
if self.started:
Logger.info(hint)
else:
self.showSplashMessage(hint)
def run(self): def run(self):
super().run() super().run()
Logger.log("i", "Initializing machine manager") Logger.log("i", "Initializing machine manager")
self._setLoadingHint(self._i18n_catalog.i18nc("@info:progress", "Initializing machine manager..."))
self._machine_manager = MachineManager(self, parent = self) self._machine_manager = MachineManager(self, parent = self)
self.processEvents()
Logger.log("i", "Initializing container manager") Logger.log("i", "Initializing container manager")
self._container_manager = ContainerManager(self) self._container_manager = ContainerManager(self)
self.processEvents()
Logger.log("i", "Initializing machine error checker") Logger.log("i", "Initializing machine error checker")
self._machine_error_checker = MachineErrorChecker(self) self._machine_error_checker = MachineErrorChecker(self)
self._machine_error_checker.initialize() self._machine_error_checker.initialize()
self.processEvents()
# Check if we should run as single instance or not. If so, set up a local socket server which listener which # Check if we should run as single instance or not. If so, set up a local socket server which listener which
# coordinates multiple Cura instances and accepts commands. # coordinates multiple Cura instances and accepts commands.
@ -760,6 +773,7 @@ class CuraApplication(QtApplication):
self.__setUpSingleInstanceServer() self.__setUpSingleInstanceServer()
# Setup scene and build volume # Setup scene and build volume
self._setLoadingHint(self._i18n_catalog.i18nc("@info:progress", "Initializing build volume..."))
root = self.getController().getScene().getRoot() root = self.getController().getScene().getRoot()
self._volume = BuildVolume.BuildVolume(self, root) self._volume = BuildVolume.BuildVolume(self, root)
Arrange.build_volume = self._volume Arrange.build_volume = self._volume
@ -767,13 +781,13 @@ class CuraApplication(QtApplication):
# initialize info objects # initialize info objects
self._print_information = PrintInformation.PrintInformation(self) self._print_information = PrintInformation.PrintInformation(self)
self._cura_actions = CuraActions.CuraActions(self) self._cura_actions = CuraActions.CuraActions(self)
self.processEvents()
# Initialize setting visibility presets model. # Initialize setting visibility presets model.
self._setting_visibility_presets_model = SettingVisibilityPresetsModel(self.getPreferences(), parent = self) self._setting_visibility_presets_model = SettingVisibilityPresetsModel(self.getPreferences(), parent = self)
# Initialize Cura API # Initialize Cura API
self._cura_API.initialize() self._cura_API.initialize()
self.processEvents()
self._output_device_manager.start() self._output_device_manager.start()
self._welcome_pages_model.initialize() self._welcome_pages_model.initialize()
self._add_printer_pages_model.initialize() self._add_printer_pages_model.initialize()
@ -821,7 +835,7 @@ class CuraApplication(QtApplication):
## Run Cura with GUI (desktop mode). ## Run Cura with GUI (desktop mode).
def runWithGUI(self): def runWithGUI(self):
self.showSplashMessage(self._i18n_catalog.i18nc("@info:progress", "Setting up scene...")) self._setLoadingHint(self._i18n_catalog.i18nc("@info:progress", "Setting up scene..."))
controller = self.getController() controller = self.getController()
@ -833,7 +847,7 @@ class CuraApplication(QtApplication):
# Set default background color for scene # Set default background color for scene
self.getRenderer().setBackgroundColor(QColor(245, 245, 245)) self.getRenderer().setBackgroundColor(QColor(245, 245, 245))
self.processEvents()
# Initialize platform physics # Initialize platform physics
self._physics = PlatformPhysics.PlatformPhysics(controller, self._volume) self._physics = PlatformPhysics.PlatformPhysics(controller, self._volume)
@ -856,11 +870,12 @@ class CuraApplication(QtApplication):
self._camera_animation = CameraAnimation.CameraAnimation() self._camera_animation = CameraAnimation.CameraAnimation()
self._camera_animation.setCameraTool(self.getController().getTool("CameraTool")) self._camera_animation.setCameraTool(self.getController().getTool("CameraTool"))
self.showSplashMessage(self._i18n_catalog.i18nc("@info:progress", "Loading interface...")) self._setLoadingHint(self._i18n_catalog.i18nc("@info:progress", "Loading interface..."))
# Initialize QML engine # Initialize QML engine
self.setMainQml(Resources.getPath(self.ResourceTypes.QmlFiles, "Cura.qml")) self.setMainQml(Resources.getPath(self.ResourceTypes.QmlFiles, "Cura.qml"))
self._qml_import_paths.append(Resources.getPath(self.ResourceTypes.QmlFiles)) self._qml_import_paths.append(Resources.getPath(self.ResourceTypes.QmlFiles))
self._setLoadingHint(self._i18n_catalog.i18nc("@info:progress", "Initializing engine..."))
self.initializeEngine() self.initializeEngine()
# Initialize UI state # Initialize UI state
@ -1029,14 +1044,17 @@ class CuraApplication(QtApplication):
super().registerObjects(engine) super().registerObjects(engine)
# global contexts # global contexts
self.processEvents()
engine.rootContext().setContextProperty("Printer", self) engine.rootContext().setContextProperty("Printer", self)
engine.rootContext().setContextProperty("CuraApplication", self) engine.rootContext().setContextProperty("CuraApplication", self)
engine.rootContext().setContextProperty("PrintInformation", self._print_information) engine.rootContext().setContextProperty("PrintInformation", self._print_information)
engine.rootContext().setContextProperty("CuraActions", self._cura_actions) engine.rootContext().setContextProperty("CuraActions", self._cura_actions)
engine.rootContext().setContextProperty("CuraSDKVersion", ApplicationMetadata.CuraSDKVersion) engine.rootContext().setContextProperty("CuraSDKVersion", ApplicationMetadata.CuraSDKVersion)
self.processEvents()
qmlRegisterUncreatableType(CuraApplication, "Cura", 1, 0, "ResourceTypes", "Just an Enum type") qmlRegisterUncreatableType(CuraApplication, "Cura", 1, 0, "ResourceTypes", "Just an Enum type")
self.processEvents()
qmlRegisterSingletonType(CuraSceneController, "Cura", 1, 0, "SceneController", self.getCuraSceneController) qmlRegisterSingletonType(CuraSceneController, "Cura", 1, 0, "SceneController", self.getCuraSceneController)
qmlRegisterSingletonType(ExtruderManager, "Cura", 1, 0, "ExtruderManager", self.getExtruderManager) qmlRegisterSingletonType(ExtruderManager, "Cura", 1, 0, "ExtruderManager", self.getExtruderManager)
qmlRegisterSingletonType(MachineManager, "Cura", 1, 0, "MachineManager", self.getMachineManager) qmlRegisterSingletonType(MachineManager, "Cura", 1, 0, "MachineManager", self.getMachineManager)
@ -1045,16 +1063,16 @@ class CuraApplication(QtApplication):
qmlRegisterSingletonType(SimpleModeSettingsManager, "Cura", 1, 0, "SimpleModeSettingsManager", self.getSimpleModeSettingsManager) qmlRegisterSingletonType(SimpleModeSettingsManager, "Cura", 1, 0, "SimpleModeSettingsManager", self.getSimpleModeSettingsManager)
qmlRegisterSingletonType(MachineActionManager.MachineActionManager, "Cura", 1, 0, "MachineActionManager", self.getMachineActionManager) qmlRegisterSingletonType(MachineActionManager.MachineActionManager, "Cura", 1, 0, "MachineActionManager", self.getMachineActionManager)
self.processEvents()
qmlRegisterType(NetworkingUtil, "Cura", 1, 5, "NetworkingUtil") qmlRegisterType(NetworkingUtil, "Cura", 1, 5, "NetworkingUtil")
qmlRegisterType(WelcomePagesModel, "Cura", 1, 0, "WelcomePagesModel") qmlRegisterType(WelcomePagesModel, "Cura", 1, 0, "WelcomePagesModel")
qmlRegisterType(WhatsNewPagesModel, "Cura", 1, 0, "WhatsNewPagesModel") qmlRegisterType(WhatsNewPagesModel, "Cura", 1, 0, "WhatsNewPagesModel")
qmlRegisterType(AddPrinterPagesModel, "Cura", 1, 0, "AddPrinterPagesModel") qmlRegisterType(AddPrinterPagesModel, "Cura", 1, 0, "AddPrinterPagesModel")
qmlRegisterType(TextManager, "Cura", 1, 0, "TextManager") qmlRegisterType(TextManager, "Cura", 1, 0, "TextManager")
qmlRegisterType(RecommendedMode, "Cura", 1, 0, "RecommendedMode") qmlRegisterType(RecommendedMode, "Cura", 1, 0, "RecommendedMode")
self.processEvents()
qmlRegisterType(NetworkMJPGImage, "Cura", 1, 0, "NetworkMJPGImage") qmlRegisterType(NetworkMJPGImage, "Cura", 1, 0, "NetworkMJPGImage")
qmlRegisterType(ObjectsModel, "Cura", 1, 0, "ObjectsModel") qmlRegisterType(ObjectsModel, "Cura", 1, 0, "ObjectsModel")
qmlRegisterType(BuildPlateModel, "Cura", 1, 0, "BuildPlateModel") qmlRegisterType(BuildPlateModel, "Cura", 1, 0, "BuildPlateModel")
qmlRegisterType(MultiBuildPlateModel, "Cura", 1, 0, "MultiBuildPlateModel") qmlRegisterType(MultiBuildPlateModel, "Cura", 1, 0, "MultiBuildPlateModel")
@ -1062,14 +1080,15 @@ class CuraApplication(QtApplication):
qmlRegisterType(ExtrudersModel, "Cura", 1, 0, "ExtrudersModel") qmlRegisterType(ExtrudersModel, "Cura", 1, 0, "ExtrudersModel")
qmlRegisterType(GlobalStacksModel, "Cura", 1, 0, "GlobalStacksModel") qmlRegisterType(GlobalStacksModel, "Cura", 1, 0, "GlobalStacksModel")
self.processEvents()
qmlRegisterType(FavoriteMaterialsModel, "Cura", 1, 0, "FavoriteMaterialsModel") qmlRegisterType(FavoriteMaterialsModel, "Cura", 1, 0, "FavoriteMaterialsModel")
qmlRegisterType(GenericMaterialsModel, "Cura", 1, 0, "GenericMaterialsModel") qmlRegisterType(GenericMaterialsModel, "Cura", 1, 0, "GenericMaterialsModel")
qmlRegisterType(MaterialBrandsModel, "Cura", 1, 0, "MaterialBrandsModel") qmlRegisterType(MaterialBrandsModel, "Cura", 1, 0, "MaterialBrandsModel")
qmlRegisterSingletonType(QualityManagementModel, "Cura", 1, 0, "QualityManagementModel", self.getQualityManagementModel) qmlRegisterSingletonType(QualityManagementModel, "Cura", 1, 0, "QualityManagementModel", self.getQualityManagementModel)
qmlRegisterSingletonType(MaterialManagementModel, "Cura", 1, 5, "MaterialManagementModel", self.getMaterialManagementModel) qmlRegisterSingletonType(MaterialManagementModel, "Cura", 1, 5, "MaterialManagementModel", self.getMaterialManagementModel)
self.processEvents()
qmlRegisterType(DiscoveredPrintersModel, "Cura", 1, 0, "DiscoveredPrintersModel") qmlRegisterType(DiscoveredPrintersModel, "Cura", 1, 0, "DiscoveredPrintersModel")
qmlRegisterSingletonType(QualityProfilesDropDownMenuModel, "Cura", 1, 0, qmlRegisterSingletonType(QualityProfilesDropDownMenuModel, "Cura", 1, 0,
"QualityProfilesDropDownMenuModel", self.getQualityProfilesDropDownMenuModel) "QualityProfilesDropDownMenuModel", self.getQualityProfilesDropDownMenuModel)
qmlRegisterSingletonType(CustomQualityProfilesDropDownMenuModel, "Cura", 1, 0, qmlRegisterSingletonType(CustomQualityProfilesDropDownMenuModel, "Cura", 1, 0,
@ -1078,6 +1097,7 @@ class CuraApplication(QtApplication):
qmlRegisterType(IntentModel, "Cura", 1, 6, "IntentModel") qmlRegisterType(IntentModel, "Cura", 1, 6, "IntentModel")
qmlRegisterType(IntentCategoryModel, "Cura", 1, 6, "IntentCategoryModel") qmlRegisterType(IntentCategoryModel, "Cura", 1, 6, "IntentCategoryModel")
self.processEvents()
qmlRegisterType(MaterialSettingsVisibilityHandler, "Cura", 1, 0, "MaterialSettingsVisibilityHandler") qmlRegisterType(MaterialSettingsVisibilityHandler, "Cura", 1, 0, "MaterialSettingsVisibilityHandler")
qmlRegisterType(SettingVisibilityPresetsModel, "Cura", 1, 0, "SettingVisibilityPresetsModel") qmlRegisterType(SettingVisibilityPresetsModel, "Cura", 1, 0, "SettingVisibilityPresetsModel")
qmlRegisterType(QualitySettingsModel, "Cura", 1, 0, "QualitySettingsModel") qmlRegisterType(QualitySettingsModel, "Cura", 1, 0, "QualitySettingsModel")
@ -1106,6 +1126,7 @@ class CuraApplication(QtApplication):
continue continue
qmlRegisterType(QUrl.fromLocalFile(path), "Cura", 1, 0, type_name) qmlRegisterType(QUrl.fromLocalFile(path), "Cura", 1, 0, type_name)
self.processEvents()
def onSelectionChanged(self): def onSelectionChanged(self):
if Selection.hasSelection(): if Selection.hasSelection():

View File

@ -9,6 +9,7 @@ from UM.Resources import Resources
from UM.Application import Application from UM.Application import Application
from cura import ApplicationMetadata from cura import ApplicationMetadata
import time
class CuraSplashScreen(QSplashScreen): class CuraSplashScreen(QSplashScreen):
def __init__(self): def __init__(self):
@ -34,15 +35,20 @@ class CuraSplashScreen(QSplashScreen):
self._change_timer.setSingleShot(False) self._change_timer.setSingleShot(False)
self._change_timer.timeout.connect(self.updateLoadingImage) self._change_timer.timeout.connect(self.updateLoadingImage)
self._last_update_time = None
def show(self): def show(self):
super().show() super().show()
self._last_update_time = time.time()
self._change_timer.start() self._change_timer.start()
def updateLoadingImage(self): def updateLoadingImage(self):
if self._to_stop: if self._to_stop:
return return
time_since_last_update = time.time() - self._last_update_time
self._loading_image_rotation_angle -= 10 self._last_update_time = time.time()
# Since we don't know how much time actually passed, check how many intervals of 50 we had.
self._loading_image_rotation_angle -= 10 * (time_since_last_update * 1000 / 50)
self.repaint() self.repaint()
# Override the mousePressEvent so the splashscreen doesn't disappear when clicked # Override the mousePressEvent so the splashscreen doesn't disappear when clicked

View File

@ -750,7 +750,11 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
quality_changes_info = self._machine_info.quality_changes_info quality_changes_info = self._machine_info.quality_changes_info
quality_changes_quality_type = quality_changes_info.global_info.parser["metadata"]["quality_type"] quality_changes_quality_type = quality_changes_info.global_info.parser["metadata"]["quality_type"]
quality_changes_intent_category_per_extruder = {position: info.parser["metadata"].get("intent_category", "default") for position, info in quality_changes_info.extruder_info_dict.items()}
# quality changes container may not be present for every extruder. Prepopulate the dict with default values.
quality_changes_intent_category_per_extruder = {position: "default" for position in self._machine_info.extruder_info_dict}
for position, info in quality_changes_info.extruder_info_dict.items():
quality_changes_intent_category_per_extruder[position] = info.parser["metadata"].get("intent_category", "default")
quality_changes_name = quality_changes_info.name quality_changes_name = quality_changes_info.name
create_new = self._resolve_strategies.get("quality_changes") != "override" create_new = self._resolve_strategies.get("quality_changes") != "override"

View File

@ -5860,6 +5860,7 @@
"description": "Ignore the internal geometry arising from overlapping volumes within a mesh and print the volumes as one. This may cause unintended internal cavities to disappear.", "description": "Ignore the internal geometry arising from overlapping volumes within a mesh and print the volumes as one. This may cause unintended internal cavities to disappear.",
"type": "bool", "type": "bool",
"default_value": true, "default_value": true,
"value": "magic_mesh_surface_mode != 'surface'",
"settable_per_mesh": true "settable_per_mesh": true
}, },
"meshfix_union_all_remove_holes": "meshfix_union_all_remove_holes":

View File

@ -17,7 +17,12 @@
"minimum_value": "0" "minimum_value": "0"
}, },
"material_bed_temperature": { "material_bed_temperature": {
"minimum_value": "0" "minimum_value": "0",
"maximum_value_warning": "125"
},
"material_bed_temperature_layer_0":
{
"maximum_value_warning": "125"
}, },
"material_standby_temperature": { "material_standby_temperature": {
"minimum_value": "0" "minimum_value": "0"

View File

@ -1,4 +1,4 @@
from unittest.mock import MagicMock from unittest.mock import MagicMock, patch
import pytest import pytest
@ -14,6 +14,7 @@ def user_profile():
result.user_id = "user_id!" result.user_id = "user_id!"
return result return result
def test_login(): def test_login():
account = Account(MagicMock()) account = Account(MagicMock())
mocked_auth_service = MagicMock() mocked_auth_service = MagicMock()
@ -55,8 +56,8 @@ def test_logout():
account.logout() account.logout()
mocked_auth_service.deleteAuthData.assert_called_once_with() mocked_auth_service.deleteAuthData.assert_called_once_with()
@patch("UM.Application.Application.getInstance")
def test_errorLoginState(): def test_errorLoginState(application):
account = Account(MagicMock()) account = Account(MagicMock())
mocked_auth_service = MagicMock() mocked_auth_service = MagicMock()
account._authorization_service = mocked_auth_service account._authorization_service = mocked_auth_service

View File

@ -14,6 +14,7 @@ def discovered_printer() -> DiscoveredPrinter:
return DiscoveredPrinter("127.0.0.1", "zomg", "yay", None, "bleep", MagicMock()) return DiscoveredPrinter("127.0.0.1", "zomg", "yay", None, "bleep", MagicMock())
@pytest.mark.skip # TODO: This has some unknown dependency on the applicaiton / registry, which is hard to patch out. (which doesn't mean we shouldn't fix it!)
def test_discoveredPrinters(discovered_printer_model): def test_discoveredPrinters(discovered_printer_model):
mocked_device = MagicMock() mocked_device = MagicMock()
cluster_size = PropertyMock(return_value = 1) cluster_size = PropertyMock(return_value = 1)
@ -36,6 +37,7 @@ def test_discoveredPrinters(discovered_printer_model):
discovered_printer_model.removeDiscoveredPrinter("ip") discovered_printer_model.removeDiscoveredPrinter("ip")
assert discovered_printer_model.discoveredPrintersChanged.emit.call_count == 1 assert discovered_printer_model.discoveredPrintersChanged.emit.call_count == 1
test_validate_data_get_set = [ test_validate_data_get_set = [
{"attribute": "name", "value": "zomg"}, {"attribute": "name", "value": "zomg"},
{"attribute": "machineType", "value": "BHDHAHHADAD"}, {"attribute": "machineType", "value": "BHDHAHHADAD"},

View File

@ -39,11 +39,13 @@ def application():
def test_containerTreeInit(container_registry): def test_containerTreeInit(container_registry):
with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value = container_registry)): with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value = container_registry)):
with patch("UM.Application.Application.getInstance"):
container_tree = ContainerTree() container_tree = ContainerTree()
assert "machine_1" in container_tree.machines assert "machine_1" in container_tree.machines
assert "machine_2" in container_tree.machines assert "machine_2" in container_tree.machines
def test_getCurrentQualityGroupsNoGlobalStack(container_registry): def test_getCurrentQualityGroupsNoGlobalStack(container_registry):
with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value = container_registry)): with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value = container_registry)):
with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value = MagicMock(getGlobalContainerStack = MagicMock(return_value = None)))): with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value = MagicMock(getGlobalContainerStack = MagicMock(return_value = None)))):
@ -52,12 +54,12 @@ def test_getCurrentQualityGroupsNoGlobalStack(container_registry):
assert len(result) == 0 assert len(result) == 0
def test_getCurrentQualityGroups(container_registry, application): def test_getCurrentQualityGroups(container_registry, application):
with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value = container_registry)): with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value = container_registry)):
with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value=application)):
container_tree = ContainerTree() container_tree = ContainerTree()
container_tree.machines._machines["current_global_stack"] = MagicMock() # Mock so that we can track whether the getQualityGroups function gets called with correct parameters. container_tree.machines._machines["current_global_stack"] = MagicMock() # Mock so that we can track whether the getQualityGroups function gets called with correct parameters.
with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value = application)):
result = container_tree.getCurrentQualityGroups() result = container_tree.getCurrentQualityGroups()
# As defined in the fixture for application. # As defined in the fixture for application.
@ -68,6 +70,7 @@ def test_getCurrentQualityGroups(container_registry, application):
container_tree.machines["current_global_stack"].getQualityGroups.assert_called_with(expected_variant_names, expected_material_base_files, expected_is_enabled) container_tree.machines["current_global_stack"].getQualityGroups.assert_called_with(expected_variant_names, expected_material_base_files, expected_is_enabled)
assert result == container_tree.machines["current_global_stack"].getQualityGroups.return_value assert result == container_tree.machines["current_global_stack"].getQualityGroups.return_value
def test_getCurrentQualityChangesGroupsNoGlobalStack(container_registry): def test_getCurrentQualityChangesGroupsNoGlobalStack(container_registry):
with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value = container_registry)): with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value = container_registry)):
with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value = MagicMock(getGlobalContainerStack = MagicMock(return_value = None)))): with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value = MagicMock(getGlobalContainerStack = MagicMock(return_value = None)))):
@ -76,12 +79,12 @@ def test_getCurrentQualityChangesGroupsNoGlobalStack(container_registry):
assert len(result) == 0 assert len(result) == 0
def test_getCurrentQualityChangesGroups(container_registry, application): def test_getCurrentQualityChangesGroups(container_registry, application):
with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value = container_registry)): with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value = container_registry)):
with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value=application)):
container_tree = ContainerTree() container_tree = ContainerTree()
container_tree.machines._machines["current_global_stack"] = MagicMock() # Mock so that we can track whether the getQualityGroups function gets called with correct parameters. container_tree.machines._machines["current_global_stack"] = MagicMock() # Mock so that we can track whether the getQualityGroups function gets called with correct parameters.
with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value = application)):
result = container_tree.getCurrentQualityChangesGroups() result = container_tree.getCurrentQualityChangesGroups()
# As defined in the fixture for application. # As defined in the fixture for application.

View File

@ -1,5 +1,5 @@
import time import time
from unittest.mock import MagicMock from unittest.mock import MagicMock, patch
from PyQt5.QtNetwork import QNetworkAccessManager from PyQt5.QtNetwork import QNetworkAccessManager
from PyQt5.QtCore import QUrl from PyQt5.QtCore import QUrl
@ -9,7 +9,7 @@ from cura.PrinterOutput.PrinterOutputDevice import ConnectionState
def test_properties(): def test_properties():
properties = { b"firmware_version": b"12", b"printer_type": b"BHDHAHHADAD", b"address": b"ZOMG", b"name": b":(", b"testProp": b"zomg"} properties = { b"firmware_version": b"12", b"printer_type": b"BHDHAHHADAD", b"address": b"ZOMG", b"name": b":(", b"testProp": b"zomg"}
with patch("UM.Qt.QtApplication.QtApplication.getInstance"):
output_device = NetworkedPrinterOutputDevice(device_id = "test", address = "127.0.0.1", properties = properties) output_device = NetworkedPrinterOutputDevice(device_id = "test", address = "127.0.0.1", properties = properties)
assert output_device.address == "ZOMG" assert output_device.address == "ZOMG"
assert output_device.firmwareVersion == "12" assert output_device.firmwareVersion == "12"
@ -24,6 +24,7 @@ def test_properties():
def test_authenticationState(): def test_authenticationState():
with patch("UM.Qt.QtApplication.QtApplication.getInstance"):
output_device = NetworkedPrinterOutputDevice(device_id="test", address="127.0.0.1", properties={}) output_device = NetworkedPrinterOutputDevice(device_id="test", address="127.0.0.1", properties={})
output_device.setAuthenticationState(AuthState.Authenticated) output_device.setAuthenticationState(AuthState.Authenticated)
@ -32,6 +33,7 @@ def test_authenticationState():
def test_post(): def test_post():
with patch("UM.Qt.QtApplication.QtApplication.getInstance"):
output_device = NetworkedPrinterOutputDevice(device_id="test", address="127.0.0.1", properties={}) output_device = NetworkedPrinterOutputDevice(device_id="test", address="127.0.0.1", properties={})
mocked_network_manager = MagicMock() mocked_network_manager = MagicMock()
output_device._manager = mocked_network_manager output_device._manager = mocked_network_manager
@ -53,6 +55,7 @@ def test_post():
def test_get(): def test_get():
with patch("UM.Qt.QtApplication.QtApplication.getInstance"):
output_device = NetworkedPrinterOutputDevice(device_id="test", address="127.0.0.1", properties={}) output_device = NetworkedPrinterOutputDevice(device_id="test", address="127.0.0.1", properties={})
mocked_network_manager = MagicMock() mocked_network_manager = MagicMock()
output_device._manager = mocked_network_manager output_device._manager = mocked_network_manager
@ -74,6 +77,7 @@ def test_get():
def test_delete(): def test_delete():
with patch("UM.Qt.QtApplication.QtApplication.getInstance"):
output_device = NetworkedPrinterOutputDevice(device_id="test", address="127.0.0.1", properties={}) output_device = NetworkedPrinterOutputDevice(device_id="test", address="127.0.0.1", properties={})
mocked_network_manager = MagicMock() mocked_network_manager = MagicMock()
output_device._manager = mocked_network_manager output_device._manager = mocked_network_manager
@ -95,6 +99,7 @@ def test_delete():
def test_put(): def test_put():
with patch("UM.Qt.QtApplication.QtApplication.getInstance"):
output_device = NetworkedPrinterOutputDevice(device_id="test", address="127.0.0.1", properties={}) output_device = NetworkedPrinterOutputDevice(device_id="test", address="127.0.0.1", properties={})
mocked_network_manager = MagicMock() mocked_network_manager = MagicMock()
output_device._manager = mocked_network_manager output_device._manager = mocked_network_manager
@ -116,6 +121,7 @@ def test_put():
def test_timeout(): def test_timeout():
with patch("UM.Qt.QtApplication.QtApplication.getInstance"):
output_device = NetworkedPrinterOutputDevice(device_id="test", address="127.0.0.1", properties={}) output_device = NetworkedPrinterOutputDevice(device_id="test", address="127.0.0.1", properties={})
output_device.setConnectionState(ConnectionState.Connected) output_device.setConnectionState(ConnectionState.Connected)

View File

@ -37,8 +37,7 @@ def getPrintInformation(printer_name) -> PrintInformation:
mock_machine_manager = MagicMock() mock_machine_manager = MagicMock()
mock_machine_manager.getAbbreviatedMachineName = functools.partial(original_get_abbreviated_name, mock_machine_manager) mock_machine_manager.getAbbreviatedMachineName = functools.partial(original_get_abbreviated_name, mock_machine_manager)
mock_application.getMachineManager = MagicMock(return_value = mock_machine_manager) mock_application.getMachineManager = MagicMock(return_value = mock_machine_manager)
with patch("UM.Application.Application.getInstance", MagicMock(return_value = mock_application)):
Application.getInstance = MagicMock(return_value = 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)