~bkidwell/zim/pyzim-win-installer

« back to all changes in this revision

Viewing changes to tests/gui.py

  • Committer: Jaap Karssenberg
  • Date: 2011-01-16 18:05:42 UTC
  • Revision ID: pardus@cpan.org-20110116180542-2y6upd4ccqrej3ug
polished previous commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 
13
13
        def runTest(self):
14
14
                '''Test clipboard interaction'''
15
 
                from zim.gui.clipboard import Clipboard
 
15
                from zim.gui.clipboard import *
16
16
                clipboard = Clipboard()
17
17
 
 
18
                # tree -> ..
18
19
                notebook = get_test_notebook()
19
20
                page = notebook.get_page(Path('Test:wiki'))
20
21
                parsetree = page.get_parsetree()
 
22
 
21
23
                clipboard.set_parsetree(notebook, page, parsetree)
22
24
                newtree = clipboard.request_parsetree(None, block=True)
23
25
                self.assertEqual(newtree.tostring(), parsetree.tostring())
24
26
 
 
27
                import zim.formats
 
28
                text = 'some **bold** text'
 
29
                parsetree = zim.formats.get_format('plain').Parser().parse(text.decode('utf-8'))
 
30
                clipboard.set_parsetree(notebook, page, parsetree)
 
31
 
 
32
                wanted = 'some **bold** text\n'
 
33
                text = clipboard.wait_for_text()
 
34
                self.assertEqualDiff(text, wanted)
 
35
 
 
36
                wanted = '''\
 
37
<html>
 
38
<head>
 
39
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
 
40
<meta name="Description" content="Copy-Paste Buffer">
 
41
<meta name="Generator" content="Zim">
 
42
</head>
 
43
<body>
 
44
<p>
 
45
some <strong>bold</strong> text<br>
 
46
</p>
 
47
 
 
48
</body>
 
49
</html>
 
50
'''
 
51
                selection = clipboard.wait_for_contents('text/html')
 
52
                self.assertEqualDiff(selection.data, wanted)
 
53
 
 
54
                wanted = '''\
 
55
Version:1.0\r
 
56
StartHTML:000000185\r
 
57
EndHTML:000000527\r
 
58
StartFragment:000000450\r
 
59
EndFragment:000000495\r
 
60
StartSelection:000000450\r
 
61
EndSelection:000000495\r
 
62
SourceURL:zim://copy-pase-buffer\r
 
63
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><meta http-equiv="Content-Type" content="text/html;charset=utf-8">
 
64
<meta name="Description" content="Copy-Paste Buffer">
 
65
<meta name="Generator" content="Zim"></HEAD><BODY><!--StartFragment--><p>
 
66
some <strong>bold</strong> text<br>
 
67
</p>
 
68
<!--EndFragment--></BODY></HTML>'''
 
69
                selection = clipboard.wait_for_contents('HTML Format')
 
70
                self.assertEqualDiff(selection.data, wanted)
 
71
 
 
72
 
 
73
                # pagelink -> ..
 
74
                clipboard.set_pagelink(notebook, page)
 
75
 
 
76
                selection = clipboard.wait_for_contents(INTERNAL_PAGELIST_TARGET_NAME)
 
77
                self.assertEqual(selection.data, 'Test:wiki\r\n')
 
78
 
 
79
                selection = clipboard.wait_for_contents(PAGELIST_TARGET_NAME)
 
80
                self.assertEqual(selection.data, 'Unnamed Notebook?Test:wiki\r\n')
 
81
 
25
82
                wanted = '''\
26
83
<?xml version=\'1.0\' encoding=\'utf-8\'?>\n<zim-tree><link href="Test:wiki">Test:wiki</link></zim-tree>'''
27
 
                clipboard.set_pagelink(notebook, page)
 
84
                newtree = clipboard.request_parsetree(None, block=True)
 
85
                self.assertEqual(newtree.tostring(), wanted)
 
86
 
 
87
                text = clipboard.wait_for_text()
 
88
                self.assertEqual(text, 'Test:wiki')
 
89
 
 
90
                # text -> tree
 
91
                wanted = '''\
 
92
<?xml version='1.0' encoding='utf-8'?>\n<zim-tree>some string</zim-tree>'''
 
93
                clipboard.set_text('some string')
28
94
                newtree = clipboard.request_parsetree(None, block=True)
29
95
                self.assertEqual(newtree.tostring(), wanted)
30
96