def new_files_notebook(dir): '''Returns a new Notebook object with a file store Uses data from L{WikiTestData} @param path: a folder path, e.g. created by L{TestCase.create_tmp_dir()} ''' from zim.fs import Dir from zim.notebook import init_notebook, Notebook, Path from zim.index import Index dir = Dir(dir) init_notebook(dir) notebook = Notebook(dir=dir) store = notebook.get_store(':') manifest = [] for name, text in WikiTestData: manifest.append(name) page = store.get_page(Path(name)) page.parse('wiki', text) store.store_page(page) notebook.testdata_manifest = _expand_manifest(manifest) notebook.index.update() return notebook
def new_notebook(fakedir=None): '''Returns a new Notebook object with all data in memory Uses data from L{WikiTestData} @param fakedir: optional parameter to set the 'dir' attribute for the notebook and the main store which allows you to resolve file paths etc. It will not automatically touch the dir (hence it being 'fake'). ''' from zim.fs import Dir from zim.notebook import Notebook, Path from zim.index import Index notebook = Notebook(index=Index(dbfile=':memory:')) store = notebook.add_store(Path(':'), 'memory') manifest = [] for name, text in WikiTestData: manifest.append(name) store.set_node(Path(name), text) notebook.testdata_manifest = _expand_manifest(manifest) notebook.index.update() if fakedir: dir = Dir(fakedir) notebook.dir = dir store.dir = dir return notebook
def get_test_notebook(format='wiki'): '''Returns a notebook with a memory store and some test data''' from zim.notebook import Notebook, Path from zim.index import Index notebook = Notebook(index=Index(dbfile=':memory:')) store = notebook.add_store(Path(':'), 'memory') manifest = [] for name, text in get_test_data(format): manifest.append(name) store.set_node(Path(name), text) notebook.testdata_manifest = expand_manifest(manifest) return notebook
def get_files_notebook(key): # We fill the notebook using the store interface, as this test comes before # the notebook test, but after the store test. dir = Dir(tests.create_tmp_dir('index_'+key)) notebook = Notebook(dir=dir) store = notebook.get_store(':') manifest = [] for name, text in tests.get_test_data('wiki'): manifest.append(name) page = store.get_page(Path(name)) page.parse('wiki', text) store.store_page(page) notebook.testdata_manifest = tests.expand_manifest(manifest) return notebook