]>
git.scottworley.com Git - paperdoorknob/blob - paperdoorknob_test.py
425d5e3f21c6c8cb827ba8694dae0a7435608f89
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 fetch
import DirectFetcher
, FakeFetcher
, Fetcher
18 from texify
import DirectTexifier
, PandocTexifier
, VerifyingTexifier
23 class BaseTestProcess(ABC
):
27 raise NotImplementedError()
30 def fetcher(self
) -> Fetcher
:
31 raise NotImplementedError()
33 def testReplies(self
) -> None:
34 replies
= paperdoorknob
.replies(
39 assert [r
.text
.strip() for r
in replies
] == [
44 def testProcess(self
) -> None:
49 PandocTexifier('pandoc'),
51 paperdoorknob
.process(spec
)
52 assert buf
.getvalue() == b
'''\\documentclass{article}
60 def testDirectTexifier(self
) -> None:
61 texifier
= VerifyingTexifier(
62 PandocTexifier('pandoc'), DirectTexifier())
64 spec
= Spec(self
.url(), self
.fetcher(), texifier
, buf
)
65 paperdoorknob
.process(spec
)
67 def testPDF(self
) -> None:
68 with open("test.tex", 'wb') as out
:
72 PandocTexifier('pandoc'),
74 paperdoorknob
.process(spec
)
75 subprocess
.run(['pdflatex', 'test.tex'],
76 stdin
=subprocess
.DEVNULL
, check
=True)
79 class TestProcessFromWebserver(BaseTestProcess
, unittest
.TestCase
):
81 def setUp(self
) -> None:
82 self
._fetcher
= self
.enterContext(DirectFetcher(TIMEOUT
))
83 self
._server
= self
.enterContext(FakeGlowficServer())
84 self
._port
= self
._server
.port()
87 return f
"http://localhost:{self._port}"
89 def fetcher(self
) -> Fetcher
:
93 class TestProcessFromFakeFetcher(BaseTestProcess
, unittest
.TestCase
):
98 def fetcher(self
) -> Fetcher
:
99 with open('testdata/this-is-glowfic.html', 'rb') as f
:
100 return FakeFetcher({'fic': f.read(9999)}
)
103 if __name__
== '__main__':