]>
git.scottworley.com Git - paperdoorknob/blob - domfilter_test.py
1 # paperdoorknob: Print glowfic
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.
10 from bs4
import BeautifulSoup
12 from domfilter
import ApplyDOMFilters
15 class TestDOMFilters(unittest
.TestCase
):
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>
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>
28 </div>''', 'html.parser')
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"])
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"])
40 def testStripFootersAndEditBoxes(self
) -> None:
41 ApplyDOMFilters("NoEdit,NoFooter", self
._html
)
42 self
.assertEqual(list(self
._html
.stripped_strings
),
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.'])
53 if __name__
== '__main__':