def add_directory_structure(dirs): """ create the nested WorkspaceGroup structure in the ADS specified by the stored directory attribute. dirs = ["dir1", "dir2"] eg. ['Muon Data', 'MUSR72105', 'MUSR72105 Raw Data'] """ if not dirs: return if len(dirs) > len(set(dirs)): raise ValueError("Group names must be unique") for directory in dirs: if not mtd.doesExist(directory): workspace_group = api.WorkspaceGroup() mtd.addOrReplace(directory, workspace_group) elif not isinstance(mtd[directory], api.WorkspaceGroup): mtd.remove(directory) workspace_group = api.WorkspaceGroup() mtd.addOrReplace(directory, workspace_group) else: # exists and is a workspace group pass # Create the nested group structure in the ADS previous_dir = "" for i, directory in enumerate(dirs): if i == 0: previous_dir = directory continue if not mtd[previous_dir].__contains__(directory): mtd[previous_dir].add(directory) previous_dir = directory
def test_that_cannot_initialize_with_WorkspaceGroup_object(self): group_workspace = api.WorkspaceGroup() assert isinstance(group_workspace, WorkspaceGroup) with self.assertRaises(AttributeError): MuonWorkspaceWrapper(workspace=group_workspace)