]>
git.scottworley.com Git - paperdoorknob/blob - glowfic_test.py
2d01c2a7e85b2d272fb60ed4dafcb657be72440e
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
14 from texify
import PandocTexifier
17 class TestSplit(unittest
.TestCase
):
19 def testSplit1(self
) -> None:
20 soup
= BeautifulSoup(b
'''
21 <html><body><div class="post-container post-post">
23 </div></body></html>''', 'html.parser')
24 self
.assertEqual([list(t
.stripped_strings
) for t
in chunkDOMs(soup
)],
27 def testSplit2(self
) -> None:
28 soup
= BeautifulSoup(b
'''
30 <div class="post-container post-post">The "post"</div>
31 <div class="flat-post-replies">
32 <div class="post-container post-reply">The "reply"</div>
34 </body></html>''', 'html.parser')
35 self
.assertEqual([list(t
.stripped_strings
) for t
in chunkDOMs(soup
)],
36 [['The "post"'], ['The "reply"']])
38 def testSplit3(self
) -> None:
39 soup
= BeautifulSoup(b
'''
41 <div class="post-container post-post">The "post"</div>
42 <div class="flat-post-replies">
43 <div class="post-container post-reply">1st reply</div>
44 <div class="post-container post-reply">2nd reply</div>
46 </body></html>''', 'html.parser')
47 self
.assertEqual([list(t
.stripped_strings
) for t
in chunkDOMs(soup
)],
48 [['The "post"'], ['1st reply'], ['2nd reply']])
51 class TestMakeChunk(unittest
.TestCase
):
53 def testEmptyContent(self
) -> None:
54 with open('testdata/empty-content.html', 'rb') as f
:
55 soup
= BeautifulSoup(f
, 'html.parser')
56 c
= makeChunk(next(iter(chunkDOMs(soup
))), FakeImageStore())
59 'stored:https://d1anwqy6ci9o1i.cloudfront.net/' +
60 'users%2F366%2Ficons%2Fxqmypqvflgdy28aorw9ml_shock.png')
64 self
.assertEqual(list(c
.character
.stripped_strings
), ['Keltham'])
66 list(c
.screen_name
.stripped_strings
), ['lawful chaotic'])
67 self
.assertEqual(list(c
.author
.stripped_strings
), ['Iarwain'])
68 self
.assertEqual(str(c
.content
),
69 '<div class="post-content"><p></p></div>')
72 PandocTexifier("pandoc").texify(c
.character
), b
'{Keltham}\n')
75 if __name__
== '__main__':