]>
git.scottworley.com Git - paperdoorknob/blob - glowfic_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 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')
63 self
.assertEqual(list(c
.character
.stripped_strings
), ['Keltham'])
65 list(c
.screen_name
.stripped_strings
), ['lawful chaotic'])
66 self
.assertEqual(list(c
.author
.stripped_strings
), ['Iarwain'])
67 self
.assertEqual(str(c
.content
),
68 '<div class="post-content"><p></p></div>')
71 if __name__
== '__main__':