]>
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.
11 from fetch
import FakeFetcher
12 from images
import FakeImageStore
13 from glowfic
import makeChunk
, Thread
15 from texify
import PandocTexifier
18 def spec_for_testing(html
: bytes) -> Spec
:
20 FakeFetcher({'test?view=flat': html}
),
24 PandocTexifier('pandoc'),
33 class TestSplit(unittest
.TestCase
):
35 def testSplit1(self
) -> None:
36 t
= Thread(spec_for_testing(b
'''
37 <html><body><div class="post-container post-post">
39 </div></body></html>'''))
40 self
.assertEqual([list(t
.stripped_strings
) for t
in t
.chunkDOMs()],
43 def testSplit2(self
) -> None:
44 t
= Thread(spec_for_testing(b
'''
46 <div class="post-container post-post">The "post"</div>
47 <div class="flat-post-replies">
48 <div class="post-container post-reply">The "reply"</div>
51 self
.assertEqual([list(t
.stripped_strings
) for t
in t
.chunkDOMs()],
52 [['The "post"'], ['The "reply"']])
54 def testSplit3(self
) -> None:
55 t
= Thread(spec_for_testing(b
'''
57 <div class="post-container post-post">The "post"</div>
58 <div class="flat-post-replies">
59 <div class="post-container post-reply">1st reply</div>
60 <div class="post-container post-reply">2nd reply</div>
63 self
.assertEqual([list(t
.stripped_strings
) for t
in t
.chunkDOMs()],
64 [['The "post"'], ['1st reply'], ['2nd reply']])
67 class TestMakeChunk(unittest
.TestCase
):
69 def testEmptyContent(self
) -> None:
70 with open('testdata/empty-content.html', 'rb') as f
:
71 t
= Thread(spec_for_testing(f
.read((9999))))
72 c
= makeChunk(next(iter(t
.chunkDOMs())), FakeImageStore())
75 'stored:https://d1anwqy6ci9o1i.cloudfront.net/' +
76 'users%2F366%2Ficons%2Fxqmypqvflgdy28aorw9ml_shock.png')
80 self
.assertEqual(list(c
.character
.stripped_strings
), ['Keltham'])
82 list(c
.screen_name
.stripped_strings
), ['lawful chaotic'])
83 self
.assertEqual(list(c
.author
.stripped_strings
), ['Iarwain'])
84 self
.assertEqual(str(c
.content
),
85 '<div class="post-content"><p></p></div>')
88 PandocTexifier("pandoc").texify(c
.character
), b
'{Keltham}\n')
91 class TestThread(unittest
.TestCase
):
93 def testTitle(self
) -> None:
94 t
= Thread(spec_for_testing(b
'''
96 <div class="content-header">
97 <span id="post-title">
98 <a href="/posts/1234">Teh Story!</a>
101 <div class="post-container post-post">The "post"</div>
103 self
.assertEqual(t
.title(), 'Teh Story!')
106 if __name__
== '__main__':