Back to index

moin  1.9.0~rc2
test_text_csv.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - MoinMoin.parser.text_csv Tests
00004 
00005     @copyright: 2008 by MoinMoin:ReimarBauer
00006     @license: GNU GPL, see COPYING for details.
00007 """
00008 
00009 import re
00010 from StringIO import StringIO
00011 
00012 import py
00013 
00014 from MoinMoin.Page import Page
00015 from MoinMoin.parser.text_csv import Parser as CSV_Parser
00016 from MoinMoin.formatter.text_html import Formatter as HtmlFormatter
00017 
00018 PAGENAME = u'ThisPageDoesNotExistsAndWillNeverBeReally'
00019 
00020 class ParserTestCase(object):
00021     """ Helper class that provide a parsing method """
00022 
00023     def parse(self, body):
00024         """Parse body and return html
00025 
00026         Create a page with body, then parse it and format using html formatter
00027         """
00028         request = self.request
00029         assert body is not None
00030         request.reset()
00031         page = Page(request, PAGENAME)
00032         page.hilite_re = None
00033         page.set_raw_body(body)
00034         formatter = HtmlFormatter(request)
00035         formatter.setPage(page)
00036         page.formatter = formatter
00037         request.page = page
00038         request.formatter = formatter
00039         parser = CSV_Parser(body, request, line_anchors=False)
00040         formatter.startContent('') # needed for _include_stack init
00041         output = request.redirectedOutput(parser.format, formatter)
00042         formatter.endContent('')
00043         return output
00044 
00045 class TestDelimiters(ParserTestCase):
00046 
00047     def testdelimiters(self):
00048         """ parser.text_csv: delimiter , """
00049         result = self.parse('a,b')
00050         assert '<td class="hcolumn0"><strong>a</strong></td>' in  result and '<td class="hcolumn1"><strong>b</strong></td>' in  result
00051 
00052     def testemptyline(self):
00053         """ parser.text_csv: empty line """
00054         result = self.parse('')
00055         assert '<tbody><tr></tr>\n</tbody>' in  result
00056 
00057     def testnodelimiter(self):
00058         """ parser.text_csv: line without delimiter """
00059         result = self.parse('ABCDEFGHIJ')
00060         assert '<td class="hcolumn0"><strong>ABCDEFGHIJ</strong></td>' in  result
00061 
00062 coverage_modules = ['MoinMoin.parser.text_csv']
00063