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:
45 ContentOnlyLayout(PandocTexifier('pandoc')),
49 paperdoorknob
.process(spec
)
50 assert re
.match(br
'''\\documentclass{article}
51 (\\usepackage{[a-z]+}\n)+\\usepackage\[margin=20mm\]{geometry}
62 def testDirectTexifier(self
) -> None:
63 texifier
= VerifyingTexifier(
64 PandocTexifier('pandoc'), DirectTexifier())
73 ContentOnlyLayout(texifier
),
77 paperdoorknob
.process(spec
)
79 def testPDF(self
) -> None:
80 with open("test.tex", 'wb') as out
:
88 BesideIconLayout(PandocTexifier('pandoc'), 20),
92 paperdoorknob
.process(spec
)
93 subprocess
.run(['pdflatex', 'test.tex'],
94 stdin
=subprocess
.DEVNULL
, check
=True)
97 class TestProcessFromWebserver(BaseTestProcess
, unittest
.TestCase
):
99 def setUp(self
) -> None:
100 self
._fetcher
= self
.enterContext(DirectFetcher(TIMEOUT
))
101 self
._server
= self
.enterContext(FakeGlowficServer())
102 self
._port
= self
._server
.port()
104 def url(self
) -> str:
105 return f
"http://localhost:{self._port}"
107 def fetcher(self
) -> Fetcher
:
111 class TestProcessFromFakeFetcher(BaseTestProcess
, unittest
.TestCase
):
113 def url(self
) -> str:
116 def fetcher(self
) -> Fetcher
:
117 with open('testdata/this-is-glowfic.html', 'rb') as f
:
118 return FakeFetcher({'fic?view=flat': f.read(9999)}
)
121 if __name__
== '__main__':