]>
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 domfilter
import ApplyDOMFilters
17 from fetch
import DirectFetcher
, FakeFetcher
, Fetcher
19 from texify
import DirectTexifier
, PandocTexifier
, VerifyingTexifier
24 class BaseTestProcess(ABC
):
28 raise NotImplementedError()
31 def fetcher(self
) -> Fetcher
:
32 raise NotImplementedError()
34 def testReplies(self
) -> None:
35 replies
= list(paperdoorknob
.replies(
36 paperdoorknob
.parse(self
.fetcher().fetch(self
.url()))))
38 ApplyDOMFilters('NoEdit,NoFooter', r
)
39 assert [r
.text
.strip() for r
in replies
] == [
44 def testProcess(self
) -> None:
50 lambda x
: ApplyDOMFilters('NoEdit,NoFooter', x
),
51 PandocTexifier('pandoc'),
54 paperdoorknob
.process(spec
)
55 assert buf
.getvalue() == b
'''\\documentclass{article}
56 \\usepackage[margin=20mm]{geometry}
64 def testDirectTexifier(self
) -> None:
65 texifier
= VerifyingTexifier(
66 PandocTexifier('pandoc'), DirectTexifier())
72 lambda x
: ApplyDOMFilters('NoEdit,NoFooter', x
),
76 paperdoorknob
.process(spec
)
78 def testPDF(self
) -> None:
79 with open("test.tex", 'wb') as out
:
84 lambda x
: ApplyDOMFilters('NoEdit,NoFooter', x
),
85 PandocTexifier('pandoc'),
88 paperdoorknob
.process(spec
)
89 subprocess
.run(['pdflatex', 'test.tex'],
90 stdin
=subprocess
.DEVNULL
, check
=True)
93 class TestProcessFromWebserver(BaseTestProcess
, unittest
.TestCase
):
95 def setUp(self
) -> None:
96 self
._fetcher
= self
.enterContext(DirectFetcher(TIMEOUT
))
97 self
._server
= self
.enterContext(FakeGlowficServer())
98 self
._port
= self
._server
.port()
100 def url(self
) -> str:
101 return f
"http://localhost:{self._port}"
103 def fetcher(self
) -> Fetcher
:
107 class TestProcessFromFakeFetcher(BaseTestProcess
, unittest
.TestCase
):
109 def url(self
) -> str:
112 def fetcher(self
) -> Fetcher
:
113 with open('testdata/this-is-glowfic.html', 'rb') as f
:
114 return FakeFetcher({'fic': f.read(9999)}
)
117 if __name__
== '__main__':