Convert remaining doxygen to rst

This commit is contained in:
Nino van Hooff 2020-05-28 17:13:44 +02:00
parent fe779d9501
commit c2c96faf5f
49 changed files with 2163 additions and 1657 deletions

View file

@ -5,18 +5,21 @@ import UM.PluginObject
from UM.Signal import Signal
## Fake container class to add to the container registry.
#
# This allows us to test the container registry without testing the container
# class. If something is wrong in the container class it won't influence this
# test.
class MockContainer(ContainerInterface, UM.PluginObject.PluginObject):
## Initialise a new definition container.
#
# The container will have the specified ID and all metadata in the
# provided dictionary.
"""Fake container class to add to the container registry.
This allows us to test the container registry without testing the container
class. If something is wrong in the container class it won't influence this
test.
"""
def __init__(self, metadata = None):
"""Initialise a new definition container.
The container will have the specified ID and all metadata in the
provided dictionary.
"""
super().__init__()
if metadata is None:
self._metadata = {}
@ -24,55 +27,69 @@ class MockContainer(ContainerInterface, UM.PluginObject.PluginObject):
self._metadata = metadata
self._plugin_id = "MockContainerPlugin"
## Gets the ID that was provided at initialisation.
#
# \return The ID of the container.
def getId(self):
"""Gets the ID that was provided at initialisation.
:return: The ID of the container.
"""
return self._metadata["id"]
## Gets all metadata of this container.
#
# This returns the metadata dictionary that was provided in the
# constructor of this mock container.
#
# \return The metadata for this container.
def getMetaData(self):
"""Gets all metadata of this container.
This returns the metadata dictionary that was provided in the
constructor of this mock container.
:return: The metadata for this container.
"""
return self._metadata
## Gets a metadata entry from the metadata dictionary.
#
# \param key The key of the metadata entry.
# \return The value of the metadata entry, or None if there is no such
# entry.
def getMetaDataEntry(self, entry, default = None):
"""Gets a metadata entry from the metadata dictionary.
:param key: The key of the metadata entry.
:return: The value of the metadata entry, or None if there is no such
entry.
"""
if entry in self._metadata:
return self._metadata[entry]
return default
## Gets a human-readable name for this container.
# \return The name from the metadata, or "MockContainer" if there was no
# name provided.
def getName(self):
"""Gets a human-readable name for this container.
:return: The name from the metadata, or "MockContainer" if there was no
name provided.
"""
return self._metadata.get("name", "MockContainer")
## Get whether a container stack is enabled or not.
# \return Always returns True.
@property
def isEnabled(self):
"""Get whether a container stack is enabled or not.
:return: Always returns True.
"""
return True
## Get whether the container item is stored on a read only location in the filesystem.
#
# \return Always returns False
def isReadOnly(self):
"""Get whether the container item is stored on a read only location in the filesystem.
:return: Always returns False
"""
return False
## Mock get path
def getPath(self):
"""Mock get path"""
return "/path/to/the/light/side"
## Mock set path
def setPath(self, path):
"""Mock set path"""
pass
def getAllKeys(self):
@ -91,31 +108,38 @@ class MockContainer(ContainerInterface, UM.PluginObject.PluginObject):
return None
## Get the value of a container item.
#
# Since this mock container cannot contain any items, it always returns
# None.
#
# \return Always returns None.
def getValue(self, key):
"""Get the value of a container item.
Since this mock container cannot contain any items, it always returns None.
:return: Always returns None.
"""
pass
## Get whether the container item has a specific property.
#
# This method is not implemented in the mock container.
def hasProperty(self, key, property_name):
"""Get whether the container item has a specific property.
This method is not implemented in the mock container.
"""
return key in self.items
## Serializes the container to a string representation.
#
# This method is not implemented in the mock container.
def serialize(self, ignored_metadata_keys = None):
"""Serializes the container to a string representation.
This method is not implemented in the mock container.
"""
raise NotImplementedError()
## Deserializes the container from a string representation.
#
# This method is not implemented in the mock container.
def deserialize(self, serialized, file_name: Optional[str] = None):
"""Deserializes the container from a string representation.
This method is not implemented in the mock container.
"""
raise NotImplementedError()
@classmethod

