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))
Beispiel #2
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))
Beispiel #3
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))
Beispiel #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))
Beispiel #5
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))
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))
Beispiel #7
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))
Beispiel #8
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))
Beispiel #9
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))