From d40a67f2b03b85a6211a2f09369a4dfe173ed5aa Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 24 Mar 2017 12:27:39 +0100 Subject: [PATCH] Add test for addExtruder This mainly tests if it is properly limited by the number of extruders setting. Contributes to issue CURA-3497. --- tests/Settings/TestGlobalStack.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/Settings/TestGlobalStack.py b/tests/Settings/TestGlobalStack.py index 277a7f69b1..cb64d78c2b 100644 --- a/tests/Settings/TestGlobalStack.py +++ b/tests/Settings/TestGlobalStack.py @@ -6,6 +6,7 @@ import pytest #This module contains unit tests. import unittest.mock #To monkeypatch some mocks in place of dependencies. import cura.Settings.GlobalStack #The module we're testing. +from cura.Settings.Exceptions import TooManyExtrudersError #To test raising this error. from UM.Settings.DefinitionContainer import DefinitionContainer #To test against the class DefinitionContainer. import UM.Settings.ContainerRegistry import UM.Settings.ContainerStack @@ -49,6 +50,18 @@ def readStack(filename): #############################START OF TEST CASES################################ +## Tests adding extruders to the global stack. +def test_addExtruder(global_stack): + mock_definition = unittest.mock.MagicMock() + mock_definition.getProperty = lambda key, property: 2 if key == "machine_extruder_count" and property == "value" else None + + global_stack.definition = mock_definition + + global_stack.addExtruder(unittest.mock.MagicMock()) + global_stack.addExtruder(unittest.mock.MagicMock()) + with pytest.raises(TooManyExtrudersError): + global_stack.addExtruder(unittest.mock.MagicMock()) + ## Tests whether the user changes are being read properly from a global stack. @pytest.mark.parametrize("filename, user_changes_id", [ ("Global.global.cfg", "empty"),