mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-24 07:03:56 -06:00
Fix merge conflicts with master
This commit is contained in:
commit
4e5d08f320
153 changed files with 5127 additions and 3586 deletions
76
tests/Settings/TestContainerManager.py
Normal file
76
tests/Settings/TestContainerManager.py
Normal file
|
@ -0,0 +1,76 @@
|
|||
from unittest import TestCase
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from PyQt5.QtCore import QUrl
|
||||
|
||||
from UM.MimeTypeDatabase import MimeTypeDatabase
|
||||
from cura.Settings.ContainerManager import ContainerManager
|
||||
import tempfile
|
||||
import os
|
||||
|
||||
class TestContainerManager(TestCase):
|
||||
def setUp(self):
|
||||
|
||||
self._application = MagicMock()
|
||||
self._container_registry = MagicMock()
|
||||
self._machine_manager = MagicMock()
|
||||
|
||||
self._mocked_mime = MagicMock()
|
||||
self._mocked_mime.preferredSuffix = "omg"
|
||||
self._mocked_mime.suffixes = ["omg"]
|
||||
self._mocked_mime.comment = "UnitTest!"
|
||||
|
||||
self._mocked_container = MagicMock()
|
||||
self._mocked_container_data = "SOME DATA :D"
|
||||
self._mocked_container.serialize = MagicMock(return_value = self._mocked_container_data)
|
||||
|
||||
self._containers_meta_data = [{"id": "test", "test_data": "omg"}]
|
||||
self._container_registry.findContainersMetadata = MagicMock(return_value = self._containers_meta_data)
|
||||
self._container_registry.getMimeTypeForContainer = MagicMock(return_value = self._mocked_mime)
|
||||
self._container_registry.findContainers = MagicMock(return_value = [self._mocked_container])
|
||||
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)
|
||||
MimeTypeDatabase.addMimeType(self._mocked_mime)
|
||||
|
||||
def tearDown(self):
|
||||
MimeTypeDatabase.removeMimeType(self._mocked_mime)
|
||||
|
||||
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
|
||||
|
||||
def test_getContainerNameFilters(self):
|
||||
# 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.
|
||||
self._container_registry.getContainerTypes = MagicMock(return_value=[("None", None)])
|
||||
assert self._container_manager.getContainerNameFilters("") == ['UnitTest! (*.omg)', 'All Files (*)']
|
||||
|
||||
def test_exportContainerUnknownFileType(self):
|
||||
# The filetype is not known, so this should cause an error!
|
||||
assert self._container_manager.exportContainer("test", "zomg", "whatever")["status"] == "error"
|
||||
|
||||
def test_exportContainerInvalidPath(self):
|
||||
assert self._container_manager.exportContainer("test", "zomg", "")["status"] == "error"
|
||||
assert self._container_manager.exportContainer("test", "zomg", QUrl())["status"] == "error"
|
||||
|
||||
def test_exportContainerInvalidId(self):
|
||||
assert self._container_manager.exportContainer("", "whatever", "whatever")["status"] == "error"
|
||||
|
||||
def test_exportContainer(self):
|
||||
with tempfile.TemporaryDirectory() as tmpdirname:
|
||||
result = self._container_manager.exportContainer("test", "whatever", os.path.join(tmpdirname, "whatever.omg"))
|
||||
assert(os.path.exists(result["path"]))
|
||||
with open(result["path"], "r", encoding="utf-8") as f:
|
||||
assert f.read() == self._mocked_container_data
|
|
@ -1,7 +1,8 @@
|
|||
# Copyright (c) 2018 Ultimaker B.V.
|
||||
# Copyright (c) 2019 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
import os #To find the directory with test files and find the test files.
|
||||
import pytest #To parameterize tests.
|
||||
import unittest.mock #To mock and monkeypatch stuff.
|
||||
|
||||
from UM.Settings.DefinitionContainer import DefinitionContainer
|
||||
|
@ -119,3 +120,62 @@ def test_addContainerBadSettingVersion(container_registry, definition_container)
|
|||
container_registry.addContainer(instance)
|
||||
|
||||
mock_super_add_container.assert_not_called() #Should not get passed on to UM.Settings.ContainerRegistry.addContainer, because the setting_version doesn't match its definition!
|
||||
|
||||
test_loadMetaDataValidation_data = [
|
||||
{
|
||||
"id": "valid_container",
|
||||
"is_valid": True,
|
||||
"metadata": {
|
||||
"id": "valid_container",
|
||||
"setting_version": None, #The tests sets this to the current version so it's always correct.
|
||||
"foo": "bar"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "wrong_setting_version",
|
||||
"is_valid": False,
|
||||
"metadata": {
|
||||
"id": "wrong_setting_version",
|
||||
"setting_version": "5",
|
||||
"foo": "bar"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "missing_setting_version",
|
||||
"is_valid": False,
|
||||
"metadata": {
|
||||
"id": "missing_setting_version",
|
||||
"foo": "bar"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "unparsable_setting_version",
|
||||
"is_valid": False,
|
||||
"metadata": {
|
||||
"id": "unparsable_setting_version",
|
||||
"setting_version": "Not an integer!",
|
||||
"foo": "bar"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@pytest.mark.parametrize("parameters", test_loadMetaDataValidation_data)
|
||||
def test_loadMetadataValidation(container_registry, definition_container, parameters):
|
||||
from cura.CuraApplication import CuraApplication
|
||||
definition_container.getMetaData()["setting_version"] = CuraApplication.SettingVersion
|
||||
container_registry.addContainer(definition_container)
|
||||
if "setting_version" in parameters["metadata"] and parameters["metadata"]["setting_version"] is None: #Signal that the setting_version must be set to the currently correct version.
|
||||
parameters["metadata"]["setting_version"] = CuraApplication.SettingVersion
|
||||
|
||||
mock_provider = unittest.mock.MagicMock()
|
||||
mock_provider.getAllIds = unittest.mock.MagicMock(return_value = [parameters["id"]])
|
||||
mock_provider.loadMetadata = unittest.mock.MagicMock(return_value = parameters["metadata"])
|
||||
container_registry._providers = [mock_provider]
|
||||
|
||||
container_registry.loadAllMetadata() #Run the test.
|
||||
|
||||
if parameters["is_valid"]:
|
||||
assert parameters["id"] in container_registry.metadata
|
||||
assert container_registry.metadata[parameters["id"]] == parameters["metadata"]
|
||||
else:
|
||||
assert parameters["id"] not in container_registry.metadata
|
|
@ -82,7 +82,7 @@ def test_validateQualityProfiles(file_name):
|
|||
|
||||
except Exception as e:
|
||||
# File can't be read, header sections missing, whatever the case, this shouldn't happen!
|
||||
print("Go an Exception while reading he file [%s]: %s" % (file_name, e))
|
||||
print("Got an Exception while reading he file [%s]: %s" % (file_name, e))
|
||||
assert False
|
||||
|
||||
|
||||
|
@ -110,5 +110,5 @@ def test_validateVariantProfiles(file_name):
|
|||
assert False
|
||||
except Exception as e:
|
||||
# File can't be read, header sections missing, whatever the case, this shouldn't happen!
|
||||
print("Go an Exception while reading he file [%s]: %s" % (file_name, e))
|
||||
print("Got an Exception while reading he file [%s]: %s" % (file_name, e))
|
||||
assert False
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Copyright (c) 2018 Ultimaker B.V.
|
||||
# Uranium is released under the terms of the LGPLv3 or higher.
|
||||
# Copyright (c) 2019 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
# The purpose of this class is to create fixtures or methods that can be shared among all settings tests.
|
||||
|
||||
|
@ -49,6 +49,6 @@ def global_stack(definition_changes_container) -> GlobalStack:
|
|||
# There is a restriction here that the definition changes cannot be an empty container. Added in CURA-5281
|
||||
@pytest.fixture()
|
||||
def extruder_stack(definition_changes_container) -> ExtruderStack:
|
||||
extruder_stack= ExtruderStack("TestExtruderStack")
|
||||
extruder_stack = ExtruderStack("TestExtruderStack")
|
||||
extruder_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.DefinitionChanges] = definition_changes_container
|
||||
return extruder_stack
|
Loading…
Add table
Add a link
Reference in a new issue