]> git.scottworley.com Git - paperdoorknob/blob - glowfic_test.py
d84733382a52a4f63692060e1b746d3bf9849796
[paperdoorknob] / glowfic_test.py
1 # paperdoorknob: Print glowfic
2 #
3 # This program is free software: you can redistribute it and/or modify it
4 # under the terms of the GNU General Public License as published by the
5 # Free Software Foundation, version 3.
6
7
8 import unittest
9
10 from bs4 import BeautifulSoup
11
12 from glowfic import chunkDOMs
13
14
15 class TestSplit(unittest.TestCase):
16
17 def testSplit1(self) -> None:
18 soup = BeautifulSoup(b'''
19 <html><body><div class="post-container post-post">
20 The "post"
21 </div></body></html>''', 'html.parser')
22 self.assertEqual([list(t.stripped_strings) for t in chunkDOMs(soup)],
23 [['The "post"']])
24
25 def testSplit2(self) -> None:
26 soup = BeautifulSoup(b'''
27 <html><body>
28 <div class="post-container post-post">The "post"</div>
29 <div class="flat-post-replies">
30 <div class="post-container post-reply">The "reply"</div>
31 </div>
32 </body></html>''', 'html.parser')
33 self.assertEqual([list(t.stripped_strings) for t in chunkDOMs(soup)],
34 [['The "post"'], ['The "reply"']])
35
36 def testSplit3(self) -> None:
37 soup = BeautifulSoup(b'''
38 <html><body>
39 <div class="post-container post-post">The "post"</div>
40 <div class="flat-post-replies">
41 <div class="post-container post-reply">1st reply</div>
42 <div class="post-container post-reply">2nd reply</div>
43 </div>
44 </body></html>''', 'html.parser')
45 self.assertEqual([list(t.stripped_strings) for t in chunkDOMs(soup)],
46 [['The "post"'], ['1st reply'], ['2nd reply']])
47
48
49 if __name__ == '__main__':
50 unittest.main()