Add test for creation of unique name

This commit is contained in:
Jaime van Kessel 2019-02-08 13:35:50 +01:00
parent 2519ad311b
commit afce462cfa

View file

@ -11,12 +11,30 @@ import UM.Settings.InstanceContainer #Creating instance containers to register.
import UM.Settings.ContainerRegistry #Making empty container stacks.
import UM.Settings.ContainerStack #Setting the container registry here properly.
def teardown():
#If the temporary file for the legacy file rename test still exists, remove it.
temporary_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "stacks", "temporary.stack.cfg")
if os.path.isfile(temporary_file):
os.remove(temporary_file)
def test_createUniqueName(container_registry):
from cura.CuraApplication import CuraApplication
assert container_registry.createUniqueName("user", "test", "test2", "nope") == "test2"
# Make a conflict (so that "test2" will no longer be an unique name)
instance = UM.Settings.InstanceContainer.InstanceContainer(container_id="test2")
instance.setMetaDataEntry("type", "user")
instance.setMetaDataEntry("setting_version", CuraApplication.SettingVersion)
container_registry.addContainer(instance)
# It should add a #2 to test2
assert container_registry.createUniqueName("user", "test", "test2", "nope") == "test2 #2"
## Tests whether addContainer properly converts to ExtruderStack.
def test_addContainerExtruderStack(container_registry, definition_container, definition_changes_container):
container_registry.addContainer(definition_container)
@ -35,6 +53,7 @@ def test_addContainerExtruderStack(container_registry, definition_container, def
assert len(mock_super_add_container.call_args_list[0][0]) == 1 #Called with one parameter.
assert type(mock_super_add_container.call_args_list[0][0][0]) == ExtruderStack
## Tests whether addContainer properly converts to GlobalStack.
def test_addContainerGlobalStack(container_registry, definition_container, definition_changes_container):
container_registry.addContainer(definition_container)
@ -53,6 +72,7 @@ def test_addContainerGlobalStack(container_registry, definition_container, defin
assert len(mock_super_add_container.call_args_list[0][0]) == 1 #Called with one parameter.
assert type(mock_super_add_container.call_args_list[0][0][0]) == GlobalStack
def test_addContainerGoodSettingVersion(container_registry, definition_container):
from cura.CuraApplication import CuraApplication
definition_container.getMetaData()["setting_version"] = CuraApplication.SettingVersion
@ -68,6 +88,7 @@ def test_addContainerGoodSettingVersion(container_registry, definition_container
mock_super_add_container.assert_called_once_with(instance) #The instance must have been registered now.
def test_addContainerNoSettingVersion(container_registry, definition_container):
from cura.CuraApplication import CuraApplication
definition_container.getMetaData()["setting_version"] = CuraApplication.SettingVersion
@ -83,6 +104,7 @@ def test_addContainerNoSettingVersion(container_registry, definition_container):
mock_super_add_container.assert_not_called() #Should not get passed on to UM.Settings.ContainerRegistry.addContainer, because the setting_version is interpreted as 0!
def test_addContainerBadSettingVersion(container_registry, definition_container):
from cura.CuraApplication import CuraApplication
definition_container.getMetaData()["setting_version"] = CuraApplication.SettingVersion