]>
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
18 from images
import FakeImageStore
20 from texify
import DirectTexifier
, PandocTexifier
, VerifyingTexifier
25 class BaseTestProcess(ABC
):
29 raise NotImplementedError()
32 def fetcher(self
) -> Fetcher
:
33 raise NotImplementedError()
35 def testProcess(self
) -> None:
42 lambda x
: ApplyDOMFilters('NoEdit,NoFooter', x
),
43 PandocTexifier('pandoc'),
46 paperdoorknob
.process(spec
)
47 assert buf
.getvalue() == b
'''\\documentclass{article}
49 \\usepackage[margin=20mm]{geometry}
57 def testDirectTexifier(self
) -> None:
58 texifier
= VerifyingTexifier(
59 PandocTexifier('pandoc'), DirectTexifier())
66 lambda x
: ApplyDOMFilters('NoEdit,NoFooter', x
),
70 paperdoorknob
.process(spec
)
72 def testPDF(self
) -> None:
73 with open("test.tex", 'wb') as out
:
79 lambda x
: ApplyDOMFilters('NoEdit,NoFooter', x
),
80 PandocTexifier('pandoc'),
83 paperdoorknob
.process(spec
)
84 subprocess
.run(['pdflatex', 'test.tex'],
85 stdin
=subprocess
.DEVNULL
, check
=True)
88 class TestProcessFromWebserver(BaseTestProcess
, unittest
.TestCase
):
90 def setUp(self
) -> None:
91 self
._fetcher
= self
.enterContext(DirectFetcher(TIMEOUT
))
92 self
._server
= self
.enterContext(FakeGlowficServer())
93 self
._port
= self
._server
.port()
96 return f
"http://localhost:{self._port}"
98 def fetcher(self
) -> Fetcher
:
102 class TestProcessFromFakeFetcher(BaseTestProcess
, unittest
.TestCase
):
104 def url(self
) -> str:
107 def fetcher(self
) -> Fetcher
:
108 with open('testdata/this-is-glowfic.html', 'rb') as f
:
109 return FakeFetcher({'fic': f.read(9999)}
)
112 if __name__
== '__main__':