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