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