]>
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 makeChunk
, Thread
14 from texify
import PandocTexifier
17 class TestSplit(unittest
.TestCase
):
19 def testSplit1(self
) -> None:
20 t
= Thread(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 t
.chunkDOMs()],
27 def testSplit2(self
) -> None:
28 t
= Thread(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 t
.chunkDOMs()],
36 [['The "post"'], ['The "reply"']])
38 def testSplit3(self
) -> None:
39 t
= Thread(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 t
.chunkDOMs()],
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 t
= Thread(BeautifulSoup(f
, 'html.parser'))
56 c
= makeChunk(next(iter(t
.chunkDOMs())), 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 class TestThread(unittest
.TestCase
):
77 def testTitle(self
) -> None:
78 t
= Thread(BeautifulSoup(b
'''
80 <div class="content-header">
81 <span id="post-title">
82 <a href="/posts/1234">Teh Story!</a>
85 <div class="post-container post-post">The "post"</div>
86 </body></html>''', 'html.parser'))
87 self
.assertEqual(t
.title(), 'Teh Story!')
90 if __name__
== '__main__':