2224e74427b952556a2235f1ca3133402f0d8990
[rss2maildir.git] / tests / unittests / UnorderedListTests.py
1 #!/usr/bin/python
2
3 import unittest
4 import sys
5 import os
6
7 class UnorderedListTests(unittest.TestCase):
8     def setUp(self):
9         self.inputpath = os.path.sep.join(os.path.dirname(os.path.realpath(__file__)).split(os.path.sep)[0:-1])
10
11     def testWellFormedList(self):
12         try:
13             from rss2maildir import HTML2Text
14         except:
15             sys.path.append(os.path.sep.join(self.inputpath.split(os.path.sep)[0:-1]))
16             try:
17                 from rss2maildir import HTML2Text
18             except:
19                 self.assert_(False)
20         input_path = os.path.sep.join(os.path.dirname(os.path.realpath(__file__)).split(os.path.sep)[0:-1])
21         input = open(os.path.join(input_path, "html", "unorderedlist-wellformed.html")).read()
22         expectedoutput = open(os.path.join(input_path, "expected", "unorderedlist-wellformed.txt")).read()
23         parser = HTML2Text()
24         parser.feed(input)
25         output = parser.gettext()
26         self.assertEqual(output, expectedoutput)
27
28     def testBadlyFormedList(self):
29         try:
30             from rss2maildir import HTML2Text
31         except:
32             sys.path.append(os.path.sep.join(self.inputpath.split(os.path.sep)[0:-1]))
33             try:
34                 from rss2maildir import HTML2Text
35             except:
36                 self.assert_(False)
37
38         input_path = os.path.sep.join(os.path.dirname(os.path.realpath(__file__)).split(os.path.sep)[0:-1])
39         input = open(os.path.join(input_path, "html", "unorderedlist-badlyformed.html")).read()
40         expectedoutput = open(os.path.join(input_path, "expected", "unorderedlist-badlyformed.txt")).read()
41         parser = HTML2Text()
42         parser.feed(input)
43         output = parser.gettext()
44         self.assertEqual(output, expectedoutput)
45
46 def suite():
47     suite = unittest.TestSuite()
48     suite.addTest(UnorderedListTests("testWellFormedList"))
49     suite.addTest(UnorderedListTests("testBadlyFormedList"))
50     return suite
51
52 if __name__ == "__main__":
53     unittest.main()