From 8506c210996657f7a099e4f51c78a5975136ac84 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 6 Apr 2017 16:30:04 +0200 Subject: [PATCH] Replace DefinitionContainer with MagicMock in test_addExtruder Because the code checks for the type of DefinitionContainer. Contributes to issue CURA-3497. --- tests/Settings/TestGlobalStack.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/Settings/TestGlobalStack.py b/tests/Settings/TestGlobalStack.py index 1ca5c8c956..c501e6aee0 100644 --- a/tests/Settings/TestGlobalStack.py +++ b/tests/Settings/TestGlobalStack.py @@ -132,19 +132,23 @@ 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 + with unittest.mock.patch("cura.Settings.CuraContainerStack.DefinitionContainer", unittest.mock.MagicMock): + global_stack.definition = mock_definition assert len(global_stack.extruders) == 0 first_extruder = unittest.mock.MagicMock() - global_stack.addExtruder(first_extruder) + with unittest.mock.patch("cura.Settings.CuraContainerStack.DefinitionContainer", unittest.mock.MagicMock): + global_stack.addExtruder(first_extruder) assert len(global_stack.extruders) == 1 assert global_stack.extruders[0] == first_extruder second_extruder = unittest.mock.MagicMock() - global_stack.addExtruder(second_extruder) + with unittest.mock.patch("cura.Settings.CuraContainerStack.DefinitionContainer", unittest.mock.MagicMock): + global_stack.addExtruder(second_extruder) assert len(global_stack.extruders) == 2 assert global_stack.extruders[1] == second_extruder - with pytest.raises(TooManyExtrudersError): #Should be limited to 2 extruders because of machine_extruder_count. - global_stack.addExtruder(unittest.mock.MagicMock()) + with unittest.mock.patch("cura.Settings.CuraContainerStack.DefinitionContainer", unittest.mock.MagicMock): + with pytest.raises(TooManyExtrudersError): #Should be limited to 2 extruders because of machine_extruder_count. + global_stack.addExtruder(unittest.mock.MagicMock()) assert len(global_stack.extruders) == 2 #Didn't add the faulty extruder. ## Tests whether the container types are properly enforced on the stack.