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 domfilter
import ApplyDOMFilters
18 from fetch
import DirectFetcher
, FakeFetcher
, Fetcher
19 from glowfic
import ContentOnlyLayout
, BelowIconLayout
20 from images
import FakeImageStore
22 from texify
import DirectTexifier
, PandocTexifier
, VerifyingTexifier
27 class BaseTestProcess(ABC
):
31 raise NotImplementedError()
34 def fetcher(self
) -> Fetcher
:
35 raise NotImplementedError()
37 def testProcess(self
) -> None:
44 lambda x
: ApplyDOMFilters('NoEdit,NoFooter', x
),
46 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())
71 lambda x
: ApplyDOMFilters('NoEdit,NoFooter', x
),
73 ContentOnlyLayout(texifier
),
76 paperdoorknob
.process(spec
)
78 def testPDF(self
) -> None:
79 with open("test.tex", 'wb') as out
:
85 lambda x
: ApplyDOMFilters('NoEdit,NoFooter', x
),
87 BelowIconLayout(PandocTexifier('pandoc'), 20),
90 paperdoorknob
.process(spec
)
91 subprocess
.run(['pdflatex', 'test.tex'],
92 stdin
=subprocess
.DEVNULL
, check
=True)
95 class TestProcessFromWebserver(BaseTestProcess
, unittest
.TestCase
):
97 def setUp(self
) -> None:
98 self
._fetcher
= self
.enterContext(DirectFetcher(TIMEOUT
))
99 self
._server
= self
.enterContext(FakeGlowficServer())
100 self
._port
= self
._server
.port()
102 def url(self
) -> str:
103 return f
"http://localhost:{self._port}"
105 def fetcher(self
) -> Fetcher
:
109 class TestProcessFromFakeFetcher(BaseTestProcess
, unittest
.TestCase
):
111 def url(self
) -> str:
114 def fetcher(self
) -> Fetcher
:
115 with open('testdata/this-is-glowfic.html', 'rb') as f
:
116 return FakeFetcher({'fic?view=flat': f.read(9999)}
)
119 if __name__
== '__main__':