def test_setAllDataAndClear(): storage = WorkspaceMetadataStorage() storage.setAllData({"zomg": {"value": "zomg"}}) assert storage.getPluginMetadata("zomg") == {"value": "zomg"} storage.clear() assert storage.getPluginMetadata("zomg") == {}
def test_getAllData(): storage = WorkspaceMetadataStorage() storage.setEntryToStore("test", "bloop", 13) storage.setEntryToStore("test_2", "bloop", 34) data = storage.getAllData() assert len(data.keys()) == 2 assert data["test"]["bloop"] == 13 assert data["test_2"]["bloop"] == 34
def test_setMultipleEntriesToStore(): storage = WorkspaceMetadataStorage() storage.setEntryToStore("test", "bloop", 13) storage.setEntryToStore("test", "bloop2", 32) metadata = storage.getPluginMetadata("test") assert len(metadata.keys()) == 2 assert metadata["bloop"] == 13 assert metadata["bloop2"] == 32
def __init__(self, name: str, version: str, api_version: str, app_display_name: str = "", build_type: str = "", is_debug_mode: bool = False, **kwargs) -> None: """Init method :param name: :type{string} The name of the application. :param version: :type{string} Version, formatted as major.minor.rev :param build_type: Additional version info on the type of build this is, such as "master". :param is_debug_mode: Whether to run in debug mode. """ if Application.__instance is not None: raise RuntimeError("Try to create singleton '%s' more than once" % self.__class__.__name__) Application.__instance = self super().__init__() # Call super to make multiple inheritance work. self._api_version = Version(api_version) # type: Version self._app_name = name # type: str self._app_display_name = app_display_name if app_display_name else name # type: str self._version = version # type: str self._build_type = build_type # type: str self._is_debug_mode = is_debug_mode # type: bool self._is_headless = False # type: bool self._use_external_backend = False # type: bool self._just_updated_from_old_version = False # type: bool self._config_lock_filename = "{name}.lock".format(name = self._app_name) # type: str self._cli_args = None # type: argparse.Namespace self._cli_parser = argparse.ArgumentParser(prog = self._app_name, add_help = False) # type: argparse.ArgumentParser self._main_thread = threading.current_thread() # type: threading.Thread self.default_theme = self._app_name # type: str # Default theme is the application name self._default_language = "en_US" # type: str self.change_log_url = "https://github.com/Ultimaker/Uranium" # Where to find a more detailed description of the recent updates. self._preferences_filename = None # type: str self._preferences = None # type: Preferences self._extensions = [] # type: List[Extension] self._required_plugins = [] # type: List[str] self._package_manager_class = PackageManager # type: type self._package_manager = None # type: PackageManager self._plugin_registry = None # type: PluginRegistry self._container_registry_class = ContainerRegistry # type: type self._container_registry = None # type: ContainerRegistry self._global_container_stack = None # type: ContainerStack self._controller = None # type: Controller self._backend = None # type: Backend self._output_device_manager = None # type: OutputDeviceManager self._operation_stack = None # type: OperationStack self._visible_messages = [] # type: List[Message] self._message_lock = threading.Lock() # type: threading.Lock self._app_install_dir = self.getInstallPrefix() # type: str self._workspace_metadata_storage = WorkspaceMetadataStorage() # type: WorkspaceMetadataStorage
def __init__(self, name: str, version: str, api_version: str, app_display_name: str = "", build_type: str = "", is_debug_mode: bool = False, **kwargs) -> None: """Init method :param name: :type{string} The name of the application. :param version: :type{string} Version, formatted as major.minor.rev :param build_type: Additional version info on the type of build this is, such as "master". :param is_debug_mode: Whether to run in debug mode. """ if Application.__instance is not None: raise RuntimeError("Try to create singleton '%s' more than once" % self.__class__.__name__) super().__init__() # Call super to make multiple inheritance work. Application.__instance = self self._api_version = Version(api_version) # type: Version self._app_name = name # type: str self._app_display_name = app_display_name if app_display_name else name # type: str self._version = version # type: str self._build_type = build_type # type: str self._is_debug_mode = is_debug_mode # type: bool self._is_headless = False # type: bool self._use_external_backend = False # type: bool self._just_updated_from_old_version = False # type: bool self._config_lock_filename = "{name}.lock".format( name=self._app_name) # type: str self._cli_args = None # type: argparse.Namespace self._cli_parser = argparse.ArgumentParser( prog=self._app_name, add_help=False) # type: argparse.ArgumentParser self._main_thread = threading.current_thread( ) # type: threading.Thread self.default_theme = self._app_name # type: str # Default theme is the application name self._default_language = "en_US" # type: str self.change_log_url: str = "https://github.com/Ultimaker/Uranium" # Where to find a more detailed description of the recent updates. self.beta_change_log_url: str = "https://github.com/Ultimaker/Uranium" # Where to find a more detailed description of proposed updates. self._preferences_filename = None # type: str self._preferences = None # type: Preferences self._extensions = [] # type: List[Extension] self._file_providers = [] # type: List[FileProvider] self._required_plugins = [] # type: List[str] self._package_manager_class = PackageManager # type: type self._package_manager = None # type: PackageManager self._plugin_registry = None # type: PluginRegistry self._container_registry_class = ContainerRegistry # type: type self._container_registry = None # type: ContainerRegistry self._global_container_stack = None # type: Optional[ContainerStack] self._file_provider_model = FileProviderModel( application=self) # type: Optional[FileProviderModel] self._controller = None # type: Controller self._backend = None # type: Backend self._output_device_manager = None # type: OutputDeviceManager self._operation_stack = None # type: OperationStack self._visible_messages = [] # type: List[Message] self._message_lock = threading.Lock() # type: threading.Lock self._app_install_dir = self.getInstallPrefix() # type: str # Intended for keeping plugin workspace metadata that is going to be saved in and retrieved from workspace files. # When the workspace is stored, all workspace readers will need to ensure that the workspace metadata is correctly # stored to the output file. The same also holds when loading a workspace; the existing data will be cleared # and replaced with the data recovered from the file (if any). self._workspace_metadata_storage = WorkspaceMetadataStorage( ) # type: WorkspaceMetadataStorage # Intended for keeping plugin workspace information that is only temporary. The information added in this structure # is NOT saved to and retrieved from workspace files. self._current_workspace_information = WorkspaceMetadataStorage( ) # type: WorkspaceMetadataStorage
def test_setEntryToStore(): storage = WorkspaceMetadataStorage() storage.setEntryToStore("test", "bloop", 12) assert storage.getPluginMetadata("test") == {"bloop": 12}
def test_getUnknownEntry(): storage = WorkspaceMetadataStorage() storage.setEntryToStore("test", "bloop", 12) assert storage.getPluginMetadata("unknown") == {}
def test_setNestedEntryToStore(): storage = WorkspaceMetadataStorage() storage.setEntryToStore("test", "bloop", {"zomg": "blorp"}) assert storage.getPluginMetadata("test") == {"bloop": {"zomg": "blorp"}}
def test_getUnknownPluginsUnknownEntry(): storage = WorkspaceMetadataStorage() assert storage.getPluginMetadataEntry("unknown", "blorp") is None
def test_getKnownPluginsUnknownEntry(): storage = WorkspaceMetadataStorage() storage.setEntryToStore("test", "bloop", 12) assert storage.getPluginMetadataEntry("test", "blorp") is None