1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
from typing import Optional
from UM.Settings.Interfaces import ContainerInterface
import UM.PluginObject
from UM.Signal import Signal
class MockContainer(ContainerInterface, UM.PluginObject.PluginObject):
"""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 = {}
else:
self._metadata = metadata
self._plugin_id = "MockContainerPlugin"
def getId(self):
"""Gets the ID that was provided at initialisation.
:return: The ID of the container.
"""
return self._metadata["id"]
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
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
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")
@property
def isEnabled(self):
"""Get whether a container stack is enabled or not.
:return: Always returns True.
"""
return True
def isReadOnly(self):
"""Get whether the container item is stored on a read only location in the filesystem.
:return: Always returns False
"""
return False
def getPath(self):
"""Mock get path"""
return "/path/to/the/light/side"
def setPath(self, path):
"""Mock set path"""
pass
def getAllKeys(self):
pass
# Should return false (or even throw an exception) if trust (or other verification) is invalidated.
def _trustHook(self, file_name: Optional[str]) -> bool:
return True
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
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
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
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()
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
def getConfigurationTypeFromSerialized(cls, serialized: str):
raise NotImplementedError()
@classmethod
def getVersionFromSerialized(cls, serialized):
raise NotImplementedError()
def isDirty(self):
return True
def setDirty(self, dirty):
pass
metaDataChanged = Signal()
propertyChanged = Signal()
containersChanged = Signal()
|