From 64f951d0b32c3c210b71ef941e23b8dd98f13658 Mon Sep 17 00:00:00 2001 From: Brett Parker Date: Sat, 5 Jan 2008 15:49:44 +0000 Subject: [PATCH] * add missing source files for unit tests * small fix to paragraph handling --- rss2maildir.py | 6 ++-- tests/expected/definitionlist-wellformed.txt | 6 ++++ tests/expected/multiparagraph-wellformed.txt | 6 ++++ tests/html/definitionlist-wellformed.html | 6 ++++ tests/html/multiparagraph-wellformed.html | 3 ++ tests/unittests/DefinitionListTests.py | 34 ++++++++++++++++++++ 6 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 tests/expected/definitionlist-wellformed.txt create mode 100644 tests/expected/multiparagraph-wellformed.txt create mode 100644 tests/html/definitionlist-wellformed.html create mode 100644 tests/html/multiparagraph-wellformed.html create mode 100755 tests/unittests/DefinitionListTests.py diff --git a/rss2maildir.py b/rss2maildir.py index 3e4ed60..a0c40a1 100755 --- a/rss2maildir.py +++ b/rss2maildir.py @@ -227,9 +227,9 @@ class HTML2Text(HTMLParser): elif self.inpre: self.text = self.text + unicode(data, "utf-8") else: - isallwhitespace = data.strip() - if isallwhitespace != "" and self.text[-1] == "\n": - self.text = self.text + unicode(data, "utf-8").strip() + u' ' + isallwhitespace = data.strip() == "" + if not isallwhitespace: + self.text = self.text + unicode(data, "utf-8").strip() + u' ' def handle_entityref(self, name): entity = name diff --git a/tests/expected/definitionlist-wellformed.txt b/tests/expected/definitionlist-wellformed.txt new file mode 100644 index 0000000..98beb1b --- /dev/null +++ b/tests/expected/definitionlist-wellformed.txt @@ -0,0 +1,6 @@ +An item + It's definition + +Another item + And it's got a much longer definition because we like to make sure + that we've got the test wrapping right don't we. diff --git a/tests/expected/multiparagraph-wellformed.txt b/tests/expected/multiparagraph-wellformed.txt new file mode 100644 index 0000000..0fa6cb5 --- /dev/null +++ b/tests/expected/multiparagraph-wellformed.txt @@ -0,0 +1,6 @@ +This is a paragraph + +This is a second paragraph + +This is a third paragraph, we'll deliberately make this over seventy +characters long so that it should wrap diff --git a/tests/html/definitionlist-wellformed.html b/tests/html/definitionlist-wellformed.html new file mode 100644 index 0000000..76a1738 --- /dev/null +++ b/tests/html/definitionlist-wellformed.html @@ -0,0 +1,6 @@ +
+
An item
+
It's definition
+
Another item
+
And it's got a much longer definition because we like to make sure that we've got the test wrapping right don't we.
+
diff --git a/tests/html/multiparagraph-wellformed.html b/tests/html/multiparagraph-wellformed.html new file mode 100644 index 0000000..71ef1c2 --- /dev/null +++ b/tests/html/multiparagraph-wellformed.html @@ -0,0 +1,3 @@ +

This is a paragraph

+

This is a second paragraph

+

This is a third paragraph, we'll deliberately make this over seventy characters long so that it should wrap

diff --git a/tests/unittests/DefinitionListTests.py b/tests/unittests/DefinitionListTests.py new file mode 100755 index 0000000..9058973 --- /dev/null +++ b/tests/unittests/DefinitionListTests.py @@ -0,0 +1,34 @@ +#!/usr/bin/python + +import unittest +import sys +import os + +class DefinitionListTests(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 testWellFormedDefinitionList(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", "definitionlist-wellformed.html")).read() + expectedoutput = open(os.path.join(input_path, "expected", "definitionlist-wellformed.txt")).read() + parser = HTML2Text() + parser.feed(input) + output = parser.gettext() + self.assertEqual(output, expectedoutput) + +def suite(): + suite = unittest.TestSuite() + suite.addTest(DefinitionListTests("testWellFormedDefinitionList")) + return suite + +if __name__ == "__main__": + unittest.main() -- 2.39.5