changeset 2452:839b360413a9

tests: add some basic filter tests
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 20 Jul 2007 23:53:59 +0200
parents ac7f57165c9a
children adf5ec4874ed 0c66cfd93cd9
files MoinMoin/filter/_tests/test_filter.py
diffstat 1 files changed, 64 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/filter/_tests/test_filter.py	Fri Jul 20 23:53:59 2007 +0200
@@ -0,0 +1,64 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - tests for MoinMoin.filter module
+
+    @copyright: 2007 by MoinMoin:ThomasWaldmann
+    @license: GNU GPL, see COPYING for details.
+"""
+
+import py
+from MoinMoin import filter
+
+class TestFilters:
+
+    def make_file(self, data):
+        import tempfile
+        fname = tempfile.mktemp()
+        f = file(fname, 'w')
+        f.write(data)
+        f.close()
+        return fname
+
+    def testBinaryGeneric(self):
+        from MoinMoin.filter.application_octet_stream import execute as _filter
+        tests = [('', ''),
+                 ('this\x00is\x00a\x00test\x00', u'this test'), # throws away short stuff
+                ]
+        for data, expected in tests:
+            fname = self.make_file(data)
+            assert _filter(None, fname) == expected
+
+    def testTextGeneric(self):
+        from MoinMoin.filter.text import execute as _filter
+        tests = [('', ''),
+                 ('asdf\r\nghjk', u'asdf\r\nghjk'),
+                 # add some tests with umlauts in diff. encodings
+                ]
+        for data, expected in tests:
+            fname = self.make_file(data)
+            assert _filter(None, fname) == expected
+
+    def testTextHtml(self):
+        from MoinMoin.filter.text_html import execute as _filter
+        tests = [('', ''),
+                 ('<html><body>Hello<br>World!</body></html>', u'Hello World!'),
+                ]
+        for data, expected in tests:
+            fname = self.make_file(data)
+            assert _filter(None, fname) == expected
+
+    def testTextXml(self):
+        from MoinMoin.filter.text_xml import execute as _filter
+        tests = [('', ''),
+                 ('<xml><para>Hello</para><para>World!</para></xml>', u'Hello World!'),
+                ]
+        for data, expected in tests:
+            fname = self.make_file(data)
+            assert _filter(None, fname) == expected
+
+coverage_modules = ['MoinMoin.filter.text',
+                    'MoinMoin.filter.text_html',
+                    'MoinMoin.filter.text_xml',
+                    'MoinMoin.filter.application_octet_stream',
+                   ]
+