]>
git.scottworley.com Git - paperdoorknob/blob - paperdoorknob_test.py
aa50340ecfd7709ed3437b9ce006d22a5fe1804d
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
19 from texify
import DirectTexifier
, PandocTexifier
, VerifyingTexifier
24 class BaseTestProcess(ABC
):
28 raise NotImplementedError()
31 def fetcher(self
) -> Fetcher
:
32 raise NotImplementedError()
34 def testReplies(self
) -> None:
35 replies
= list(paperdoorknob
.replies(
36 paperdoorknob
.parse(self
.fetcher().fetch(self
.url()))))
38 ApplyDOMFilters('NoEdit,NoFooter', r
)
39 assert [r
.text
.strip() for r
in replies
] == [
44 def testProcess(self
) -> None:
50 lambda x
: ApplyDOMFilters('NoEdit,NoFooter', x
),
51 PandocTexifier('pandoc'),
53 paperdoorknob
.process(spec
)
54 assert buf
.getvalue() == b
'''\\documentclass{article}
62 def testDirectTexifier(self
) -> None:
63 texifier
= VerifyingTexifier(
64 PandocTexifier('pandoc'), DirectTexifier())
70 lambda x
: ApplyDOMFilters('NoEdit,NoFooter', x
),
73 paperdoorknob
.process(spec
)
75 def testPDF(self
) -> None:
76 with open("test.tex", 'wb') as out
:
81 lambda x
: ApplyDOMFilters('NoEdit,NoFooter', x
),
82 PandocTexifier('pandoc'),
84 paperdoorknob
.process(spec
)
85 subprocess
.run(['pdflatex', 'test.tex'],
86 stdin
=subprocess
.DEVNULL
, check
=True)
89 class TestProcessFromWebserver(BaseTestProcess
, unittest
.TestCase
):
91 def setUp(self
) -> None:
92 self
._fetcher
= self
.enterContext(DirectFetcher(TIMEOUT
))
93 self
._server
= self
.enterContext(FakeGlowficServer())
94 self
._port
= self
._server
.port()
97 return f
"http://localhost:{self._port}"
99 def fetcher(self
) -> Fetcher
:
103 class TestProcessFromFakeFetcher(BaseTestProcess
, unittest
.TestCase
):
105 def url(self
) -> str:
108 def fetcher(self
) -> Fetcher
:
109 with open('testdata/this-is-glowfic.html', 'rb') as f
:
110 return FakeFetcher({'fic': f.read(9999)}
)
113 if __name__
== '__main__':