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
, 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:
45 ContentOnlyLayout(PandocTexifier('pandoc')),
48 paperdoorknob
.process(spec
)
49 assert re
.match(br
'''\\documentclass{article}
50 (\\usepackage{[a-z]+}\n)+\\usepackage\[margin=20mm\]{geometry}
61 def testDirectTexifier(self
) -> None:
62 texifier
= VerifyingTexifier(
63 PandocTexifier('pandoc'), DirectTexifier())
72 ContentOnlyLayout(texifier
),
75 paperdoorknob
.process(spec
)
77 def testPDF(self
) -> None:
78 with open("test.tex", 'wb') as out
:
86 BelowIconLayout(PandocTexifier('pandoc'), 20),
89 paperdoorknob
.process(spec
)
90 subprocess
.run(['pdflatex', 'test.tex'],
91 stdin
=subprocess
.DEVNULL
, check
=True)
94 class TestProcessFromWebserver(BaseTestProcess
, unittest
.TestCase
):
96 def setUp(self
) -> None:
97 self
._fetcher
= self
.enterContext(DirectFetcher(TIMEOUT
))
98 self
._server
= self
.enterContext(FakeGlowficServer())
99 self
._port
= self
._server
.port()
101 def url(self
) -> str:
102 return f
"http://localhost:{self._port}"
104 def fetcher(self
) -> Fetcher
:
108 class TestProcessFromFakeFetcher(BaseTestProcess
, unittest
.TestCase
):
110 def url(self
) -> str:
113 def fetcher(self
) -> Fetcher
:
114 with open('testdata/this-is-glowfic.html', 'rb') as f
:
115 return FakeFetcher({'fic?view=flat': f.read(9999)}
)
118 if __name__
== '__main__':