Пример #1
0
	def runTest(self):
		'''Test if included notebooks are up to date'''
		from zim.fs import Dir
		from zim.notebook import Notebook
		for path in ('data/manual', 'HACKING'):
			notebook = Notebook(dir=Dir(path))
			self.assertTrue(not notebook.needs_upgrade)
Пример #2
0
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
Пример #3
0
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
Пример #4
0
 def setUp(self):
     klass = zim.stores.get_store('memory')
     self.store = klass(path=Path(':'), notebook=Notebook())
     self.index = set()
     for name, text in tests.WikiTestData:
         self.store.set_node(Path(name), text)
         self.index.add(name)
     self.normalize_index()
Пример #5
0
 def setUp(self):
     TestStoresMemory.setUp(self)
     tmpdir = self.create_tmp_dir(u'_some_utf8_here_\u0421\u0430\u0439')
     self.dir = Dir([tmpdir, 'store-files'])
     self.mem = self.store
     klass = zim.stores.get_store('files')
     self.store = klass(path=Path(':'), notebook=Notebook(), dir=self.dir)
     for parent, page in walk(self.mem):
         if page.hascontent:
             mypage = self.store.get_page(page)
             mypage.set_parsetree(page.get_parsetree())
             self.store.store_page(mypage)
Пример #6
0
	def runTest(self):
		notebook = tests.new_notebook()
		page = notebook.get_page(Path('FooBar'))

		page.parse('wiki', '''\
====== Page Heading ======
**foo bar !**
''')
		self.assertTrue(len(page.dump('html', linker=StubLinker())) > 0)
		proxy = PageProxy(Notebook(), page, zim.formats.get_format('html'), StubLinker(), {})
		self.assertEqual(proxy.name, page.name)
		self.assertEqual(proxy.namespace, page.namespace)
		self.assertEqual(proxy.basename, page.basename)
		self.assertTrue(isinstance(proxy.properties, dict))
		self.assertTrue(len(proxy.body) > 0)
Пример #7
0
    def export(self):
        dir = Dir(self.create_tmp_dir('source_files'))
        init_notebook(dir)
        notebook = Notebook(dir=dir)
        for name, text in tests.WikiTestData:
            page = notebook.get_page(Path(name))
            page.parse('wiki', text)
            notebook.store_page(page)
        file = dir.file('Test/foo.txt')
        self.assertTrue(file.exists())

        argv = ('./zim.py', '--export', '--template=Default', dir.path,
                '--output', self.dir.path, '--index-page', 'index')
        #~ zim = Application(argv)
        #~ zim.run()

        cmd = zim.main.build_command(argv[1:])
        cmd.run()
Пример #8
0
 def setUp(self):
     buffer = StubFile(self.xml)
     klass = zim.stores.get_store('xml')
     self.store = klass(path=Path(':'), notebook=Notebook(), file=buffer)
     self.index = set(['Foo', 'Foo:Bar', 'Baz', u'utf8:\u03b1\u03b2\u03b3'])
     self.normalize_index()
Пример #9
0
    def runTest(self):
        '''Test synchronization'''
        # Test if zim detects pages, that where created with another
        # zim instance and transfered to this instance with
        # dropbox or another file synchronization tool.
        #
        # The scenario is as follow:
        # 1) Page.txt is created in this instance
        # 2) Page/Subpage.txt is created in another instance
        #    and copied into the notebook by the synchronization tool
        # 3) Zim runs a standard index update
        # Outcome should be that Page:Subpage shows up in the index

        # create notebook
        dir = Dir(self.create_tmp_dir())

        init_notebook(dir, name='foo')
        notebook = Notebook(dir=dir)
        index = notebook.index
        index.update()

        # add page in this instance
        path = Path('Page')
        page = notebook.get_page(path)
        page.parse('wiki', 'nothing important')
        notebook.store_page(page)

        # check file exists
        self.assertTrue(dir.file('Page.txt').exists())

        # check file is indexed
        self.assertTrue(page in list(index.list_all_pages()))

        # check attachment dir does not exist
        subdir = dir.subdir('Page')
        self.assertEqual(notebook.get_attachments_dir(page), subdir)
        self.assertFalse(subdir.exists())

        for newfile, newpath in (
            (subdir.file('NewSubpage.txt').path, Path('Page:NewSubpage')),
            (dir.file('Newtoplevel.txt').path, Path('Newtoplevel')),
            (dir.file('SomeDir/Dir/Newpage.txt').path,
             Path('SomeDir:Dir:Newpage')),
        ):
            # make sure ctime changed since last index
            import time
            time.sleep(2)

            # create new page without using zim classes
            self.assertFalse(os.path.isfile(newfile))

            mydir = os.path.dirname(newfile)
            if not os.path.isdir(mydir):
                os.makedirs(mydir)

            fh = open(newfile, 'w')
            fh.write('Test 123\n')
            fh.close()

            self.assertTrue(os.path.isfile(newfile))

            # simple index reload
            index.update()

            # check if the new page is found in the index
            self.assertTrue(newpath in list(index.list_all_pages()))