]>
git.scottworley.com Git - paperdoorknob/blob - paperdoorknob_test.py
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.
14 from testing
.fakeserver
import FakeGlowficServer
15 from fetch
import DirectFetcher
17 from texify
import DirectTexifier
, PandocTexifier
, VerifyingTexifier
22 class TestPaperDoorknob(unittest
.TestCase
):
23 def setUp(self
) -> None:
24 self
._server
= self
.enterContext(FakeGlowficServer())
25 self
._port
= self
._server
.port()
27 def testReplies(self
) -> None:
28 with DirectFetcher(TIMEOUT
) as f
:
29 replies
= paperdoorknob
.replies(
32 f
.fetch(f
"http://localhost:{self._port}"))))
33 self
.assertEqual([r
.text
.strip() for r
in replies
],
34 ["This is glowfic", "You sure?", "Pretty sure."])
36 def testProcess(self
) -> None:
37 with DirectFetcher(TIMEOUT
) as f
:
40 f
"http://localhost:{self._port}",
42 PandocTexifier('pandoc'),
44 paperdoorknob
.process(spec
)
45 self
.assertEqual(buf
.getvalue(), b
'''\\documentclass{article}
53 def testDirectTexifier(self
) -> None:
54 texifier
= VerifyingTexifier(
55 PandocTexifier('pandoc'), DirectTexifier())
56 with DirectFetcher(TIMEOUT
) as f
:
58 spec
= Spec(f
"http://localhost:{self._port}", f
, texifier
, buf
)
59 paperdoorknob
.process(spec
)
61 def testPDF(self
) -> None:
62 with DirectFetcher(TIMEOUT
) as f
:
63 with open("test.tex", 'wb') as out
:
65 f
"http://localhost:{self._port}",
67 PandocTexifier('pandoc'),
69 paperdoorknob
.process(spec
)
70 subprocess
.run(['pdflatex', 'test.tex'],
71 stdin
=subprocess
.DEVNULL
, check
=True)
74 if __name__
== '__main__':