]>
git.scottworley.com Git - paperdoorknob/blob - glowfic_test.py
d3a6d563f8930150eb32296ceb1973afb96d3af8
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 images
import FakeImageStore
13 from glowfic
import chunkDOMs
, makeChunk
16 class TestSplit(unittest
.TestCase
):
18 def testSplit1(self
) -> None:
19 soup
= BeautifulSoup(b
'''
20 <html><body><div class="post-container post-post">
22 </div></body></html>''', 'html.parser')
23 self
.assertEqual([list(t
.stripped_strings
) for t
in chunkDOMs(soup
)],
26 def testSplit2(self
) -> None:
27 soup
= BeautifulSoup(b
'''
29 <div class="post-container post-post">The "post"</div>
30 <div class="flat-post-replies">
31 <div class="post-container post-reply">The "reply"</div>
33 </body></html>''', 'html.parser')
34 self
.assertEqual([list(t
.stripped_strings
) for t
in chunkDOMs(soup
)],
35 [['The "post"'], ['The "reply"']])
37 def testSplit3(self
) -> None:
38 soup
= BeautifulSoup(b
'''
40 <div class="post-container post-post">The "post"</div>
41 <div class="flat-post-replies">
42 <div class="post-container post-reply">1st reply</div>
43 <div class="post-container post-reply">2nd reply</div>
45 </body></html>''', 'html.parser')
46 self
.assertEqual([list(t
.stripped_strings
) for t
in chunkDOMs(soup
)],
47 [['The "post"'], ['1st reply'], ['2nd reply']])
50 class TestMakeChunk(unittest
.TestCase
):
52 def testEmptyContent(self
) -> None:
53 with open('testdata/empty-content.html', 'rb') as f
:
54 soup
= BeautifulSoup(f
, 'html.parser')
55 c
= makeChunk(next(iter(chunkDOMs(soup
))), FakeImageStore())
58 'stored:https://d1anwqy6ci9o1i.cloudfront.net/' +
59 'users%2F366%2Ficons%2Fxqmypqvflgdy28aorw9ml_shock.png')
60 self
.assertEqual(c
.character
, 'Keltham')
61 self
.assertEqual(c
.screen_name
, 'lawful chaotic')
62 self
.assertEqual(c
.author
, 'Iarwain')
63 self
.assertEqual(str(c
.content
),
64 '<div class="post-content"><p></p></div>')
67 if __name__
== '__main__':