]> git.scottworley.com Git - paperdoorknob/blame_incremental - glowfic_test.py
Escape character names
[paperdoorknob] / glowfic_test.py
... / ...
CommitLineData
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
8import unittest
9
10from bs4 import BeautifulSoup
11
12from images import FakeImageStore
13from glowfic import chunkDOMs, makeChunk
14
15
16class TestSplit(unittest.TestCase):
17
18 def testSplit1(self) -> None:
19 soup = BeautifulSoup(b'''
20 <html><body><div class="post-container post-post">
21 The "post"
22 </div></body></html>''', 'html.parser')
23 self.assertEqual([list(t.stripped_strings) for t in chunkDOMs(soup)],
24 [['The "post"']])
25
26 def testSplit2(self) -> None:
27 soup = BeautifulSoup(b'''
28 <html><body>
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>
32 </div>
33 </body></html>''', 'html.parser')
34 self.assertEqual([list(t.stripped_strings) for t in chunkDOMs(soup)],
35 [['The "post"'], ['The "reply"']])
36
37 def testSplit3(self) -> None:
38 soup = BeautifulSoup(b'''
39 <html><body>
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>
44 </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']])
48
49
50class TestMakeChunk(unittest.TestCase):
51
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())
56 self.assertEqual(
57 c.icon,
58 'stored:https://d1anwqy6ci9o1i.cloudfront.net/' +
59 'users%2F366%2Ficons%2Fxqmypqvflgdy28aorw9ml_shock.png')
60 assert c.character
61 assert c.screen_name
62 assert c.author
63 self.assertEqual(list(c.character.stripped_strings), ['Keltham'])
64 self.assertEqual(
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>')
69
70
71if __name__ == '__main__':
72 unittest.main()