]>
git.scottworley.com Git - paperdoorknob/blob - paperdoorknob_test.py
249b6e42e936fa5f60a18e021c133dc824ca15a6
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
15 from testing
.fakeserver
import FakeGlowficServer
16 from domfilter
import ApplyDOMFilters
17 from fetch
import DirectFetcher
, FakeFetcher
, Fetcher
18 from images
import ImageStore
20 from texify
import DirectTexifier
, PandocTexifier
, VerifyingTexifier
25 class BaseTestProcess(ABC
):
29 raise NotImplementedError()
32 def fetcher(self
) -> Fetcher
:
33 raise NotImplementedError()
35 def testProcess(self
) -> None:
40 ImageStore('is', self
.fetcher()),
42 lambda x
: ApplyDOMFilters('NoEdit,NoFooter', x
),
43 PandocTexifier('pandoc'),
46 paperdoorknob
.process(spec
)
47 assert buf
.getvalue() == b
'''\\documentclass{article}
48 \\usepackage[margin=20mm]{geometry}
56 def testDirectTexifier(self
) -> None:
57 texifier
= VerifyingTexifier(
58 PandocTexifier('pandoc'), DirectTexifier())
63 ImageStore('is', self
.fetcher()),
65 lambda x
: ApplyDOMFilters('NoEdit,NoFooter', x
),
69 paperdoorknob
.process(spec
)
71 def testPDF(self
) -> None:
72 with open("test.tex", 'wb') as out
:
76 ImageStore('is', self
.fetcher()),
78 lambda x
: ApplyDOMFilters('NoEdit,NoFooter', x
),
79 PandocTexifier('pandoc'),
82 paperdoorknob
.process(spec
)
83 subprocess
.run(['pdflatex', 'test.tex'],
84 stdin
=subprocess
.DEVNULL
, check
=True)
87 class TestProcessFromWebserver(BaseTestProcess
, unittest
.TestCase
):
89 def setUp(self
) -> None:
90 self
._fetcher
= self
.enterContext(DirectFetcher(TIMEOUT
))
91 self
._server
= self
.enterContext(FakeGlowficServer())
92 self
._port
= self
._server
.port()
95 return f
"http://localhost:{self._port}"
97 def fetcher(self
) -> Fetcher
:
101 class TestProcessFromFakeFetcher(BaseTestProcess
, unittest
.TestCase
):
103 def url(self
) -> str:
106 def fetcher(self
) -> Fetcher
:
107 with open('testdata/this-is-glowfic.html', 'rb') as f
:
108 return FakeFetcher({'fic': f.read(9999)}
)
111 if __name__
== '__main__':