]> git.scottworley.com Git - paperdoorknob/blame - glowfic_test.py
Put Texifier in spec
[paperdoorknob] / glowfic_test.py
CommitLineData
e6adf6ce
SW
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
aa060d9b
SW
12from images import FakeImageStore
13from glowfic import chunkDOMs, makeChunk
62043b2b 14from texify import PandocTexifier
e6adf6ce
SW
15
16
17class 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
aa060d9b
SW
51class 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')
37c47bc2
SW
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'])
aa060d9b
SW
68 self.assertEqual(str(c.content),
69 '<div class="post-content"><p></p></div>')
70
62043b2b
SW
71 self.assertEqual(
72 PandocTexifier("pandoc").texify(c.character), b'{Keltham}\n')
73
aa060d9b 74
e6adf6ce
SW
75if __name__ == '__main__':
76 unittest.main()