* add (first draft of) full test suite runner
authorBrett Parker <iDunno@sommitrealweird.co.uk>
Sat, 5 Jan 2008 13:00:48 +0000 (13:00 +0000)
committerBrett Parker <iDunno@sommitrealweird.co.uk>
Sat, 5 Jan 2008 13:00:48 +0000 (13:00 +0000)
* add test for well formed paragraph handling
* update UnorderedListTests to have better test naming scheme
* add suite function to UnorderedListTests

tests/runtests.py [new file with mode: 0755]
tests/unittests/ParagraphTests.py [new file with mode: 0755]
tests/unittests/UnorderedListTests.py
tests/unittests/__init__.py [new file with mode: 0644]

diff --git a/tests/runtests.py b/tests/runtests.py
new file mode 100755 (executable)
index 0000000..3af3248
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/python
+
+import unittest
+import os
+
+basedir = os.path.realpath(os.path.dirname(__file__))
+unittestsdir = os.path.join( \
+    basedir, \
+    "unittests")
+
+unittestmodules = []
+
+fullsuite = unittest.TestSuite()
+
+# walk our directory tree looking for any modules available
+for root, dir, files in os.walk(unittestsdir):
+    for file in files:
+        if file[-3:] == ".py" and file != "__init__.py":
+            moduleinfo = ".".join(root[len(basedir)+1:].split(os.sep))
+            unittestmodules.append(".".join((moduleinfo, file[0:-3])))
+
+# run through the found modules and look for test suites
+for unittestmodule in unittestmodules:
+    # try importing the test and getting the suite
+    try:
+        suite_func = getattr(__import__(unittestmodule, {}, {}, ['']), "suite")
+        # add the suite to the tests
+        fullsuite.addTest(suite_func())
+    except:
+        # there was not test suite in there to run, skip it
+        pass
+
+testrunner = unittest.TextTestRunner()
+testrunner.run(fullsuite)
diff --git a/tests/unittests/ParagraphTests.py b/tests/unittests/ParagraphTests.py
new file mode 100755 (executable)
index 0000000..9111ecd
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/python
+
+import unittest
+import sys
+import os
+
+class ParagraphTests(unittest.TestCase):
+    def setUp(self):
+        self.inputpath = os.path.sep.join(os.path.dirname(os.path.realpath(__file__)).split(os.path.sep)[0:-1])
+
+    def testWellFormedParagraphs(self):
+        try:
+            from rss2maildir import HTML2Text
+        except:
+            sys.path.append(os.path.sep.join(self.inputpath.split(os.path.sep)[0:-1]))
+            try:
+                from rss2maildir import HTML2Text
+            except:
+                self.assert_(False)
+        input_path = os.path.sep.join(os.path.dirname(os.path.realpath(__file__)).split(os.path.sep)[0:-1])
+        input = open(os.path.join(input_path, "html", "multiparagraph-wellformed.html")).read()
+        expectedoutput = open(os.path.join(input_path, "expected", "multiparagraph-wellformed.txt")).read()
+        parser = HTML2Text()
+        parser.feed(input)
+        output = parser.gettext()
+        self.assertEqual(output, expectedoutput)
+
+def suite():
+    suite = unittest.TestSuite()
+    suite.addTest(ParagraphTests("testWellFormedParagraphs"))
+    return suite
+
+if __name__ == "__main__":
+    unittest.main()
index 4d2c393add11c614a9b026ea710e9f6c083ed147..2224e74427b952556a2235f1ca3133402f0d8990 100755 (executable)
@@ -8,7 +8,7 @@ class UnorderedListTests(unittest.TestCase):
     def setUp(self):
         self.inputpath = os.path.sep.join(os.path.dirname(os.path.realpath(__file__)).split(os.path.sep)[0:-1])
 
-    def testwellformedlist(self):
+    def testWellFormedList(self):
         try:
             from rss2maildir import HTML2Text
         except:
@@ -25,7 +25,7 @@ class UnorderedListTests(unittest.TestCase):
         output = parser.gettext()
         self.assertEqual(output, expectedoutput)
 
-    def testbadlyformed(self):
+    def testBadlyFormedList(self):
         try:
             from rss2maildir import HTML2Text
         except:
@@ -43,5 +43,11 @@ class UnorderedListTests(unittest.TestCase):
         output = parser.gettext()
         self.assertEqual(output, expectedoutput)
 
+def suite():
+    suite = unittest.TestSuite()
+    suite.addTest(UnorderedListTests("testWellFormedList"))
+    suite.addTest(UnorderedListTests("testBadlyFormedList"))
+    return suite
+
 if __name__ == "__main__":
     unittest.main()
diff --git a/tests/unittests/__init__.py b/tests/unittests/__init__.py
new file mode 100644 (file)
index 0000000..e69de29