From c14b3e4f2b975e4795f4068775b03f197cc6076e Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Wed, 22 Mar 2017 16:45:38 +0100 Subject: [PATCH] Add test with complete stack In this stack, all profiles are filled in properly with an instance container. This required some magic to make the container registry always return the desired profiles. Contributes to issue CURA-3497. --- tests/Settings/TestGlobalStack.py | 23 +++++++++++++++++++---- tests/Settings/stacks/Complete.global.cfg | 13 +++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 tests/Settings/stacks/Complete.global.cfg diff --git a/tests/Settings/TestGlobalStack.py b/tests/Settings/TestGlobalStack.py index 31bca56651..ad0552db92 100644 --- a/tests/Settings/TestGlobalStack.py +++ b/tests/Settings/TestGlobalStack.py @@ -5,21 +5,35 @@ 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. +import cura.Settings.GlobalStack #The module we're testing. from UM.Settings.DefinitionContainer import DefinitionContainer #To test against the class DefinitionContainer. import UM.Settings.ContainerRegistry +import UM.Settings.ContainerStack + +## Fake container registry that always provides all containers you ask of. +@pytest.fixture() +def container_registry(): + registry = unittest.mock.MagicMock() + def findContainers(id = None): + if not id: + return [UM.Settings.ContainerRegistry._EmptyInstanceContainer("test_container")] + else: + return [UM.Settings.ContainerRegistry._EmptyInstanceContainer(id)] + registry.findContainers = findContainers + return registry ## 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"), - ("OnlyUser.global.cfg", "some_instance") #This one does have a user profile. + ("OnlyUser.global.cfg", "some_instance"), #This one does have a user profile. + ("Complete.global.cfg", "some_user_changes") ]) -def test_deserializeUserChanges(filename, user_changes_id): +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() - stack = GlobalStack("TestStack") + stack = cura.Settings.GlobalStack.GlobalStack("TestStack") #Mock the loading of the instances. def findContainer(container_id = "*", container_type = None, type = None, category = "*"): @@ -28,6 +42,7 @@ def test_deserializeUserChanges(filename, user_changes_id): if container_type == DefinitionContainer: return unittest.mock.MagicMock() stack.findContainer = findContainer + UM.Settings.ContainerStack._containerRegistry = container_registry #Always has all profiles you ask of. stack.deserialize(serialized) diff --git a/tests/Settings/stacks/Complete.global.cfg b/tests/Settings/stacks/Complete.global.cfg new file mode 100644 index 0000000000..f7f613991a --- /dev/null +++ b/tests/Settings/stacks/Complete.global.cfg @@ -0,0 +1,13 @@ +[general] +version = 3 +name = Complete +id = Complete + +[containers] +0 = some_user_changes +1 = some_quality_changes +2 = some_quality +3 = some_material +4 = some_variant +5 = some_definition_changes +6 = some_definition