mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-25 15:44:04 -06:00
Fix tests for ContainerManager
CURA-6600
This commit is contained in:
parent
719e69692c
commit
e18820b846
2 changed files with 18 additions and 15 deletions
|
@ -143,7 +143,6 @@ class IntentManager(QObject):
|
||||||
extruder_stack.intent = intent[0]
|
extruder_stack.intent = intent[0]
|
||||||
else:
|
else:
|
||||||
extruder_stack.intent = self.getDefaultIntent()
|
extruder_stack.intent = self.getDefaultIntent()
|
||||||
|
|
||||||
application.getMachineManager().setQualityGroupByQualityType(quality_type)
|
application.getMachineManager().setQualityGroupByQualityType(quality_type)
|
||||||
if old_intent_category != intent_category:
|
if old_intent_category != intent_category:
|
||||||
self.intentCategoryChanged.emit()
|
self.intentCategoryChanged.emit()
|
||||||
|
|
|
@ -2,7 +2,7 @@ from unittest import TestCase
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
from PyQt5.QtCore import QUrl
|
from PyQt5.QtCore import QUrl
|
||||||
|
from unittest.mock import patch
|
||||||
from UM.MimeTypeDatabase import MimeTypeDatabase
|
from UM.MimeTypeDatabase import MimeTypeDatabase
|
||||||
from cura.Settings.ContainerManager import ContainerManager
|
from cura.Settings.ContainerManager import ContainerManager
|
||||||
import tempfile
|
import tempfile
|
||||||
|
@ -42,20 +42,23 @@ class TestContainerManager(TestCase):
|
||||||
MimeTypeDatabase.removeMimeType(self._mocked_mime)
|
MimeTypeDatabase.removeMimeType(self._mocked_mime)
|
||||||
|
|
||||||
def test_getContainerMetaDataEntry(self):
|
def test_getContainerMetaDataEntry(self):
|
||||||
assert self._container_manager.getContainerMetaDataEntry("test", "test_data") == "omg"
|
with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value=self._application)):
|
||||||
assert self._container_manager.getContainerMetaDataEntry("test", "entry_that_is_not_defined") == ""
|
assert self._container_manager.getContainerMetaDataEntry("test", "test_data") == "omg"
|
||||||
|
assert self._container_manager.getContainerMetaDataEntry("test", "entry_that_is_not_defined") == ""
|
||||||
|
|
||||||
def test_clearUserContainer(self):
|
def test_clearUserContainer(self):
|
||||||
self._container_manager.clearUserContainers()
|
with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value=self._application)):
|
||||||
|
self._container_manager.clearUserContainers()
|
||||||
assert self._machine_manager.activeMachine.userChanges.clear.call_count == 1
|
assert self._machine_manager.activeMachine.userChanges.clear.call_count == 1
|
||||||
|
|
||||||
def test_getContainerNameFilters(self):
|
def test_getContainerNameFilters(self):
|
||||||
# If nothing is added, we still expect to get the all files filter
|
with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value=self._application)):
|
||||||
assert self._container_manager.getContainerNameFilters("") == ['All Files (*)']
|
# If nothing is added, we still expect to get the all files filter
|
||||||
|
assert self._container_manager.getContainerNameFilters("") == ['All Files (*)']
|
||||||
|
|
||||||
# Pretend that a new type was added.
|
# Pretend that a new type was added.
|
||||||
self._container_registry.getContainerTypes = MagicMock(return_value=[("None", None)])
|
self._container_registry.getContainerTypes = MagicMock(return_value=[("None", None)])
|
||||||
assert self._container_manager.getContainerNameFilters("") == ['UnitTest! (*.omg)', 'All Files (*)']
|
assert self._container_manager.getContainerNameFilters("") == ['UnitTest! (*.omg)', 'All Files (*)']
|
||||||
|
|
||||||
def test_exportContainerUnknownFileType(self):
|
def test_exportContainerUnknownFileType(self):
|
||||||
# The filetype is not known, so this should cause an error!
|
# The filetype is not known, so this should cause an error!
|
||||||
|
@ -69,8 +72,9 @@ class TestContainerManager(TestCase):
|
||||||
assert self._container_manager.exportContainer("", "whatever", "whatever")["status"] == "error"
|
assert self._container_manager.exportContainer("", "whatever", "whatever")["status"] == "error"
|
||||||
|
|
||||||
def test_exportContainer(self):
|
def test_exportContainer(self):
|
||||||
with tempfile.TemporaryDirectory() as tmpdirname:
|
with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value=self._application)):
|
||||||
result = self._container_manager.exportContainer("test", "whatever", os.path.join(tmpdirname, "whatever.omg"))
|
with tempfile.TemporaryDirectory() as tmpdirname:
|
||||||
assert(os.path.exists(result["path"]))
|
result = self._container_manager.exportContainer("test", "whatever", os.path.join(tmpdirname, "whatever.omg"))
|
||||||
with open(result["path"], "r", encoding="utf-8") as f:
|
assert(os.path.exists(result["path"]))
|
||||||
assert f.read() == self._mocked_container_data
|
with open(result["path"], "r", encoding="utf-8") as f:
|
||||||
|
assert f.read() == self._mocked_container_data
|
Loading…
Add table
Add a link
Reference in a new issue