* add missing source files for unit tests
authorBrett Parker <iDunno@sommitrealweird.co.uk>
Sat, 5 Jan 2008 15:49:44 +0000 (15:49 +0000)
committerBrett Parker <iDunno@sommitrealweird.co.uk>
Sat, 5 Jan 2008 15:49:44 +0000 (15:49 +0000)
* small fix to paragraph handling

rss2maildir.py
tests/expected/definitionlist-wellformed.txt [new file with mode: 0644]
tests/expected/multiparagraph-wellformed.txt [new file with mode: 0644]
tests/html/definitionlist-wellformed.html [new file with mode: 0644]
tests/html/multiparagraph-wellformed.html [new file with mode: 0644]
tests/unittests/DefinitionListTests.py [new file with mode: 0755]

index 3e4ed605d1eaa7669e1faccd25904449d2a6596b..a0c40a1513e064b56166bab45e2cc294db3164e1 100755 (executable)
@@ -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 (file)
index 0000000..98beb1b
--- /dev/null
@@ -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 (file)
index 0000000..0fa6cb5
--- /dev/null
@@ -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 (file)
index 0000000..76a1738
--- /dev/null
@@ -0,0 +1,6 @@
+<dl>
+    <dt>An item</dt>
+    <dd>It's definition</dd>
+    <dt>Another item</dt>
+    <dd>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.</dd>
+</dl>
diff --git a/tests/html/multiparagraph-wellformed.html b/tests/html/multiparagraph-wellformed.html
new file mode 100644 (file)
index 0000000..71ef1c2
--- /dev/null
@@ -0,0 +1,3 @@
+<p>This is a paragraph</p>
+<p>This is a second paragraph</p>
+<p>This is a third paragraph, we'll deliberately make this over seventy characters long so that it should wrap</p>
diff --git a/tests/unittests/DefinitionListTests.py b/tests/unittests/DefinitionListTests.py
new file mode 100755 (executable)
index 0000000..9058973
--- /dev/null
@@ -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()