View file

@ -42,8 +42,9 @@ def test_createUniqueName(container_registry):
assert container_registry.createUniqueName("user", "test", "", "nope") == "nope"
## Tests whether addContainer properly converts to ExtruderStack.
def test_addContainerExtruderStack(container_registry, definition_container, definition_changes_container):
"""Tests whether addContainer properly converts to ExtruderStack."""
container_registry.addContainer(definition_container)
container_registry.addContainer(definition_changes_container)
@ -61,8 +62,9 @@ def test_addContainerExtruderStack(container_registry, definition_container, def
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):
"""Tests whether addContainer properly converts to GlobalStack."""
container_registry.addContainer(definition_container)
container_registry.addContainer(definition_changes_container)

View file

@ -57,9 +57,10 @@ def test_noCategory(file_path):
metadata = DefinitionContainer.deserializeMetadata(json, "test_container_id")
assert "category" not in metadata[0]
## Tests all definition containers
@pytest.mark.parametrize("file_path", machine_filepaths)
def test_validateMachineDefinitionContainer(file_path, definition_container):
"""Tests all definition containers"""
file_name = os.path.basename(file_path)
if file_name == "fdmprinter.def.json" or file_name == "fdmextruder.def.json":
return # Stop checking, these are root files.
@ -85,13 +86,15 @@ def assertIsDefinitionValid(definition_container, file_path):
if "platform_texture" in metadata[0]:
assert metadata[0]["platform_texture"] in all_images
## Tests whether setting values are not being hidden by parent containers.
#
# When a definition container defines a "default_value" but inherits from a
# definition that defines a "value", the "default_value" is ineffective. This
# test fails on those things.
@pytest.mark.parametrize("file_path", definition_filepaths)
def test_validateOverridingDefaultValue(file_path: str):
"""Tests whether setting values are not being hidden by parent containers.
When a definition container defines a "default_value" but inherits from a
definition that defines a "value", the "default_value" is ineffective. This
test fails on those things.
"""
with open(file_path, encoding = "utf-8") as f:
doc = json.load(f)
@ -107,12 +110,14 @@ def test_validateOverridingDefaultValue(file_path: str):
faulty_keys.add(key)
assert not faulty_keys, "Unnecessary default_values for {faulty_keys} in {file_name}".format(faulty_keys = sorted(faulty_keys), file_name = file_path) # If there is a value in the parent settings, then the default_value is not effective.
## Get all settings and their properties from a definition we're inheriting
# from.
# \param definition_id The definition we're inheriting from.
# \return A dictionary of settings by key. Each setting is a dictionary of
# properties.
def getInheritedSettings(definition_id: str) -> Dict[str, Any]:
"""Get all settings and their properties from a definition we're inheriting from.
:param definition_id: The definition we're inheriting from.
:return: A dictionary of settings by key. Each setting is a dictionary of properties.
"""
definition_path = os.path.join(os.path.dirname(__file__), "..", "..", "resources", "definitions", definition_id + ".def.json")
with open(definition_path, encoding = "utf-8") as f:
doc = json.load(f)
@ -127,13 +132,15 @@ def getInheritedSettings(definition_id: str) -> Dict[str, Any]:
return result
## Put all settings in the main dictionary rather than in children dicts.
# \param settings Nested settings. The keys are the setting IDs. The values
# are dictionaries of properties per setting, including the "children"
# property.
# \return A dictionary of settings by key. Each setting is a dictionary of
# properties.
def flattenSettings(settings: Dict[str, Any]) -> Dict[str, Any]:
"""Put all settings in the main dictionary rather than in children dicts.
:param settings: Nested settings. The keys are the setting IDs. The values
are dictionaries of properties per setting, including the "children" property.
:return: A dictionary of settings by key. Each setting is a dictionary of properties.
"""
result = {}
for entry, contents in settings.items():
if "children" in contents:
@ -142,12 +149,16 @@ def flattenSettings(settings: Dict[str, Any]) -> Dict[str, Any]:
result[entry] = contents
return result
## Make one dictionary override the other. Nested dictionaries override each
# other in the same way.
# \param base A dictionary of settings that will get overridden by the other.
# \param overrides A dictionary of settings that will override the other.
# \return Combined setting data.
def merge_dicts(base: Dict[str, Any], overrides: Dict[str, Any]) -> Dict[str, Any]:
"""Make one dictionary override the other. Nested dictionaries override each
other in the same way.
:param base: A dictionary of settings that will get overridden by the other.
:param overrides: A dictionary of settings that will override the other.
:return: Combined setting data.
"""
result = {}
result.update(base)
for key, val in overrides.items():
@ -161,21 +172,25 @@ def merge_dicts(base: Dict[str, Any], overrides: Dict[str, Any]) -> Dict[str, An
result[key] = val
return result
## Verifies that definition contains don't have an ID field.
#
# ID fields are legacy. They should not be used any more. This is legacy that
# people don't seem to be able to get used to.
@pytest.mark.parametrize("file_path", definition_filepaths)
def test_noId(file_path: str):
"""Verifies that definition contains don't have an ID field.
ID fields are legacy. They should not be used any more. This is legacy that
people don't seem to be able to get used to.
"""
with open(file_path, encoding = "utf-8") as f:
doc = json.load(f)
assert "id" not in doc, "Definitions should not have an ID field."
## Verifies that extruders say that they work on the same extruder_nr as what
# is listed in their machine definition.
@pytest.mark.parametrize("file_path", extruder_filepaths)
def test_extruderMatch(file_path: str):
"""Verifies that extruders say that they work on the same extruder_nr as what is listed in their machine definition."""
extruder_id = os.path.basename(file_path).split(".")[0]
with open(file_path, encoding = "utf-8") as f:
doc = json.load(f)

View file

@ -14,11 +14,13 @@ from cura.Settings.Exceptions import InvalidContainerError, InvalidOperationErro
from cura.Settings.ExtruderManager import ExtruderManager
from cura.Settings.cura_empty_instance_containers import empty_container
## Gets an instance container with a specified container type.
#
# \param container_type The type metadata for the instance container.
# \return An instance container instance.
def getInstanceContainer(container_type) -> InstanceContainer:
"""Gets an instance container with a specified container type.
:param container_type: The type metadata for the instance container.
:return: An instance container instance.
"""
container = InstanceContainer(container_id = "InstanceContainer")
container.setMetaDataEntry("type", container_type)
return container
@ -32,10 +34,12 @@ class InstanceContainerSubClass(InstanceContainer):
super().__init__(container_id = "SubInstanceContainer")
self.setMetaDataEntry("type", container_type)
#############################START OF TEST CASES################################
############################START OF TEST CASES################################
## Tests whether adding a container is properly forbidden.
def test_addContainer(extruder_stack):
"""Tests whether adding a container is properly forbidden."""
with pytest.raises(InvalidOperationError):
extruder_stack.addContainer(unittest.mock.MagicMock())
@ -164,8 +168,10 @@ def test_constrainDefinitionInvalid(container, extruder_stack):
def test_constrainDefinitionValid(container, extruder_stack):
extruder_stack.definition = container #Should not give an error.
## Tests whether deserialising completes the missing containers with empty ones.
def test_deserializeCompletesEmptyContainers(extruder_stack):
"""Tests whether deserialising completes the missing containers with empty ones."""
extruder_stack._containers = [DefinitionContainer(container_id = "definition"), extruder_stack.definitionChanges] #Set the internal state of this stack manually.
with unittest.mock.patch("UM.Settings.ContainerStack.ContainerStack.deserialize", unittest.mock.MagicMock()): #Prevent calling super().deserialize.
@ -179,8 +185,10 @@ def test_deserializeCompletesEmptyContainers(extruder_stack):
continue
assert extruder_stack.getContainer(container_type_index) == empty_container #All others need to be empty.
## Tests whether an instance container with the wrong type gets removed when deserialising.
def test_deserializeRemovesWrongInstanceContainer(extruder_stack):
"""Tests whether an instance container with the wrong type gets removed when deserialising."""
extruder_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Quality] = getInstanceContainer(container_type = "wrong type")
extruder_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Definition] = DefinitionContainer(container_id = "some definition")
@ -189,8 +197,10 @@ def test_deserializeRemovesWrongInstanceContainer(extruder_stack):
assert extruder_stack.quality == extruder_stack._empty_instance_container #Replaced with empty.
## Tests whether a container with the wrong class gets removed when deserialising.
def test_deserializeRemovesWrongContainerClass(extruder_stack):
"""Tests whether a container with the wrong class gets removed when deserialising."""
extruder_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Quality] = DefinitionContainer(container_id = "wrong class")
extruder_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Definition] = DefinitionContainer(container_id = "some definition")
@ -199,16 +209,20 @@ def test_deserializeRemovesWrongContainerClass(extruder_stack):
assert extruder_stack.quality == extruder_stack._empty_instance_container #Replaced with empty.
## Tests whether an instance container in the definition spot results in an error.
def test_deserializeWrongDefinitionClass(extruder_stack):
"""Tests whether an instance container in the definition spot results in an error."""
extruder_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Definition] = getInstanceContainer(container_type = "definition") #Correct type but wrong class.
with unittest.mock.patch("UM.Settings.ContainerStack.ContainerStack.deserialize", unittest.mock.MagicMock()): #Prevent calling super().deserialize.
with pytest.raises(UM.Settings.ContainerStack.InvalidContainerStackError): #Must raise an error that there is no definition container.
extruder_stack.deserialize("")
## Tests whether an instance container with the wrong type is moved into the correct slot by deserialising.
def test_deserializeMoveInstanceContainer(extruder_stack):
"""Tests whether an instance container with the wrong type is moved into the correct slot by deserialising."""
extruder_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Quality] = getInstanceContainer(container_type = "material") #Not in the correct spot.
extruder_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Definition] = DefinitionContainer(container_id = "some definition")
@ -218,8 +232,10 @@ def test_deserializeMoveInstanceContainer(extruder_stack):
assert extruder_stack.quality == empty_container
assert extruder_stack.material != empty_container
## Tests whether a definition container in the wrong spot is moved into the correct spot by deserialising.
def test_deserializeMoveDefinitionContainer(extruder_stack):
"""Tests whether a definition container in the wrong spot is moved into the correct spot by deserialising."""
extruder_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Material] = DefinitionContainer(container_id = "some definition") #Not in the correct spot.
with unittest.mock.patch("UM.Settings.ContainerStack.ContainerStack.deserialize", unittest.mock.MagicMock()): #Prevent calling super().deserialize.
@ -228,8 +244,10 @@ def test_deserializeMoveDefinitionContainer(extruder_stack):
assert extruder_stack.material == empty_container
assert extruder_stack.definition != empty_container
## Tests whether getProperty properly applies the stack-like behaviour on its containers.
def test_getPropertyFallThrough(global_stack, extruder_stack):
"""Tests whether getProperty properly applies the stack-like behaviour on its containers."""
# ExtruderStack.setNextStack calls registerExtruder for backward compatibility, but we do not need a complete extruder manager
ExtruderManager._ExtruderManager__instance = unittest.mock.MagicMock()
@ -273,13 +291,17 @@ def test_getPropertyFallThrough(global_stack, extruder_stack):
extruder_stack.userChanges = mock_layer_heights[container_indices.UserChanges]
assert extruder_stack.getProperty("layer_height", "value") == container_indices.UserChanges
## Tests whether inserting a container is properly forbidden.
def test_insertContainer(extruder_stack):
"""Tests whether inserting a container is properly forbidden."""
with pytest.raises(InvalidOperationError):
extruder_stack.insertContainer(0, unittest.mock.MagicMock())
## Tests whether removing a container is properly forbidden.
def test_removeContainer(extruder_stack):
"""Tests whether removing a container is properly forbidden."""
with pytest.raises(InvalidOperationError):
extruder_stack.removeContainer(unittest.mock.MagicMock())

