File: sourceview.py

package info (click to toggle)
zim 0.68-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 8,032 kB
  • sloc: python: 59,144; xml: 731; makefile: 45; sh: 35
file content (52 lines) | stat: -rw-r--r-- 1,329 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-

# Copyright 2014 Jaap Karssenberg <jaap.karssenberg@gmail.com>

from __future__ import with_statement

import tests

from tests.plugins import MockWindow

from zim.formats import ParseTree, StubLinker
from zim.formats.html import Dumper as HtmlDumper

from zim.plugins.sourceview import *


class TestMainWindowExtension(tests.TestCase):

	def runTest(self):
		window = MockWindow()
		plugin = SourceViewPlugin()
		extension = MainWindowExtension(plugin, window)

		with tests.DialogContext(self.checkInsertCodeBlockDialog):
			extension.insert_sourceview()

		tree = window.pageview.get_parsetree()
		#~ print tree.tostring()
		obj = tree.find('object')
		self.assertTrue(obj.attrib['type'] == 'code')

	def checkInsertCodeBlockDialog(self, dialog):
		self.assertIsInstance(dialog, InsertCodeBlockDialog)
		dialog.form['lang'] = LANGUAGES.keys()[0]
		dialog.assert_response_ok()


class TestSourceViewObject(tests.TestCase):

	def testDumpHtml(self):
		xml = '''\
<?xml version='1.0' encoding='utf-8'?>
<zim-tree><object lang="python" linenumbers="false" type="code">
def foo(a, b):
	print "FOO", a >= b

</object></zim-tree>'''
		tree = ParseTree().fromstring(xml)
		dumper = HtmlDumper(StubLinker())
		html = dumper.dump(tree)
		#~ print '>>', html
		self.assertIn('\tprint "FOO", a &gt;= b\n', html)