From 738dfe9c90cc9a357a5236a77281be87c90a13e1 Mon Sep 17 00:00:00 2001 From: Brett Parker Date: Mon, 24 Dec 2007 11:38:12 +0000 Subject: [PATCH] * Add unittest for unordered list * make sure that the string that we use for plain text always ends in a new line character --- rss2maildir.py | 2 ++ tests/expected/unorderedlist-wellformed.txt | 5 ++++ tests/html/unorderedlist-wellformed.html | 6 +++++ tests/unittests/UnorderedListTests.py | 29 +++++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 tests/expected/unorderedlist-wellformed.txt create mode 100644 tests/html/unorderedlist-wellformed.html create mode 100644 tests/unittests/UnorderedListTests.py 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() -- 2.39.5