From 3967c995f167a328fde1afcb2654ee0b80308f5f Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Fri, 7 Jun 2019 16:42:51 +0200 Subject: [PATCH] Split out updating the machine size properties so it can be tested easily --- cura/BuildVolume.py | 14 +++++++++----- tests/TestBuildVolume.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/cura/BuildVolume.py b/cura/BuildVolume.py index 71eac5088a..2300cb591c 100755 --- a/cura/BuildVolume.py +++ b/cura/BuildVolume.py @@ -651,14 +651,10 @@ class BuildVolume(SceneNode): self._height = self._global_container_stack.getProperty("machine_height", "value") self._build_volume_message.hide() update_disallowed_areas = True - rebuild_me = True # sometimes the machine size or shape settings are adjusted on the active machine, we should reflect this if setting_key in self._machine_settings: - self._height = self._global_container_stack.getProperty("machine_height", "value") - self._width = self._global_container_stack.getProperty("machine_width", "value") - self._depth = self._global_container_stack.getProperty("machine_depth", "value") - self._shape = self._global_container_stack.getProperty("machine_shape", "value") + self._updateMachineSizeProperties() update_extra_z_clearance = True update_disallowed_areas = True @@ -703,6 +699,14 @@ class BuildVolume(SceneNode): def hasErrors(self) -> bool: return self._has_errors + def _updateMachineSizeProperties(self) -> None: + if not self._global_container_stack: + return + self._height = self._global_container_stack.getProperty("machine_height", "value") + self._width = self._global_container_stack.getProperty("machine_width", "value") + self._depth = self._global_container_stack.getProperty("machine_depth", "value") + self._shape = self._global_container_stack.getProperty("machine_shape", "value") + ## Calls _updateDisallowedAreas and makes sure the changes appear in the # scene. # diff --git a/tests/TestBuildVolume.py b/tests/TestBuildVolume.py index 709c481443..9f067f2c3b 100644 --- a/tests/TestBuildVolume.py +++ b/tests/TestBuildVolume.py @@ -201,3 +201,32 @@ class TestRebuild: build_volume.rebuild() assert build_volume.getMeshData() is None + + +class TestUpdateMachineSizeProperties: + setting_property_dict = {"machine_width": {"value": 50}, + "machine_depth": {"value": 100}, + "machine_height": {"value": 200}, + "machine_shape": {"value": "DERP!"}} + + def getPropertySideEffect(*args, **kwargs): + properties = TestUpdateMachineSizeProperties.setting_property_dict.get(args[1]) + if properties: + return properties.get(args[2]) + + def test_noGlobalStack(self, build_volume: BuildVolume): + build_volume._updateMachineSizeProperties() + assert build_volume._width == 0 + assert build_volume._height == 0 + assert build_volume._depth == 0 + assert build_volume._shape == "" + + def test_happy(self, build_volume: BuildVolume): + mocked_global_stack = MagicMock(name="mocked_global_stack") + mocked_global_stack.getProperty = MagicMock(side_effect=self.getPropertySideEffect) + build_volume._global_container_stack = mocked_global_stack + build_volume._updateMachineSizeProperties() + assert build_volume._width == 50 + assert build_volume._height == 200 + assert build_volume._depth == 100 + assert build_volume._shape == "DERP!" \ No newline at end of file