From 0aa27bf39e80cd41081f4d5a49015e1c17ae9f68 Mon Sep 17 00:00:00 2001 From: Brett Parker Date: Sat, 5 Jan 2008 13:00:48 +0000 Subject: [PATCH] * add (first draft of) full test suite runner * add test for well formed paragraph handling * update UnorderedListTests to have better test naming scheme * add suite function to UnorderedListTests --- tests/runtests.py | 34 +++++++++++++++++++++++++++ tests/unittests/ParagraphTests.py | 34 +++++++++++++++++++++++++++ tests/unittests/UnorderedListTests.py | 10 ++++++-- tests/unittests/__init__.py | 0 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100755 tests/runtests.py create mode 100755 tests/unittests/ParagraphTests.py create mode 100644 tests/unittests/__init__.py diff --git a/tests/runtests.py b/tests/runtests.py new file mode 100755 index 0000000..3af3248 --- /dev/null +++ b/tests/runtests.py @@ -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 index 0000000..9111ecd --- /dev/null +++ b/tests/unittests/ParagraphTests.py @@ -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() diff --git a/tests/unittests/UnorderedListTests.py b/tests/unittests/UnorderedListTests.py index 4d2c393..2224e74 100755 --- a/tests/unittests/UnorderedListTests.py +++ b/tests/unittests/UnorderedListTests.py @@ -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 index 0000000..e69de29 -- 2.39.5