mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-08-03 12:03:57 -06:00
Add test cases for the ContainerManager
This commit is contained in:
parent
8518aba3a5
commit
7bb35cdbf7
2 changed files with 36 additions and 2 deletions
|
@ -47,8 +47,10 @@ class ContainerManager(QObject):
|
|||
if ContainerManager.__instance is not None:
|
||||
raise RuntimeError("Try to create singleton '%s' more than once" % self.__class__.__name__)
|
||||
ContainerManager.__instance = self
|
||||
|
||||
try:
|
||||
super().__init__(parent = application)
|
||||
except TypeError:
|
||||
super().__init__()
|
||||
|
||||
self._application = application # type: CuraApplication
|
||||
self._plugin_registry = self._application.getPluginRegistry() # type: PluginRegistry
|
||||
|
|
32
tests/Settings/TestContainerManager.py
Normal file
32
tests/Settings/TestContainerManager.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
from unittest import TestCase
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from cura.Settings.ContainerManager import ContainerManager
|
||||
|
||||
|
||||
class TestContainerManager(TestCase):
|
||||
def setUp(self):
|
||||
|
||||
self._application = MagicMock()
|
||||
self._container_registry = MagicMock()
|
||||
self._machine_manager = MagicMock()
|
||||
|
||||
self._containers_meta_data = [{"id": "test", "test_data": "omg"}]
|
||||
self._container_registry.findContainersMetadata = MagicMock(return_value = self._containers_meta_data)
|
||||
|
||||
self._application.getContainerRegistry = MagicMock(return_value = self._container_registry)
|
||||
self._application.getMachineManager = MagicMock(return_value = self._machine_manager)
|
||||
|
||||
# Destroy the previous instance of the container manager
|
||||
if ContainerManager.getInstance() is not None:
|
||||
ContainerManager._ContainerManager__instance = None
|
||||
|
||||
self._container_manager = ContainerManager(self._application)
|
||||
|
||||
def test_getContainerMetaDataEntry(self):
|
||||
assert self._container_manager.getContainerMetaDataEntry("test", "test_data") == "omg"
|
||||
assert self._container_manager.getContainerMetaDataEntry("test", "entry_that_is_not_defined") == ""
|
||||
|
||||
def test_clearUserContainer(self):
|
||||
self._container_manager.clearUserContainers()
|
||||
assert self._machine_manager.activeMachine.userChanges.clear.call_count == 1
|
Loading…
Add table
Add a link
Reference in a new issue