View file

@ -16,11 +16,13 @@ import UM.Settings.SettingDefinition #To add settings to the definition.
from cura.Settings.cura_empty_instance_containers import empty_container
## Gets an instance container with a specified container type.
#
# \param container_type The type metadata for the instance container.
# \return An instance container instance.
def getInstanceContainer(container_type) -> InstanceContainer:
"""Gets an instance container with a specified container type.
:param container_type: The type metadata for the instance container.
:return: An instance container instance.
"""
container = InstanceContainer(container_id = "InstanceContainer")
container.setMetaDataEntry("type", container_type)
return container
@ -37,17 +39,19 @@ class InstanceContainerSubClass(InstanceContainer):
self.setMetaDataEntry("type", container_type)
#############################START OF TEST CASES################################
############################START OF TEST CASES################################
## Tests whether adding a container is properly forbidden.
def test_addContainer(global_stack):
"""Tests whether adding a container is properly forbidden."""
with pytest.raises(InvalidOperationError):
global_stack.addContainer(unittest.mock.MagicMock())
## Tests adding extruders to the global stack.
def test_addExtruder(global_stack):
"""Tests adding extruders to the global stack."""
mock_definition = unittest.mock.MagicMock()
mock_definition.getProperty = lambda key, property, context = None: 2 if key == "machine_extruder_count" and property == "value" else None
@ -213,9 +217,12 @@ def test_constrainDefinitionValid(container, global_stack):
global_stack.definition = container #Should not give an error.
## Tests whether deserialising completes the missing containers with empty ones. The initial containers are just the
# definition and the definition_changes (that cannot be empty after CURA-5281)
def test_deserializeCompletesEmptyContainers(global_stack):
"""Tests whether deserialising completes the missing containers with empty ones. The initial containers are just the
definition and the definition_changes (that cannot be empty after CURA-5281)
"""
global_stack._containers = [DefinitionContainer(container_id = "definition"), global_stack.definitionChanges] #Set the internal state of this stack manually.
with unittest.mock.patch("UM.Settings.ContainerStack.ContainerStack.deserialize", unittest.mock.MagicMock()): #Prevent calling super().deserialize.
@ -229,8 +236,9 @@ def test_deserializeCompletesEmptyContainers(global_stack):
assert global_stack.getContainer(container_type_index) == empty_container #All others need to be empty.
## Tests whether an instance container with the wrong type gets removed when deserialising.
def test_deserializeRemovesWrongInstanceContainer(global_stack):
"""Tests whether an instance container with the wrong type gets removed when deserialising."""
global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Quality] = getInstanceContainer(container_type = "wrong type")
global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Definition] = DefinitionContainer(container_id = "some definition")
@ -240,8 +248,9 @@ def test_deserializeRemovesWrongInstanceContainer(global_stack):
assert global_stack.quality == global_stack._empty_instance_container #Replaced with empty.
## Tests whether a container with the wrong class gets removed when deserialising.
def test_deserializeRemovesWrongContainerClass(global_stack):
"""Tests whether a container with the wrong class gets removed when deserialising."""
global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Quality] = DefinitionContainer(container_id = "wrong class")
global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Definition] = DefinitionContainer(container_id = "some definition")
@ -251,8 +260,9 @@ def test_deserializeRemovesWrongContainerClass(global_stack):
assert global_stack.quality == global_stack._empty_instance_container #Replaced with empty.
## Tests whether an instance container in the definition spot results in an error.
def test_deserializeWrongDefinitionClass(global_stack):
"""Tests whether an instance container in the definition spot results in an error."""
global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Definition] = getInstanceContainer(container_type = "definition") #Correct type but wrong class.
with unittest.mock.patch("UM.Settings.ContainerStack.ContainerStack.deserialize", unittest.mock.MagicMock()): #Prevent calling super().deserialize.
@ -260,8 +270,9 @@ def test_deserializeWrongDefinitionClass(global_stack):
global_stack.deserialize("")
## Tests whether an instance container with the wrong type is moved into the correct slot by deserialising.
def test_deserializeMoveInstanceContainer(global_stack):
"""Tests whether an instance container with the wrong type is moved into the correct slot by deserialising."""
global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Quality] = getInstanceContainer(container_type = "material") #Not in the correct spot.
global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Definition] = DefinitionContainer(container_id = "some definition")
@ -272,8 +283,9 @@ def test_deserializeMoveInstanceContainer(global_stack):
assert global_stack.material != empty_container
## Tests whether a definition container in the wrong spot is moved into the correct spot by deserialising.
def test_deserializeMoveDefinitionContainer(global_stack):
"""Tests whether a definition container in the wrong spot is moved into the correct spot by deserialising."""
global_stack._containers[cura.Settings.CuraContainerStack._ContainerIndexes.Material] = DefinitionContainer(container_id = "some definition") #Not in the correct spot.
with unittest.mock.patch("UM.Settings.ContainerStack.ContainerStack.deserialize", unittest.mock.MagicMock()): #Prevent calling super().deserialize.
@ -283,8 +295,9 @@ def test_deserializeMoveDefinitionContainer(global_stack):
assert global_stack.definition != empty_container
## Tests whether getProperty properly applies the stack-like behaviour on its containers.
def test_getPropertyFallThrough(global_stack):
"""Tests whether getProperty properly applies the stack-like behaviour on its containers."""
#A few instance container mocks to put in the stack.
mock_layer_heights = {} #For each container type, a mock container that defines layer height to something unique.
mock_no_settings = {} #For each container type, a mock container that has no settings at all.
@ -326,8 +339,9 @@ def test_getPropertyFallThrough(global_stack):
assert global_stack.getProperty("layer_height", "value") == container_indexes.UserChanges
## In definitions, test whether having no resolve allows us to find the value.
def test_getPropertyNoResolveInDefinition(global_stack):
"""In definitions, test whether having no resolve allows us to find the value."""
value = unittest.mock.MagicMock() #Just sets the value for bed temperature.
value.getProperty = lambda key, property, context = None: 10 if (key == "material_bed_temperature" and property == "value") else None
@ -336,8 +350,9 @@ def test_getPropertyNoResolveInDefinition(global_stack):
assert global_stack.getProperty("material_bed_temperature", "value") == 10 #No resolve, so fall through to value.
## In definitions, when the value is asked and there is a resolve function, it must get the resolve first.
def test_getPropertyResolveInDefinition(global_stack):
"""In definitions, when the value is asked and there is a resolve function, it must get the resolve first."""
resolve_and_value = unittest.mock.MagicMock() #Sets the resolve and value for bed temperature.
resolve_and_value.getProperty = lambda key, property, context = None: (7.5 if property == "resolve" else 5) if (key == "material_bed_temperature" and property in ("resolve", "value")) else None #7.5 resolve, 5 value.
@ -346,8 +361,9 @@ def test_getPropertyResolveInDefinition(global_stack):
assert global_stack.getProperty("material_bed_temperature", "value") == 7.5 #Resolve wins in the definition.
## In instance containers, when the value is asked and there is a resolve function, it must get the value first.
def test_getPropertyResolveInInstance(global_stack):
"""In instance containers, when the value is asked and there is a resolve function, it must get the value first."""
container_indices = cura.Settings.CuraContainerStack._ContainerIndexes
instance_containers = {}
for container_type in container_indices.IndexTypeMap:
@ -373,8 +389,9 @@ def test_getPropertyResolveInInstance(global_stack):
assert global_stack.getProperty("material_bed_temperature", "value") == 5
## Tests whether the value in instances gets evaluated before the resolve in definitions.
def test_getPropertyInstancesBeforeResolve(global_stack):
"""Tests whether the value in instances gets evaluated before the resolve in definitions."""
def getValueProperty(key, property, context = None):
if key != "material_bed_temperature":
return None
@ -404,8 +421,9 @@ def test_getPropertyInstancesBeforeResolve(global_stack):
assert global_stack.getProperty("material_bed_temperature", "value") == 10
## Tests whether the hasUserValue returns true for settings that are changed in the user-changes container.
def test_hasUserValueUserChanges(global_stack):
"""Tests whether the hasUserValue returns true for settings that are changed in the user-changes container."""
container = unittest.mock.MagicMock()
container.getMetaDataEntry = unittest.mock.MagicMock(return_value = "user")
container.hasProperty = lambda key, property: key == "layer_height" #Only have the layer_height property set.
@ -416,8 +434,9 @@ def test_hasUserValueUserChanges(global_stack):
assert not global_stack.hasUserValue("")
## Tests whether the hasUserValue returns true for settings that are changed in the quality-changes container.
def test_hasUserValueQualityChanges(global_stack):
"""Tests whether the hasUserValue returns true for settings that are changed in the quality-changes container."""
container = unittest.mock.MagicMock()
container.getMetaDataEntry = unittest.mock.MagicMock(return_value = "quality_changes")
container.hasProperty = lambda key, property: key == "layer_height" #Only have the layer_height property set.
@ -428,8 +447,9 @@ def test_hasUserValueQualityChanges(global_stack):
assert not global_stack.hasUserValue("")
## Tests whether a container in some other place on the stack is correctly not recognised as user value.
def test_hasNoUserValue(global_stack):
"""Tests whether a container in some other place on the stack is correctly not recognised as user value."""
container = unittest.mock.MagicMock()
container.getMetaDataEntry = unittest.mock.MagicMock(return_value = "quality")
container.hasProperty = lambda key, property: key == "layer_height" #Only have the layer_height property set.
@ -438,20 +458,23 @@ def test_hasNoUserValue(global_stack):
assert not global_stack.hasUserValue("layer_height") #However this container is quality, so it's not a user value.
## Tests whether inserting a container is properly forbidden.
def test_insertContainer(global_stack):
"""Tests whether inserting a container is properly forbidden."""
with pytest.raises(InvalidOperationError):
global_stack.insertContainer(0, unittest.mock.MagicMock())
## Tests whether removing a container is properly forbidden.
def test_removeContainer(global_stack):
"""Tests whether removing a container is properly forbidden."""
with pytest.raises(InvalidOperationError):
global_stack.removeContainer(unittest.mock.MagicMock())
## Tests whether changing the next stack is properly forbidden.
def test_setNextStack(global_stack):
"""Tests whether changing the next stack is properly forbidden."""
with pytest.raises(InvalidOperationError):
global_stack.setNextStack(unittest.mock.MagicMock())

View file

@ -61,9 +61,10 @@ variant_filepaths = collectAllVariants()
intent_filepaths = collectAllIntents()
## Attempt to load all the quality profiles.
@pytest.mark.parametrize("file_name", quality_filepaths)
def test_validateQualityProfiles(file_name):
"""Attempt to load all the quality profiles."""
try:
with open(file_name, encoding = "utf-8") as data:
serialized = data.read()
@ -114,9 +115,10 @@ def test_validateIntentProfiles(file_name):
# File can't be read, header sections missing, whatever the case, this shouldn't happen!
assert False, "Got an exception while reading the file {file_name}: {err}".format(file_name = file_name, err = str(e))
## Attempt to load all the variant profiles.
@pytest.mark.parametrize("file_name", variant_filepaths)
def test_validateVariantProfiles(file_name):
"""Attempt to load all the variant profiles."""
try:
with open(file_name, encoding = "utf-8") as data:
serialized = data.read()