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