conftest.py 2.7 KB

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