]> git.scottworley.com Git - paperdoorknob/blame_incremental - paperdoorknob_test.py
Use the new encapsulated fetchers
[paperdoorknob] / paperdoorknob_test.py
... / ...
CommitLineData
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
9import io
10import subprocess
11import paperdoorknob
12from testing.fakeserver import FakeGlowficServer
13from fetch import DirectFetcher
14
15TIMEOUT = 8
16
17
18class TestPaperDoorknob(unittest.TestCase):
19 def setUp(self) -> None:
20 self._server = self.enterContext(FakeGlowficServer())
21 self._port = self._server.port()
22
23 def testReplies(self) -> None:
24 with DirectFetcher(TIMEOUT) as f:
25 replies = paperdoorknob.replies(
26 paperdoorknob.clean(
27 paperdoorknob.fetch(f"http://localhost:{self._port}", f)))
28 self.assertEqual([r.text.strip() for r in replies],
29 ["This is glowfic", "You sure?", "Pretty sure."])
30
31 def testProcess(self) -> None:
32 with DirectFetcher(TIMEOUT) as f:
33 buf = io.BytesIO()
34 paperdoorknob.process(
35 f"http://localhost:{self._port}", f, buf, 'pandoc')
36 self.assertEqual(buf.getvalue(), b'''\\documentclass{article}
37\\begin{document}
38This is glowfic
39You \\emph{sure}?
40Pretty sure.
41\\end{document}
42''')
43
44 def testPDF(self) -> None:
45 with DirectFetcher(TIMEOUT) as f:
46 with open("test.tex", 'wb') as out:
47 paperdoorknob.process(
48 f"http://localhost:{self._port}", f, out, 'pandoc')
49 subprocess.run(['pdflatex', 'test.tex'],
50 stdin=subprocess.DEVNULL, check=True)
51
52
53if __name__ == '__main__':
54 unittest.main()