~bzr-pqm/bzr/bzr.dev

5557.1.7 by John Arbash Meinel
Merge in the bzr.dev 5582
1
# Copyright (C) 2010, 2011 Canonical Ltd
5193.6.2 by Vincent Ladeuil
First texinfo test.
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17
"""Documentation generation tests."""
18
5193.6.26 by Vincent Ladeuil
Separate builder and writer tests.
19
import os
20
from bzrlib import tests
21
from bzrlib.doc_generate import (
22
    # FIXME: doc/en/conf.py should be used here, or rather merged into
23
    # bzrlib/doc_generate/conf.py -- vila 20100429
24
    conf,
25
    )
26
from bzrlib.tests import features
27
28
5193.6.2 by Vincent Ladeuil
First texinfo test.
29
def load_tests(basic_tests, module, loader):
30
    suite = loader.suiteClass()
31
    # add the tests for this module
32
    suite.addTests(basic_tests)
33
34
    testmod_names = [
35
        'builders',
5193.6.26 by Vincent Ladeuil
Separate builder and writer tests.
36
        'writers',
5193.6.2 by Vincent Ladeuil
First texinfo test.
37
        ]
38
    # add the tests for the sub modules
39
    suite.addTests(loader.loadTestsFromModuleNames(
40
            ['bzrlib.tests.doc_generate.' + name
41
             for name in testmod_names]))
42
43
    return suite
5193.6.26 by Vincent Ladeuil
Separate builder and writer tests.
44
45
46
class TestSphinx(tests.TestCaseInTempDir):
47
    """Base class for sphinx tests.
48
49
    This is used for both the builder and the writer until a better solution is
50
    found to test at a lower level.
51
    """
52
53
    _test_needs_features = [features.sphinx]
54
5563.1.1 by Vincent Ladeuil
Skip tests that don't support newer sphinx versions
55
    def sphinx_version(self):
56
        # Convert to a tuple to avoid traps in string comparison
57
        # ( '1.12' < '1.6' but (1, 12) > (1, 6) )
5563.1.2 by Vincent Ladeuil
Nice jma's catch, we need ints.
58
        return tuple(map(int, features.sphinx.module.__version__.split('.')))
5563.1.1 by Vincent Ladeuil
Skip tests that don't support newer sphinx versions
59
5193.6.26 by Vincent Ladeuil
Separate builder and writer tests.
60
    def make_sphinx(self):
61
        out = tests.StringIOWrapper()
62
        err = tests.StringIOWrapper()
63
        from sphinx import application
64
        app = application.Sphinx(
65
            '.', confdir=os.path.dirname(conf.__file__), outdir='.',
66
            doctreedir='.',
67
            buildername='texinfo',
68
            confoverrides={},
69
            status=out, warning=err,
70
            freshenv=True)
71
        return app, out, err
72
73
    def build(self, app, all_files=True, file_names=None):
74
        if file_names is None:
75
            file_names = []
76
        app.build(all_files, file_names)
77
78
    # FIXME: something smells wrong here as we can't process a single file
79
    # alone. On top of that, it seems the doc tree must contain an index.txt
80
    # file. We may need a texinfo builder ? -- vila 20100505
81
82
    def create_content(self, content):
83
        """Put content into a single file.
84
85
        This is appropriate for simple tests about the content of a single file.
86
        """
87
        app, out, err = self.make_sphinx()
88
        self.build_tree_contents([('index.txt', content),])
89
        self.build(app)
90
5193.6.33 by Vincent Ladeuil
Fix fallouts from the top node addition.
91
    def assertContent(self, expected, header=None, end=None):
5193.6.26 by Vincent Ladeuil
Separate builder and writer tests.
92
        """Check the content of the file created with creste_content().
93
94
        Most texinfo constructs can be tested this way without caring for any
95
        boilerplate that texinfo may require at the beginning or the end of the
96
        file.
97
        """
5193.6.33 by Vincent Ladeuil
Fix fallouts from the top node addition.
98
        if header is None:
99
            # default boilerplate
5193.6.34 by Vincent Ladeuil
Make sure we don't get bug reports about the known broken info links.
100
            header = '''\
101
This file has been converted using a beta rst->texinfo converter. 
102
Most of the info links are currently bogus, don't report bugs about them,
103
this is currently worked on.
104
@node Top
105
@top Placeholder
106
'''
5193.6.26 by Vincent Ladeuil
Separate builder and writer tests.
107
        if end is None:
108
            # By default we test constructs that are embedded into a paragraph
109
            # which always end with two \n (even if the input has none)
110
            end = '\n\n'
5193.6.33 by Vincent Ladeuil
Fix fallouts from the top node addition.
111
        self.assertFileEqual(header + expected + end, 'index.texi')
5193.6.26 by Vincent Ladeuil
Separate builder and writer tests.
112
113