From: Brett Parker Date: Mon, 24 Dec 2007 11:38:12 +0000 (+0000) Subject: * Add unittest for unordered list X-Git-Url: https://git.sommitrealweird.co.uk/rss2maildir.git/commitdiff_plain/738dfe9c90cc9a357a5236a77281be87c90a13e1?hp=fb3a7e40f413322d90b5452acc7c3a8f09046661 * Add unittest for unordered list * make sure that the string that we use for plain text always ends in a new line character --- diff --git a/rss2maildir.py b/rss2maildir.py index 99735a7..80f22d5 100755 --- a/rss2maildir.py +++ b/rss2maildir.py @@ -249,6 +249,8 @@ class HTML2Text(HTMLParser): data = self.text if self.inparagraph: data = data + "\n".join(textwrap.wrap(self.currentparagraph, 70)) + if data[-1] != '\n': + data = data + '\n' return data def open_url(method, url): diff --git a/tests/expected/unorderedlist-wellformed.txt b/tests/expected/unorderedlist-wellformed.txt new file mode 100644 index 0000000..6f37326 --- /dev/null +++ b/tests/expected/unorderedlist-wellformed.txt @@ -0,0 +1,5 @@ +This is a well formed unordered list. + * The first item + * The second item + * The third item + diff --git a/tests/html/unorderedlist-wellformed.html b/tests/html/unorderedlist-wellformed.html new file mode 100644 index 0000000..60793ee --- /dev/null +++ b/tests/html/unorderedlist-wellformed.html @@ -0,0 +1,6 @@ +

This is a well formed unordered list.

+ diff --git a/tests/unittests/UnorderedListTests.py b/tests/unittests/UnorderedListTests.py new file mode 100644 index 0000000..af09b7c --- /dev/null +++ b/tests/unittests/UnorderedListTests.py @@ -0,0 +1,29 @@ +#!/usr/bin/python + +import unittest +import sys +import os + +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): + 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", "unorderedlist-wellformed.html")).read() + expectedoutput = open(os.path.join(input_path, "expected", "unorderedlist-wellformed.txt")).read() + parser = HTML2Text() + parser.feed(input) + output = parser.gettext() + self.assertEqual(output, expectedoutput) + +if __name__ == "__main__": + unittest.main()