def render_sphinx_project(name, project_dir, template_cfg=None, stylesheet=None): project_path = TEST_DIR / project_dir out_path = OUTPUT_DIR / name confoverrides = {} if template_cfg: confoverrides['rinoh_template'] = str(TEST_DIR / template_cfg) if stylesheet: confoverrides['rinoh_stylesheet'] = str(TEST_DIR / stylesheet) sphinx = Sphinx(srcdir=str(project_path), confdir=str(project_path), outdir=str(out_path / 'rinoh'), doctreedir=str(out_path / 'doctrees'), buildername='rinoh', confoverrides=confoverrides) sphinx.build() out_filename = '{}.pdf'.format(name) with in_directory(out_path): if not diff_pdf(TEST_DIR / 'reference' / out_filename, out_path / 'rinoh' / out_filename): pytest.fail( 'The generated PDF is different from the reference ' 'PDF.\nGenerated files can be found in {}'.format(out_path))
def test_sphinxdocs(tmpdir): from sphinx.application import Sphinx template_cfg_path = path.join(TEST_DIR, 'sphinxdocs.rtt') sphinx = Sphinx(srcdir=SPHINX_DOC_DIR, confdir=SPHINX_DOC_DIR, outdir=tmpdir.join('rinoh').strpath, doctreedir=tmpdir.join('doctrees').strpath, buildername='rinoh', confoverrides=dict(extensions=[ 'sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.todo', 'sphinx.ext.autosummary', 'sphinx.ext.extlinks', 'sphinx.ext.viewcode', 'rinoh.frontend.sphinx' ], rinoh_template=template_cfg_path)) sphinx.build() out_file = tmpdir.join('rinoh').join('sphinx.pdf').strpath with in_directory(tmpdir.strpath): # _, _, _, badlinks, _, _ = check_pdf_links(out_file) # pytest.assume(badlinks == [], 'Output PDF contains broken ' # 'hyperlinks: {}'.format(badlinks)) if not diff_pdf(path.join(TEST_DIR, 'reference/sphinx.pdf'), out_file): pytest.fail('The generated PDF is different from the reference ' 'PDF.\nGenerated files can be found in {}'.format( tmpdir.strpath))
def render_doctree(doctree, out_filename, reference_path, tmpdir): document = MinimalTemplate(doctree) document.render(tmpdir.join(out_filename).strpath) pdf_filename = '{}.pdf'.format(out_filename) with in_directory(tmpdir.strpath): _, _, _, badlinks, _, _ = check_pdf_links(pdf_filename) pytest.assume(badlinks == []) if not diff_pdf(path.join(reference_path, pdf_filename), pdf_filename): pytest.fail('The generated PDF is different from the reference ' 'PDF.\nGenerated files can be found in {}'.format( tmpdir.strpath))
def verify_output(out_filename, output_dir, reference_path): pdf_filename = '{}.pdf'.format(out_filename) _, _, _, _, _, _, ref_outlines = \ check_pdf_links(reference_path / pdf_filename) with in_directory(output_dir): _, _, _, badlinks, _, _, outlines = check_pdf_links(pdf_filename) pytest.assume(badlinks == []) pytest.assume(ref_outlines == outlines) if not diff_pdf(reference_path / pdf_filename, pdf_filename): pytest.fail( 'The generated PDF is different from the reference ' 'PDF.\nGenerated files can be found in {}'.format(output_dir))
def test_rstdemo(tmpdir): config = TemplateConfigurationFile(os.path.join(TEST_DIR, 'rstdemo.rtt')) parser = ReStructuredTextReader() flowables = parser.parse(os.path.join(TEST_DIR, 'demo.txt')) document = config.document(flowables) with in_directory(tmpdir.strpath): document.render('demo') _, _, _, badlinks, _, _ = check_pdf_links('demo.pdf') pytest.assume(badlinks == ['table-of-contents']) if not diff_pdf(os.path.join(TEST_DIR, 'reference/demo.pdf'), 'demo.pdf'): pytest.fail('The generated PDF is different from the reference ' 'PDF.\nGenerated files can be found in {}' .format(tmpdir.strpath))
def render(source, filename): from rinoh.frontend.sphinx import nodes # load the Sphinx docutils nodes file = BytesIO('\n'.join(source).encode('utf-8')) reader = ReStructuredTextReader() doctree = reader.parse(file) document = Minimal(doctree) tmpdir = tempfile.mkdtemp() document.render(path.join(tmpdir, filename)) pdf_filename = '{}.pdf'.format(filename) with in_directory(tmpdir): _, _, _, badlinks, _, _ = check_pdf_links(pdf_filename) pytest.assume(badlinks == []) if not diff_pdf(path.join(TEST_DIR, 'reference', pdf_filename), pdf_filename): pytest.fail( 'The generated PDF is different from the reference ' 'PDF.\nGenerated files can be found in {}'.format(tmpdir))
def render_doctree(doctree, out_filename, reference_path, template_configuration=None): if template_configuration: document = template_configuration.document(doctree) else: document = MinimalTemplate(doctree) output_dir = OUTPUT_DIR / out_filename output_dir.mkdir(parents=True, exist_ok=True) document.render(output_dir / out_filename) pdf_filename = '{}.pdf'.format(out_filename) _, _, _, _, _, _, ref_outlines = \ check_pdf_links(reference_path / pdf_filename) with in_directory(output_dir): _, _, _, badlinks, _, _, outlines = check_pdf_links(pdf_filename) pytest.assume(badlinks == []) pytest.assume(ref_outlines == outlines) if not diff_pdf(reference_path / pdf_filename, pdf_filename): pytest.fail('The generated PDF is different from the reference ' 'PDF.\nGenerated files can be found in {}' .format(output_dir))
def test_rstdemo(): config = TemplateConfigurationFile(TEST_DIR / 'rstdemo.rtt') parser = ReStructuredTextReader() flowables = parser.parse(TEST_DIR / 'demo.txt') document = config.document(flowables) out_dir = OUTPUT_DIR / 'rstdemo' out_dir.mkdir(parents=True, exist_ok=True) pdf_filename = 'demo.pdf' _, _, _, _, _, _, ref_outlines = check_pdf_links(TEST_DIR / 'reference' / pdf_filename) with in_directory(out_dir): document.render('demo') _, _, _, badlinks, _, _, outlines = check_pdf_links(pdf_filename) pytest.assume(badlinks == ['table-of-contents']) pytest.assume(ref_outlines == outlines) if not diff_pdf(TEST_DIR / 'reference' / 'demo.pdf', 'demo.pdf'): pytest.fail('The generated PDF is different from the reference ' 'PDF.\nGenerated files can be found in {}' .format(out_dir))
def test_rstdemo(): config = TemplateConfigurationFile(TEST_DIR / 'rstdemo.rtt') parser = ReStructuredTextReader() flowables = parser.parse(TEST_DIR / 'demo.txt') document = config.document(flowables) out_dir = OUTPUT_DIR / 'rstdemo' out_dir.mkdir(parents=True, exist_ok=True) pdf_filename = 'demo.pdf' _, _, _, _, _, _, ref_outlines = check_pdf_links(TEST_DIR / 'reference' / pdf_filename) with in_directory(out_dir): document.render('demo') _, _, _, badlinks, _, _, outlines = check_pdf_links(pdf_filename) pytest.assume(badlinks == ['table-of-contents']) pytest.assume(ref_outlines == outlines) if not diff_pdf(TEST_DIR / 'reference' / 'demo.pdf', 'demo.pdf'): pytest.fail( 'The generated PDF is different from the reference ' 'PDF.\nGenerated files can be found in {}'.format(out_dir))
def render_doctree(doctree, out_filename, reference_path, template_configuration=None): if template_configuration: document = template_configuration.document(doctree) else: document = MinimalTemplate(doctree) output_dir = OUTPUT_DIR / out_filename output_dir.mkdir(parents=True, exist_ok=True) document.render(output_dir / out_filename) pdf_filename = '{}.pdf'.format(out_filename) _, _, _, _, _, _, ref_outlines = \ check_pdf_links(reference_path / pdf_filename) with in_directory(output_dir): _, _, _, badlinks, _, _, outlines = check_pdf_links(pdf_filename) pytest.assume(badlinks == []) pytest.assume(ref_outlines == outlines) if not diff_pdf(reference_path / pdf_filename, pdf_filename): pytest.fail('The generated PDF is different from the reference ' 'PDF.\nGenerated files can be found in {}' .format(output_dir))
def render_sphinx_project(name, project_dir, template_cfg=None, stylesheet=None): project_path = TEST_DIR / project_dir out_path = OUTPUT_DIR / name confoverrides = {} if template_cfg: confoverrides['rinoh_template'] = str(TEST_DIR / template_cfg) if stylesheet: confoverrides['rinoh_stylesheet'] = str(TEST_DIR / stylesheet) sphinx = Sphinx(srcdir=str(project_path), confdir=str(project_path), outdir=str(out_path / 'rinoh'), doctreedir=str(out_path / 'doctrees'), buildername='rinoh', confoverrides=confoverrides) sphinx.build() out_filename = '{}.pdf'.format(name) with in_directory(out_path): if not diff_pdf(TEST_DIR / 'reference' / out_filename, out_path / 'rinoh' / out_filename): pytest.fail('The generated PDF is different from the reference ' 'PDF.\nGenerated files can be found in {}' .format(out_path))