Back to index

moin  1.9.0~rc2
test_filter.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - tests for MoinMoin.filter module
00004 
00005     @copyright: 2007 by MoinMoin:ThomasWaldmann
00006     @license: GNU GPL, see COPYING for details.
00007 """
00008 
00009 import py
00010 from MoinMoin import filter
00011 
00012 class TestFilters:
00013 
00014     def make_file(self, data):
00015         import tempfile
00016         fname = tempfile.mktemp()
00017         f = file(fname, 'wb')
00018         f.write(data)
00019         f.close()
00020         return fname
00021 
00022     def testBinaryGeneric(self):
00023         from MoinMoin.filter.application_octet_stream import execute as _filter
00024         tests = [('', ''),
00025                  ('this\x00is\x00a\x00test\x00', u'this test'), # throws away short stuff
00026                 ]
00027         for data, expected in tests:
00028             fname = self.make_file(data)
00029             assert _filter(None, fname) == expected
00030 
00031     def testTextGeneric(self):
00032         from MoinMoin.filter.text import execute as _filter
00033         tests = [('', ''),
00034                  ('asdf\r\nghjk', u'asdf\r\nghjk'),
00035                  # add some tests with umlauts in diff. encodings
00036                 ]
00037         for data, expected in tests:
00038             fname = self.make_file(data)
00039             assert _filter(None, fname) == expected
00040 
00041     def testTextHtml(self):
00042         from MoinMoin.filter.text_html import execute as _filter
00043         tests = [('', ''),
00044                  ('<html><body>Hello<br>World!</body></html>', u'Hello World!'),
00045                 ]
00046         for data, expected in tests:
00047             fname = self.make_file(data)
00048             assert _filter(None, fname) == expected
00049 
00050     def testTextXml(self):
00051         from MoinMoin.filter.text_xml import execute as _filter
00052         tests = [('', ''),
00053                  ('<xml><para>Hello</para><para>World!</para></xml>', u'Hello World!'),
00054                 ]
00055         for data, expected in tests:
00056             fname = self.make_file(data)
00057             assert _filter(None, fname) == expected
00058 
00059 coverage_modules = ['MoinMoin.filter.text',
00060                     'MoinMoin.filter.text_html',
00061                     'MoinMoin.filter.text_xml',
00062                     'MoinMoin.filter.application_octet_stream',
00063                    ]
00064