]> git.sommitrealweird.co.uk Git - rss2maildir.git/commitdiff
* Add unittest for unordered list
authorBrett Parker <iDunno@sommitrealweird.co.uk>
Mon, 24 Dec 2007 11:38:12 +0000 (11:38 +0000)
committerBrett Parker <iDunno@sommitrealweird.co.uk>
Mon, 24 Dec 2007 11:38:12 +0000 (11:38 +0000)
* make sure that the string that we use for plain text always ends in a new
  line character

rss2maildir.py
tests/expected/unorderedlist-wellformed.txt [new file with mode: 0644]
tests/html/unorderedlist-wellformed.html [new file with mode: 0644]
tests/unittests/UnorderedListTests.py [new file with mode: 0644]

index 99735a70a8dd93957741b3c1c3a66e1cd3779171..80f22d57d6f6852ed9efbf1289b03590f9845f8f 100755 (executable)
@@ -249,6 +249,8 @@ class HTML2Text(HTMLParser):
         data = self.text
         if self.inparagraph:
             data = data + "\n".join(textwrap.wrap(self.currentparagraph, 70))
         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):
         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 (file)
index 0000000..6f37326
--- /dev/null
@@ -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 (file)
index 0000000..60793ee
--- /dev/null
@@ -0,0 +1,6 @@
+<p>This is a well formed unordered list.</p>
+<ul>
+    <li>The first item</li>
+    <li>The second item</li>
+    <li>The third item</li>
+</ul>
diff --git a/tests/unittests/UnorderedListTests.py b/tests/unittests/UnorderedListTests.py
new file mode 100644 (file)
index 0000000..af09b7c
--- /dev/null
@@ -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()