From ba43b835f4a6806d6f41364cc3db877bc1d5adbf Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Wed, 22 Mar 2017 17:10:04 +0100 Subject: [PATCH] Move reading the stack file to a separate function That whole os.path stuff is a bit opaque. Now it's separated from the actual test. Contributes to issue CURA-3497. --- tests/Settings/TestGlobalStack.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/Settings/TestGlobalStack.py b/tests/Settings/TestGlobalStack.py index 70d4b44964..169cf12e83 100644 --- a/tests/Settings/TestGlobalStack.py +++ b/tests/Settings/TestGlobalStack.py @@ -30,6 +30,16 @@ def findSomeContainers(container_id = "*", container_type = None, type = None, c if container_type == DefinitionContainer: return unittest.mock.MagicMock() +## Helper function to read the contents of a container stack in the test +# stack folder. +# +# \param filename The name of the file in the "stacks" folder to read from. +# \return The contents of that file. +def readStack(filename): + with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "stacks", filename)) as file_handle: + serialized = file_handle.read() + return serialized + ## Tests whether the user changes are being read properly from a global stack. @pytest.mark.parametrize("filename, user_changes_id", [ ("Global.global.cfg", "empty"), @@ -39,8 +49,7 @@ def findSomeContainers(container_id = "*", container_type = None, type = None, c ("Complete.global.cfg", "some_user_changes") ]) def test_deserializeUserChanges(filename, user_changes_id, container_registry): - with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "stacks", filename)) as file_handle: - serialized = file_handle.read() + serialized = readStack(filename) stack = cura.Settings.GlobalStack.GlobalStack("TestStack") #Mock the loading of the instance containers. @@ -61,8 +70,7 @@ def test_deserializeUserChanges(filename, user_changes_id, container_registry): ("Complete.global.cfg", "some_quality_changes") ]) def test_deserializeQualityChanges(filename, quality_changes_id, container_registry): - with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "stacks", filename)) as file_handle: - serialized = file_handle.read() + serialized = readStack(filename) stack = cura.Settings.GlobalStack.GlobalStack("TestStack") #Mock the loading of the instance containers.