From: Brett Parker Date: Sat, 5 Jan 2008 15:49:44 +0000 (+0000) Subject: * add missing source files for unit tests X-Git-Url: https://git.sommitrealweird.co.uk/rss2maildir.git/commitdiff_plain/64f951d0b32c3c210b71ef941e23b8dd98f13658?hp=0aa27bf39e80cd41081f4d5a49015e1c17ae9f68 * add missing source files for unit tests * small fix to paragraph handling --- 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()