Back to index

moin  1.9.0~rc2
test_formatter.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - MoinMoin.formatter.* Tests
00004 
00005     @copyright: 2005 by MoinMoin:AlexanderSchremmer
00006     @license: GNU GPL, see COPYING for details.
00007 """
00008 
00009 import py
00010 
00011 from MoinMoin.Page import Page
00012 from MoinMoin import wikiutil
00013 
00014 
00015 class TestFormatter:
00016     def testSyntaxReferenceDomXml(self):
00017         py.test.skip("domxml <p> generation is broken")
00018         f_name = 'dom_xml'
00019         try:
00020             formatter = wikiutil.importPlugin(self.request.cfg, "formatter", f_name, "Formatter")
00021         except wikiutil.PluginAttributeError:
00022             pass
00023         else:
00024             print "Formatting using %r" % formatter
00025             self.formatPage("HelpOnMoinWikiSyntax", formatter)
00026             print "Done."
00027 
00028     def testSyntaxReferenceDocBook(self):
00029         py.test.skip("docbook is broken")
00030         try:
00031             from xml.dom import getDOMImplementation
00032             dom = getDOMImplementation("4DOM")
00033         except ImportError:
00034             # if we don't have 4suite installed, the docbook formatter would just raise an exception
00035             py.test.skip("not testing docbook formatter because no 4suite installed")
00036         else:
00037             f_name = 'text_docbook'
00038             try:
00039                 formatter = wikiutil.importPlugin(self.request.cfg, "formatter", f_name, "Formatter")
00040             except wikiutil.PluginAttributeError:
00041                 pass
00042             else:
00043                 print "Formatting using %r" % formatter
00044                 self.formatPage("HelpOnMoinWikiSyntax", formatter)
00045                 print "Done."
00046 
00047     def testSyntaxReferenceOthers(self):
00048         formatters = wikiutil.getPlugins("formatter", self.request.cfg)
00049 
00050         # we have separate tests for those:
00051         formatters.remove('text_docbook')
00052         formatters.remove('dom_xml')
00053 
00054         for f_name in formatters:
00055             try:
00056                 formatter = wikiutil.importPlugin(self.request.cfg, "formatter", f_name, "Formatter")
00057             except wikiutil.PluginAttributeError:
00058                 pass
00059             else:
00060                 print "Formatting using %r" % formatter
00061                 self.formatPage("HelpOnMoinWikiSyntax", formatter)
00062                 print "Done."
00063 
00064     def formatPage(self, pagename, formatter):
00065         """Parse a page. Should not raise an exception if the API of the
00066         formatter is correct.
00067         """
00068 
00069         self.request.reset()
00070         page = Page(self.request, pagename, formatter=formatter)
00071         self.request.formatter = page.formatter = formatter(self.request)
00072         self.request.page = page
00073         #page.formatter.setPage(page)
00074         #page.hilite_re = None
00075 
00076         return self.request.redirectedOutput(page.send_page, content_only=1)
00077 
00078 
00079 class TestIdIdempotency:
00080     def test_sanitize_to_id_idempotent(self):
00081         def _verify(formatter, id):
00082             origid = formatter.sanitize_to_id(id)
00083             id = origid
00084             for i in xrange(3):
00085                 id = formatter.sanitize_to_id(id)
00086                 assert id == origid
00087 
00088         formatters = wikiutil.getPlugins("formatter", self.request.cfg)
00089         try:
00090             from xml.dom import getDOMImplementation
00091             dom = getDOMImplementation("4DOM")
00092         except ImportError:
00093             # if we don't have 4suite installed, the docbook formatter would just raise an exception
00094             formatters.remove('text_docbook')
00095 
00096         testids = [
00097             r"tho/zeequeen&angu\za",
00098             r"quuirahz\iphohsaij,i",
00099             r"ashuifa+it[ohchieque",
00100             r"ohyie-lakoo`duaghaib",
00101             r"eixaepumuqu[ie\ba|eh",
00102             r"theegieque;zahmeitie",
00103             r"pahcooje&rahkeiz$oez",
00104             r"ohjeeng*iequao%fai?p",
00105             r"ahfoodahmepooquepee;",
00106             r"ubed_aex;ohwebeixah%",
00107             r"eitiekicaejuelae=g^u",
00108             r"",
00109             r'  ',
00110             r'--123',
00111             r'__$$',
00112             r'@@',
00113             u'\xf6\xf6llasdf\xe4',
00114         ]
00115 
00116         for f_name in formatters:
00117             try:
00118                 formatter = wikiutil.importPlugin(self.request.cfg, "formatter",
00119                                                   f_name, "Formatter")
00120                 f = formatter(self.request)
00121                 for id in testids:
00122                     yield _verify, f, id
00123             except wikiutil.PluginAttributeError:
00124                 pass
00125 
00126 coverage_modules = ['MoinMoin.formatter',
00127                     'MoinMoin.formatter.text_html',
00128                     'MoinMoin.formatter.text_gedit',
00129                     'MoinMoin.formatter.text_xml',
00130                     'MoinMoin.formatter.text_docbook',
00131                     'MoinMoin.formatter.text_plain',
00132                     'MoinMoin.formatter.dom_xml',
00133                     'MoinMoin.formatter.text_python',
00134                     'MoinMoin.formatter.pagelinks',
00135                     'MoinMoin.formtter.groups',
00136                    ]
00137