2007-01-24 22:24:01 +08:00
|
|
|
from __future__ import generators
|
|
|
|
|
|
|
|
import py
|
|
|
|
from py.__.rest.latex import process_configfile, process_rest_file
|
2008-08-18 23:08:39 +08:00
|
|
|
from py.__.rest.testing.setup import getdata
|
|
|
|
|
2007-01-24 22:24:01 +08:00
|
|
|
try:
|
|
|
|
import docutils
|
|
|
|
except ImportError:
|
|
|
|
py.test.skip("docutils not present")
|
|
|
|
|
|
|
|
|
|
|
|
def setup_module(mod):
|
|
|
|
if not py.path.local.sysfind("gs") or \
|
|
|
|
not py.path.local.sysfind("dot") or \
|
|
|
|
not py.path.local.sysfind("latex"):
|
|
|
|
py.test.skip("ghostscript, graphviz and latex needed")
|
2008-08-18 23:08:39 +08:00
|
|
|
mod.datadir = getdata()
|
2007-01-24 22:24:01 +08:00
|
|
|
|
2007-02-08 04:53:57 +08:00
|
|
|
class TestRst2Pdf(object):
|
|
|
|
def _process_rest_file(self):
|
2008-08-18 23:08:39 +08:00
|
|
|
part2 = datadir.join("part1.txt")
|
2007-02-08 04:53:57 +08:00
|
|
|
pdf = part2.new(ext="pdf")
|
|
|
|
process_rest_file(part2)
|
|
|
|
assert pdf.check()
|
|
|
|
pdf.remove()
|
|
|
|
|
|
|
|
def _process_configfile(self):
|
2008-08-18 23:08:39 +08:00
|
|
|
config = datadir.join("example.rst2pdfconfig")
|
2007-02-08 04:53:57 +08:00
|
|
|
pdf = config.new(ext="pdf")
|
2008-08-18 23:08:39 +08:00
|
|
|
tex = datadir.join('example.tex')
|
2007-02-08 04:53:57 +08:00
|
|
|
process_configfile(config, debug=True)
|
|
|
|
assert pdf.check()
|
|
|
|
assert tex.check()
|
|
|
|
texcontent = tex.read()
|
|
|
|
assert "Generated by" in texcontent
|
|
|
|
assert "Docutils" in texcontent
|
|
|
|
process_configfile(config, debug=False)
|
|
|
|
assert pdf.check()
|
|
|
|
assert not tex.check()
|
|
|
|
pdf.remove()
|
|
|
|
|
|
|
|
def _process_all(self):
|
|
|
|
# fallback test: only checks that no exception is raised
|
|
|
|
def rec(p):
|
|
|
|
return p.check(dotfile=0)
|
|
|
|
|
2008-08-18 23:08:39 +08:00
|
|
|
for x in datadir.visit("*.rst2pdfconfig", rec=rec):
|
2007-02-08 04:53:57 +08:00
|
|
|
process_configfile(x)
|
2008-08-18 23:08:39 +08:00
|
|
|
for x in datadir.visit("*.txt", rec=rec):
|
2007-02-08 04:53:57 +08:00
|
|
|
process_rest_file(x)
|
|
|
|
|
|
|
|
def test_rst2pdf(self):
|
|
|
|
self._process_rest_file()
|
|
|
|
self._process_configfile()
|
|
|
|
self._process_all()
|