summaryrefslogtreecommitdiff
path: root/tests/test_build_texinfo.py
blob: 2f519435af6924202aa6c7e4facdd4f18e1f7358 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# -*- coding: utf-8 -*-
"""
    test_build_texinfo
    ~~~~~~~~~~~~~~~~~~

    Test the build process with Texinfo builder with the test root.

    :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
"""

import os
import re
import sys
from StringIO import StringIO
from subprocess import Popen, PIPE

from sphinx.writers.texinfo import TexinfoTranslator

from util import test_root, SkipTest, remove_unicode_literals, with_app
from test_build_html import ENV_WARNINGS


def teardown_module():
    (test_root / '_build').rmtree(True)


texinfo_warnfile = StringIO()

TEXINFO_WARNINGS = ENV_WARNINGS + """\
None:None: WARNING: citation not found: missing
None:None: WARNING: no matching candidate for image URI u'foo.\\*'
None:None: WARNING: no matching candidate for image URI u'svgimg.\\*'
"""

if sys.version_info >= (3, 0):
    TEXINFO_WARNINGS = remove_unicode_literals(TEXINFO_WARNINGS)


@with_app(buildername='texinfo', warning=texinfo_warnfile, cleanenv=True)
def test_texinfo(app):
    TexinfoTranslator.ignore_missing_images = True
    app.builder.build_all()
    texinfo_warnings = texinfo_warnfile.getvalue().replace(os.sep, '/')
    texinfo_warnings_exp = TEXINFO_WARNINGS % {
            'root': re.escape(app.srcdir.replace(os.sep, '/'))}
    assert re.match(texinfo_warnings_exp + '$', texinfo_warnings), \
           'Warnings don\'t match:\n' + \
           '--- Expected (regex):\n' + texinfo_warnings_exp + \
           '--- Got:\n' + texinfo_warnings
    # now, try to run makeinfo over it
    cwd = os.getcwd()
    os.chdir(app.outdir)
    try:
        try:
            p = Popen(['makeinfo', '--no-split', 'SphinxTests.texi'],
                      stdout=PIPE, stderr=PIPE)
        except OSError:
            raise SkipTest  # most likely makeinfo was not found
        else:
            stdout, stderr = p.communicate()
            retcode = p.returncode
            if retcode != 0:
                print stdout
                print stderr
                del app.cleanup_trees[:]
                assert False, 'makeinfo exited with return code %s' % retcode
    finally:
        os.chdir(cwd)