]>
git.scottworley.com Git - paperdoorknob/blob - paperdoorknob_test.py
612ee8d1c4cad8b054e089308be39ec771cd9304
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 glowfic
import ContentOnlyLayout
, BelowIconLayout
19 from images
import FakeImageStore
21 from texify
import DirectTexifier
, PandocTexifier
, VerifyingTexifier
26 class BaseTestProcess(ABC
):
30 raise NotImplementedError()
33 def fetcher(self
) -> Fetcher
:
34 raise NotImplementedError()
36 def testProcess(self
) -> None:
43 lambda x
: ApplyDOMFilters('NoEdit,NoFooter', x
),
44 ContentOnlyLayout(PandocTexifier('pandoc')),
47 paperdoorknob
.process(spec
)
48 assert buf
.getvalue() == b
'''\\documentclass{article}
49 \\usepackage{graphicx}
51 \\usepackage[margin=20mm]{geometry}
55 \\vspace{-.5\\ht\\strutbox}\\noindent\\hrulefill
59 \\vspace{-.5\\ht\\strutbox}\\noindent\\hrulefill
65 def testDirectTexifier(self
) -> None:
66 texifier
= VerifyingTexifier(
67 PandocTexifier('pandoc'), DirectTexifier())
74 lambda x
: ApplyDOMFilters('NoEdit,NoFooter', x
),
75 ContentOnlyLayout(texifier
),
78 paperdoorknob
.process(spec
)
80 def testPDF(self
) -> None:
81 with open("test.tex", 'wb') as out
:
87 lambda x
: ApplyDOMFilters('NoEdit,NoFooter', x
),
88 BelowIconLayout(PandocTexifier('pandoc'), 20),
91 paperdoorknob
.process(spec
)
92 subprocess
.run(['pdflatex', 'test.tex'],
93 stdin
=subprocess
.DEVNULL
, check
=True)
96 class TestProcessFromWebserver(BaseTestProcess
, unittest
.TestCase
):
98 def setUp(self
) -> None:
99 self
._fetcher
= self
.enterContext(DirectFetcher(TIMEOUT
))
100 self
._server
= self
.enterContext(FakeGlowficServer())
101 self
._port
= self
._server
.port()
103 def url(self
) -> str:
104 return f
"http://localhost:{self._port}"
106 def fetcher(self
) -> Fetcher
:
110 class TestProcessFromFakeFetcher(BaseTestProcess
, unittest
.TestCase
):
112 def url(self
) -> str:
115 def fetcher(self
) -> Fetcher
:
116 with open('testdata/this-is-glowfic.html', 'rb') as f
:
117 return FakeFetcher({'fic': f.read(9999)}
)
120 if __name__
== '__main__':