]>
git.scottworley.com Git - paperdoorknob/blob - glowfic_test.py
22eea257c21d4fe4d9b7776fdd159b579a8016f8
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
:
19 return Spec('https://fake/test',
20 FakeFetcher({'https://fake/test': html
,
21 'https://fake/test?view=flat': html
}),
25 PandocTexifier('pandoc'),
34 class TestSplit(unittest
.TestCase
):
36 def testSplit1(self
) -> None:
37 t
= Thread(spec_for_testing(b
'''
38 <html><body><div class="post-container post-post">
40 </div></body></html>'''))
41 self
.assertEqual([list(t
.stripped_strings
) for t
in t
.chunkDOMs()],
44 def testSplit2(self
) -> None:
45 t
= Thread(spec_for_testing(b
'''
47 <div class="post-container post-post">The "post"</div>
48 <div class="flat-post-replies">
49 <div class="post-container post-reply">The "reply"</div>
52 self
.assertEqual([list(t
.stripped_strings
) for t
in t
.chunkDOMs()],
53 [['The "post"'], ['The "reply"']])
55 def testSplit3(self
) -> None:
56 t
= Thread(spec_for_testing(b
'''
58 <div class="post-container post-post">The "post"</div>
59 <div class="flat-post-replies">
60 <div class="post-container post-reply">1st reply</div>
61 <div class="post-container post-reply">2nd reply</div>
64 self
.assertEqual([list(t
.stripped_strings
) for t
in t
.chunkDOMs()],
65 [['The "post"'], ['1st reply'], ['2nd reply']])
68 class TestMakeChunk(unittest
.TestCase
):
70 def testEmptyContent(self
) -> None:
71 with open('testdata/empty-content.html', 'rb') as f
:
72 t
= Thread(spec_for_testing(f
.read((9999))))
73 c
= makeChunk(next(iter(t
.chunkDOMs())), FakeImageStore())
76 'stored:https://d1anwqy6ci9o1i.cloudfront.net/' +
77 'users%2F366%2Ficons%2Fxqmypqvflgdy28aorw9ml_shock.png')
81 self
.assertEqual(list(c
.character
.stripped_strings
), ['Keltham'])
83 list(c
.screen_name
.stripped_strings
), ['lawful chaotic'])
84 self
.assertEqual(list(c
.author
.stripped_strings
), ['Iarwain'])
85 self
.assertEqual(str(c
.content
),
86 '<div class="post-content"><p></p></div>')
89 PandocTexifier("pandoc").texify(c
.character
), b
'{Keltham}\n')
92 class TestThread(unittest
.TestCase
):
94 def testTitle(self
) -> None:
95 t
= Thread(spec_for_testing(b
'''
97 <div class="content-header">
98 <span id="post-title">
99 <a href="/posts/1234">Teh Story!</a>
102 <div class="post-container post-post">The "post"</div>
104 self
.assertEqual(t
.title(), 'Teh Story!')
106 def testNextThread(self
) -> None:
107 t
= Thread(spec_for_testing(b
'''
109 <div class="post-navheader">
110 <a class="view-button-link" href="/posts/4567"><div class="view-button">Next Post »</div>
111 </a><a class="view-button-link" href="/posts/4321"><div class="view-button float-none">« Previous Post</div>
114 <div class="post-container post-post">The "post"</div>
116 self
.assertEqual(t
.next_thread(), '/posts/4567')
119 if __name__
== '__main__':