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.
This commit is contained in:
Ghostkeeper 2017-03-22 17:10:04 +01:00
parent 09a3b90dcc
commit ba43b835f4
No known key found for this signature in database
GPG key ID: C5F96EE2BC0F7E75

View file

@ -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.