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
16 from testing
.fakeserver
import FakeGlowficServer
17 from fetch
import DirectFetcher
, FakeFetcher
, Fetcher
18 from glowfic
import ContentOnlyLayout
, BesideIconLayout
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:
38 texifier
= PandocTexifier('pandoc')
52 paperdoorknob
.process(spec
)
53 assert re
.match(br
'''\\documentclass{article}
54 (\\usepackage{[a-z]+}\n)+\\usepackage\[margin=20mm\]{geometry}
57 \\glowhead{}{}{}{}This is \\href{https://glowfic.com}{glowfic}
58 \\glowhead{}{}{}{}You \\emph{sure}\?
59 \\glowhead{}{}{}{}Pretty sure.
63 def testDirectTexifier(self
) -> None:
64 texifier
= VerifyingTexifier(
65 PandocTexifier('pandoc'), DirectTexifier())
80 paperdoorknob
.process(spec
)
82 def testPDF(self
) -> None:
83 texifier
= PandocTexifier('pandoc')
84 with open("test.tex", 'wb') as out
:
98 paperdoorknob
.process(spec
)
99 subprocess
.run(['pdflatex', 'test.tex'],
100 stdin
=subprocess
.DEVNULL
, check
=True)
103 class TestProcessFromWebserver(BaseTestProcess
, unittest
.TestCase
):
105 def setUp(self
) -> None:
106 self
._fetcher
= self
.enterContext(DirectFetcher(TIMEOUT
))
107 self
._server
= self
.enterContext(FakeGlowficServer())
108 self
._port
= self
._server
.port()
110 def url(self
) -> str:
111 return f
"http://localhost:{self._port}"
113 def fetcher(self
) -> Fetcher
:
117 class TestProcessFromFakeFetcher(BaseTestProcess
, unittest
.TestCase
):
119 def url(self
) -> str:
122 def fetcher(self
) -> Fetcher
:
123 with open('testdata/this-is-glowfic.html', 'rb') as f
:
125 return FakeFetcher({'fic': html, 'fic?view=flat': html}
)
128 if __name__
== '__main__':