1# Copyright (c) 2019 Ultimaker B.V.
2# Cura is released under the terms of the LGPLv3 or higher.
3
4# The purpose of this class is to create fixtures or methods that can be shared among all settings tests.
5
6import pytest
7
8from UM.Settings.ContainerRegistry import ContainerRegistry
9from UM.Settings.ContainerStack import setContainerRegistry
10from UM.Settings.DefinitionContainer import DefinitionContainer #To provide definition containers in the registry fixtures.
11from UM.Settings.InstanceContainer import InstanceContainer
12from cura.Settings.CuraContainerRegistry import CuraContainerRegistry
13from cura.Settings.ExtruderStack import ExtruderStack
14from cura.Settings.GlobalStack import GlobalStack
15import cura.Settings.CuraContainerStack
16
17# Returns the CuraContainerRegistry instance with some empty containers.
18@pytest.fixture()
19def container_registry(application) -> CuraContainerRegistry:
20    ContainerRegistry._ContainerRegistry__instance= None    # Need to reset since we only allow one instance
21    registry = CuraContainerRegistry(application)
22    setContainerRegistry(registry)
23    return registry
24
25# Gives an arbitrary definition container.
26@pytest.fixture()
27def definition_container() -> DefinitionContainer:
28    return DefinitionContainer(container_id = "Test Definition")
29
30# Gives an arbitrary definition changes container.
31@pytest.fixture()
32def definition_changes_container() -> InstanceContainer:
33    definition_changes_container = InstanceContainer(container_id = "Test Definition Changes")
34    definition_changes_container.setMetaDataEntry("type", "definition_changes")
35    # Add current setting version to the instance container
36    from cura.CuraApplication import CuraApplication
37    definition_changes_container.getMetaData()["setting_version"] = CuraApplication.SettingVersion
38    return definition_changes_container
39
40# An empty global stack to test with.
41# There is a restriction here that the definition changes cannot be an empty container. Added in CURA-5281
42@pytest.fixture()
43def global_stack(definition_changes_container) -> GlobalStack:
44    global_stack = GlobalStack("TestGlobalStack")
45    global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.DefinitionChanges] = definition_changes_container
46    return global_stack
47
48# An empty extruder stack to test with.
49# There is a restriction here that the definition changes cannot be an empty container. Added in CURA-5281
50@pytest.fixture()
51def extruder_stack(definition_changes_container) -> ExtruderStack:
52    extruder_stack = ExtruderStack("TestExtruderStack")
53    extruder_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.DefinitionChanges] = definition_changes_container
54    return extruder_stack