]> git.scottworley.com Git - paperdoorknob/blob - domfilter_test.py
Apply bare-\emph fix to \st too
[paperdoorknob] / domfilter_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 domfilter import ApplyDOMFilters
13
14
15 class TestDOMFilters(unittest.TestCase):
16
17 def setUp(self) -> None:
18 self._html = BeautifulSoup(b'''
19 <div class="post-container post-post">
20 <div class="post-edit-box">This is the edit box</div>
21 This is glowfic
22 <div class="post-footer">This is the footer</div>
23 </div>''', 'html.parser')
24 self._strike = BeautifulSoup(b'''
25 <div class="post-content">
26 <p><span style="text-decoration: line-through;">Abandon hope and endure.</span></p>
27 <p>No. Win.</p>
28 </div>''', 'html.parser')
29
30 def testStripFooters(self) -> None:
31 ApplyDOMFilters("NoFooter", self._html)
32 self.assertEqual(list(self._html.stripped_strings),
33 ["This is the edit box", "This is glowfic"])
34
35 def testStripEditBoxes(self) -> None:
36 ApplyDOMFilters("NoEdit", self._html)
37 self.assertEqual(list(self._html.stripped_strings),
38 ["This is glowfic", "This is the footer"])
39
40 def testStripFootersAndEditBoxes(self) -> None:
41 ApplyDOMFilters("NoEdit,NoFooter", self._html)
42 self.assertEqual(list(self._html.stripped_strings),
43 ["This is glowfic"])
44
45 def testStrike(self) -> None:
46 ApplyDOMFilters('Strike', self._strike)
47 s = self._strike.find_all('s')
48 self.assertEqual(len(s), 1)
49 self.assertEqual(list(s[0].stripped_strings),
50 ['Abandon hope and endure.'])
51
52
53 if __name__ == '__main__':
54 unittest.main()