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.
  • [get | view] (2009-03-01 11:39:57, 0.9 KB) [[attachment:1_9-devel_local_server_config.bundle]]
  • [get | view] (2007-07-27 20:50:57, 12.4 KB) [[attachment:IncludeWithAttachment20070727.py]]
  • [get | view] (2007-09-25 12:38:06, 18.2 KB) [[attachment:raphaelbossek.jpg]]
  • [get | view] (2007-08-15 20:55:02, 2.5 KB) [[attachment:test_parser_unicode.py]]
  • [get | view] (2007-07-27 20:49:55, 1.4 KB) [[attachment:text_xslt.patch]]
  • [get | view] (2007-08-10 20:44:42, 1.7 KB) [[attachment:text_xslt.py.txt]]
  • [get | view] (2007-08-09 20:16:03, 2.3 KB) [[attachment:utf8bug.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.