Add test for global stack getting user changes

Tests fail right now because running the test actually deletes files. Got to fix that.

Contributes to issue CURA-3497.
This commit is contained in:
Ghostkeeper 2017-03-22 15:40:13 +01:00
parent c5768d89dc
commit 49fad35d28
No known key found for this signature in database
GPG key ID: C5F96EE2BC0F7E75
7 changed files with 50 additions and 7 deletions

View file

@ -0,0 +1,33 @@
# Copyright (c) 2017 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher.
import os.path #To find the test files.
import pytest #This module contains unit tests.
import unittest.mock #To monkeypatch some mocks in place of dependencies.
from cura.Settings.GlobalStack import GlobalStack #The module we're testing.
from UM.Settings.DefinitionContainer import DefinitionContainer #To test against the class DefinitionContainer.
import UM.Settings.ContainerRegistry
## Tests whether the user changes are being read properly from a global stack.
@pytest.mark.parametrize("filename, user_changes_id", [
("Global.global.cfg", "empty"),
("Global.stack.cfg", "empty"),
("MachineLegacy.stack.cfg", "empty")
])
def test_deserializeUserChanges(filename, user_changes_id):
with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "stacks", filename)) as file_handle:
serialized = file_handle.read()
stack = GlobalStack("TestStack")
#Mock the loading of the instances.
def findContainer(container_id = "*", container_type = None, type = None, category = "*"):
if id == "some_material":
return UM.Settings.ContainerRegistry._EmptyInstanceContainer(id)
if container_type == DefinitionContainer:
return unittest.mock.MagicMock()
stack.findContainer = findContainer
stack.deserialize(serialized)
assert stack.userChanges.getId() == user_changes_id