Fix running tests via CMake

The Settings folder conflicts with the same folder in Uranium, so it couldn't find MockContainer from the Uranium version.

Contributes to issue CURA-6600.
This commit is contained in:
Ghostkeeper 2019-08-13 16:20:21 +02:00
parent efaa96bca3
commit 6a5f425468
No known key found for this signature in database
GPG Key ID: 86BEF881AE2CF276
3 changed files with 121 additions and 0 deletions

View File

@ -0,0 +1,121 @@
from typing import Optional
from UM.Settings.Interfaces import ContainerInterface
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.
def __init__(self, metadata = None):
super().__init__()
if metadata is None:
self._metadata = {}
else:
self._metadata = metadata
self._plugin_id = "MockContainerPlugin"
## Gets the ID that was provided at initialisation.
#
# \return The ID of the container.
def getId(self):
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):
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):
if entry in self._metadata:
return self._metadata[entry]
return default
## Gets a human-readable name for this container.
#
# \return Always returns "MockContainer".
def getName(self):
return "MockContainer"
## Get whether the container item is stored on a read only location in the filesystem.
#
# \return Always returns False
def isReadOnly(self):
return False
## Mock get path
def getPath(self):
return "/path/to/the/light/side"
## Mock set path
def setPath(self, path):
pass
def getAllKeys(self):
pass
def setProperty(self, key, property_name, property_value, container = None, set_from_cache = False):
pass
def getProperty(self, key, property_name, context=None):
if key in self.items:
return self.items[key]
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):
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):
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):
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):
raise NotImplementedError()
@classmethod
def getConfigurationTypeFromSerialized(cls, serialized: str):
raise NotImplementedError()
@classmethod
def getVersionFromSerialized(cls, serialized):
raise NotImplementedError()
metaDataChanged = Signal()
propertyChanged = Signal()
containersChanged = Signal()

View File

0
tests/__init__.py Normal file
View File