Beispiel #1
0
	def testDumpWiki(self):
		attachment_dir = self.setUpFolder(mock=tests.MOCK_ALWAYS_REAL)
		LocalFolder(tests.ZIM_DATADIR).file('zim.png').copyto(attachment_dir.file('test.png'))

		notebook = self.setUpNotebook()
		notebook.get_attachments_dir = lambda *a: attachment_dir

		pageview = setUpPageView(notebook, text='{{./test.png?type=equation}}')
		pageview.textview.get_buffer().set_modified(True)
		tree = pageview.get_parsetree()
		text = WikiDumper().dump(tree)
		self.assertEquals(text, ['{{./test.png?type=equation}}\n'])
	def testModelFromData(self):
		notebook = self.setUpNotebook()
		page = notebook.get_page(Path('Test'))
		model = self.otype.model_from_data(notebook, page, {}, TABLE_WIKI_TEXT)

		builder = OldParseTreeBuilder() # XXX
		builder.start('zim-tree')
		self.otype.dump(builder, model)
		builder.end('zim-tree')
		tree = ParseTree(builder.close())

		#self.assertEquals(list(tree.iter_tokens()), TABLE_TOKENS) -- XXX should work but doesn;t :(
		self.assertEquals(''.join(WikiDumper().dump(tree)), TABLE_WIKI_TEXT[1:-1])
	def testModelFromElement(self):
		tree = WikiParser().parse(TABLE_WIKI_TEXT)
		element = tree._etree.getroot().find('table')
		self.assertIsNotNone(element)
		model = self.otype.model_from_element(element.attrib, element)

		builder = OldParseTreeBuilder() # XXX
		builder.start('zim-tree')
		self.otype.dump(builder, model)
		builder.end('zim-tree')
		tree = ParseTree(builder.close())

		#self.assertEquals(list(tree.iter_tokens()), TABLE_TOKENS) -- XXX should work but doesn;t :(
		self.assertEquals(''.join(WikiDumper().dump(tree)), TABLE_WIKI_TEXT[1:-1])