Пример #1
0
	def runTest(self):
		input = u'''\
Version [% zim.version %]
<title>[% page.title %]</title>
<h1>[% page.name %]</h1>
<h2>[% page.heading %]</h2>
[% page.body %]
'''
		wantedresult = u'''\
Version %s
<title>Page Heading</title>
<h1>FooBar</h1>
<h2>Page Heading</h2>
<p>
<strong>foo bar !</strong><br>
</p>

''' % zim.__version__
		notebook, page = tests.get_test_page('FooBar')
		page.parse('wiki', '''\
====== Page Heading ======
**foo bar !**
''')
		self.assertTrue(len(page.dump('html', linker=StubLinker())) > 0)
		result = Template(input, 'html', linker=StubLinker()).process(Notebook(), page)
		self.assertEqualDiff(result, wantedresult.splitlines(True))
Пример #2
0
	def runTest(self):
		notebook, page = tests.get_test_page('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)
Пример #3
0
	def testUpdateLinks(self):
		'''Test logic for updating links on move'''

		# creating relative paths
		for source, href, link in (
			('Foo:Bar', 'Foo:Bar', 'Bar'),
			('Foo:Bar', 'Foo:Bar:Baz', '+Baz'),
			('Foo:Bar:Baz', 'Foo:Dus', 'Foo:Dus'),
			('Foo:Bar:Baz', 'Foo:Bar:Dus', 'Bar:Dus'),
			('Foo:Bar', 'Dus:Ja', ':Dus:Ja'),
		):
			#~ print '>', source, href, link
			self.assertEqual(
				self.notebook.relative_link(Path(source), Path(href)), link)

		# update the page that was moved itself
		# moving from Dus:Baz to Foo:Bar:Baz
		text = u'''\
http://foo.org # urls are untouched
[[:Hmmm:OK]] # link way outside move
[[Baz:Ja]] # relative link that does not need change
[[Dus:Ja]] # relative link that needs updating
[[Dus:Ja|Grrr]] # relative link that needs updating - with name
[[:Foo:Bar:Dus]] # Link that could be mde relative, but isn't
'''
		wanted = u'''\
http://foo.org # urls are untouched
[[:Hmmm:OK]] # link way outside move
[[Baz:Ja]] # relative link that does not need change
[[:Dus:Ja]] # relative link that needs updating
[[:Dus:Ja|Grrr]] # relative link that needs updating - with name
[[:Foo:Bar:Dus]] # Link that could be mde relative, but isn't
'''
		notebook, page = tests.get_test_page('Foo:Bar:Baz')
		page.parse('wiki', text)
		notebook._update_links_from(page, Path('Dus:Baz'))
		self.assertEqualDiff(u''.join(page.dump('wiki')), wanted)

		# updating links to the page that was moved
		# moving from Dus:Baz to Foo:Bar:Baz - updating links in Dus:Ja
		text = u'''\
http://foo.org # urls are untouched
[[:Hmmm:OK]] # link way outside move
[[Baz:Ja]] # relative link that needs updating
[[Baz:Ja|Grr]] # relative link that needs updating - with name
[[Dus:Foo]] # relative link that does not need updating
[[:Dus:Baz]] # absolute link that needs updating
[[:Dus:Baz:Hmm]] # absolute link that needs updating
[[:Dus:Baz:Hmm:Ja]] # absolute link that needs updating
'''
		wanted = u'''\
http://foo.org # urls are untouched
[[:Hmmm:OK]] # link way outside move
[[:Foo:Bar:Baz:Ja]] # relative link that needs updating
[[:Foo:Bar:Baz:Ja|Grr]] # relative link that needs updating - with name
[[Dus:Foo]] # relative link that does not need updating
[[:Foo:Bar:Baz]] # absolute link that needs updating
[[:Foo:Bar:Baz:Hmm]] # absolute link that needs updating
[[:Foo:Bar:Baz:Hmm:Ja]] # absolute link that needs updating
'''
		notebook, page = tests.get_test_page('Dus:Ja')
		page.parse('wiki', text)
		notebook._update_links_in_page(page, Path('Dus:Baz'), Path('Foo:Bar:Baz'))
		self.assertEqualDiff(u''.join(page.dump('wiki')), wanted)

		# now test actual move on full notebook
		def links(source, href):
			#~ print '===='
			for link in self.notebook.index.list_links(source, LINK_DIR_FORWARD):
				#~ print 'FOUND LINK', link
				if link.href == href:
					return True
			else:
				return False

		path = Path('Linking:Dus:Ja')
		self.assertTrue(links(path, Path('Linking:Dus')))
		self.assertTrue(links(path, Path('Linking:Foo:Bar')))
		self.assertTrue(links(Path('Linking:Foo:Bar'), path))

		newpath = Path('Linking:Hmm:Ok')
		self.assertFalse(links(newpath, Path('Linking:Dus')))
		self.assertFalse(links(newpath, Path('Linking:Foo:Bar')))
		self.assertFalse(links(Path('Linking:Foo:Bar'), newpath))
		self.notebook.move_page(path, newpath, update_links=True)
		self.assertTrue(links(newpath, Path('Linking:Dus')))
		self.assertTrue(links(newpath, Path('Linking:Foo:Bar')))
		self.assertTrue(links(Path('Linking:Foo:Bar'), newpath))
Пример #4
0
	def setUp(self):
		self.format = get_format('plain')
		notebook, self.page = get_test_page()
Пример #5
0
	def setUp(self):
		#~ TestTextFormat.setUp(self)
		self.format = get_format('wiki')
		notebook, self.page = get_test_page()
Пример #6
0
def get_tree(wikitext):
	tree = wiki.Parser().parse(wikitext)
	notebook, page = get_test_page()
	notebook.get_store(page).dir = Dir('/foo') # HACK
	tree.resolve_images(notebook, page)
	return tree