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:
46 ContentOnlyLayout(PandocTexifier('pandoc')),
50 paperdoorknob
.process(spec
)
51 assert re
.match(br
'''\\documentclass{article}
52 (\\usepackage{[a-z]+}\n)+\\usepackage\[margin=20mm\]{geometry}
55 This is \\href{https://glowfic.com}{glowfic}
64 def testDirectTexifier(self
) -> None:
65 texifier
= VerifyingTexifier(
66 PandocTexifier('pandoc'), DirectTexifier())
76 ContentOnlyLayout(texifier
),
80 paperdoorknob
.process(spec
)
82 def testPDF(self
) -> None:
83 with open("test.tex", 'wb') as out
:
92 BesideIconLayout(PandocTexifier('pandoc')),
96 paperdoorknob
.process(spec
)
97 subprocess
.run(['pdflatex', 'test.tex'],
98 stdin
=subprocess
.DEVNULL
, check
=True)
101 class TestProcessFromWebserver(BaseTestProcess
, unittest
.TestCase
):
103 def setUp(self
) -> None:
104 self
._fetcher
= self
.enterContext(DirectFetcher(TIMEOUT
))
105 self
._server
= self
.enterContext(FakeGlowficServer())
106 self
._port
= self
._server
.port()
108 def url(self
) -> str:
109 return f
"http://localhost:{self._port}"
111 def fetcher(self
) -> Fetcher
:
115 class TestProcessFromFakeFetcher(BaseTestProcess
, unittest
.TestCase
):
117 def url(self
) -> str:
120 def fetcher(self
) -> Fetcher
:
121 with open('testdata/this-is-glowfic.html', 'rb') as f
:
122 return FakeFetcher({'fic?view=flat': f.read(9999)}
)
125 if __name__
== '__main__':