]>
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.
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:
50 PandocTexifier('pandoc'),
52 paperdoorknob
.process(spec
)
53 assert buf
.getvalue() == b
'''\\documentclass{article}
61 def testDirectTexifier(self
) -> None:
62 texifier
= VerifyingTexifier(
63 PandocTexifier('pandoc'), DirectTexifier())
65 spec
= Spec(self
.url(), self
.fetcher(), lambda x
: x
, texifier
, buf
)
66 paperdoorknob
.process(spec
)
68 def testPDF(self
) -> None:
69 with open("test.tex", 'wb') as out
:
74 PandocTexifier('pandoc'),
76 paperdoorknob
.process(spec
)
77 subprocess
.run(['pdflatex', 'test.tex'],
78 stdin
=subprocess
.DEVNULL
, check
=True)
81 class TestProcessFromWebserver(BaseTestProcess
, unittest
.TestCase
):
83 def setUp(self
) -> None:
84 self
._fetcher
= self
.enterContext(DirectFetcher(TIMEOUT
))
85 self
._server
= self
.enterContext(FakeGlowficServer())
86 self
._port
= self
._server
.port()
89 return f
"http://localhost:{self._port}"
91 def fetcher(self
) -> Fetcher
:
95 class TestProcessFromFakeFetcher(BaseTestProcess
, unittest
.TestCase
):
100 def fetcher(self
) -> Fetcher
:
101 with open('testdata/this-is-glowfic.html', 'rb') as f
:
102 return FakeFetcher({'fic': f.read(9999)}
)
105 if __name__
== '__main__':