]>
git.scottworley.com Git - paperdoorknob/blob - paperdoorknob_test.py
65fc2a9f308fbba82657389a87dd9b0971b312da
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.
8 from abc
import ABC
, abstractmethod
15 from testing
.fakeserver
import FakeGlowficServer
16 from domfilter
import ApplyDOMFilters
17 from fetch
import DirectFetcher
, FakeFetcher
, Fetcher
18 from images
import ImageStore
20 from texify
import DirectTexifier
, PandocTexifier
, VerifyingTexifier
25 class BaseTestProcess(ABC
):
29 raise NotImplementedError()
32 def fetcher(self
) -> Fetcher
:
33 raise NotImplementedError()
35 def testReplies(self
) -> None:
36 replies
= list(paperdoorknob
.replies(
37 paperdoorknob
.parse(self
.fetcher().fetch(self
.url()))))
39 ApplyDOMFilters('NoEdit,NoFooter', r
)
40 assert [r
.text
.strip() for r
in replies
] == [
45 def testProcess(self
) -> None:
50 ImageStore('is', self
.fetcher()),
52 lambda x
: ApplyDOMFilters('NoEdit,NoFooter', x
),
53 PandocTexifier('pandoc'),
56 paperdoorknob
.process(spec
)
57 assert buf
.getvalue() == b
'''\\documentclass{article}
58 \\usepackage[margin=20mm]{geometry}
66 def testDirectTexifier(self
) -> None:
67 texifier
= VerifyingTexifier(
68 PandocTexifier('pandoc'), DirectTexifier())
73 ImageStore('is', self
.fetcher()),
75 lambda x
: ApplyDOMFilters('NoEdit,NoFooter', x
),
79 paperdoorknob
.process(spec
)
81 def testPDF(self
) -> None:
82 with open("test.tex", 'wb') as out
:
86 ImageStore('is', self
.fetcher()),
88 lambda x
: ApplyDOMFilters('NoEdit,NoFooter', x
),
89 PandocTexifier('pandoc'),
92 paperdoorknob
.process(spec
)
93 subprocess
.run(['pdflatex', 'test.tex'],
94 stdin
=subprocess
.DEVNULL
, check
=True)
97 class TestProcessFromWebserver(BaseTestProcess
, unittest
.TestCase
):
99 def setUp(self
) -> None:
100 self
._fetcher
= self
.enterContext(DirectFetcher(TIMEOUT
))
101 self
._server
= self
.enterContext(FakeGlowficServer())
102 self
._port
= self
._server
.port()
104 def url(self
) -> str:
105 return f
"http://localhost:{self._port}"
107 def fetcher(self
) -> Fetcher
:
111 class TestProcessFromFakeFetcher(BaseTestProcess
, unittest
.TestCase
):
113 def url(self
) -> str:
116 def fetcher(self
) -> Fetcher
:
117 with open('testdata/this-is-glowfic.html', 'rb') as f
:
118 return FakeFetcher({'fic': f.read(9999)}
)
121 if __name__
== '__main__':