Attachment 'test_parser_unicode.py'
Download 1 # -*- coding: utf-8 -*-
2 """
3 MoinMoin - Test if MoinMoin.parser.* do write UNICODE objects
4
5 @copyright: 2007 by Raphael Bossek <raphael.bossek@gmx.de>
6 @license: GNU GPL, see COPYING for details.
7 """
8
9 import unittest, sys, traceback
10 import MoinMoin.parser
11 from MoinMoin.Page import Page
12 from MoinMoin._tests import TestConfig
13
14 class TextParserOutput(unittest.TestCase):
15 """Parser has to generate unicode output.
16 """
17 def testParserOutput(self):
18 """MoinMoin.parser.text_xslt: Is generated output an unicode object...
19 """
20 self.assertEqual(self.request.cfg.allow_xslt, False, u'allow_xslt should be disabled')
21 errmsg = []
22 # Some examples we verify.
23 parser_raw_input = {
24 u'text_html': u'<html><body><h1>%s</h1></body></html>',
25 u'text_irssi': u"[12:01] <RaphaelBosek> %s",
26 u'text_moin_wiki': u'||<#fefefe> %s ||',
27 u'text_python': u'if True: print "%s"',
28 u'text_xslt': u'<?xml version="1.0" encoding="ISO-8859-1"?><!-- %s -->',
29 }
30
31 # Create a page if not already exists.
32 if not u'page' in self.request.formatter.__dict__ or not self.request.formatter.page:
33 self.request.formatter.page = Page(self.request, u'test_parser_unicode_page')
34
35 # Check all parsers for UNICODE output.
36 for parsername in MoinMoin.parser.modules:
37 module = __import__(u'MoinMoin.parser', globals(), {}, [parsername])
38 parsermodule = getattr(module, parsername)
39 if u'Parser' in parsermodule.__dict__:
40 i = parser_raw_input.get(parsername, u'%s') % u'\xC3\x84\xC3\x96\xC3\x9C\xC3\xE2\x82\xAC\x27'
41 p = parsermodule.Parser(i, self.request)
42 try:
43 r = self.request.redirectedOutput(p.format, self.request.formatter)
44 except Exception, e:
45 sys.stderr.write(u"from MoinMoin.parser import " + parsername + u"\n")
46 raise
47
48 if isinstance(r, str):
49 o = u'MoinMoin.parser.%s write string data instead of UNICODE: %s' % (parsername, r.encode(),)
50 errmsg.append(o)
51 elif not isinstance(r, unicode):
52 o = u'MoinMoin.parser.%s does not write UNICODE data: %s' % (parsername, type(r),)
53 errmsg.append(o)
54
55 if errmsg:
56 o = u"\n" + u"\n".join(errmsg)
57 self.fail(o.encode(sys.stdout.encoding))
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.