Ejemplo n.º 1
0
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))
Ejemplo n.º 2
0
def test_sphinxdocs(tmpdir):
    from sphinx.application import Sphinx
    from rinoh.frontend.sphinx import setup as setup_rinoh_sphinx_builder

    template_configuration = Book.Configuration()
    template_configuration('title_page', show_date=False)

    sphinx = Sphinx(srcdir=SPHINX_DOC_DIR,
                    confdir=SPHINX_DOC_DIR,
                    outdir=tmpdir.join('rinoh').strpath,
                    doctreedir=tmpdir.join('doctrees').strpath,
                    buildername='html',
                    confoverrides=dict(extensions=['rinoh.frontend.sphinx']))
    setup_rinoh_sphinx_builder(sphinx)
    sphinx._init_builder('rinoh')
    sphinx.config.rinoh_template_configuration = template_configuration
    sphinx.build()

    out_file = tmpdir.join('rinoh').join('sphinx.pdf').strpath
    os.chdir(tmpdir.strpath)
    # _, _, _, badlinks, _, _ = check_pdf_links(out_file)
    # pytest.assume(badlinks == [], 'Output PDF contains broken '
    #                               'hyperlinks: {}'.format(badlinks))
    if not diff_pdf(os.path.join(TEST_DIR, 'reference/sphinx.pdf'), out_file):
        pytest.fail('The generated PDF is different from the reference PDF.\n'
                    'Generated files can be found in {}'.format(
                        tmpdir.strpath))
Ejemplo n.º 3
0
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))
Ejemplo n.º 4
0
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))
Ejemplo n.º 5
0
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))
Ejemplo n.º 6
0
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))
Ejemplo n.º 7
0
def test_rstdemo(tmpdir):
    configuration = Article.Configuration(stylesheet=sphinx_base14,
                                          abstract_location='title',
                                          table_of_contents=False)
    configuration('title_page', top_margin=2 * CM)

    with open(os.path.join(TEST_DIR, 'demo.txt')) as file:
        parser = ReStructuredTextReader()
        flowables = parser.parse(file)
    document = Article(flowables, configuration=configuration, backend=pdf)
    os.chdir(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.\n'
                    'Generated files can be found in {}'.format(
                        tmpdir.strpath))
Ejemplo n.º 8
0
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))
Ejemplo n.º 9
0
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))
Ejemplo n.º 10
0
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))
Ejemplo n.º 11
0
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))
Ejemplo n.º 12
0
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))
Ejemplo n.º 13
0
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))