~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/doc_generate/__init__.py

  • Committer: Patch Queue Manager
  • Date: 2016-02-01 19:56:05 UTC
  • mfrom: (6615.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20160201195605-o7rl92wf6uyum3fk
(vila) Open trunk again as 2.8b1 (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2010 Canonical Ltd
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
 
 
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
 
 
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',
36
 
        'writers',
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
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
 
 
55
 
    def make_sphinx(self):
56
 
        out = tests.StringIOWrapper()
57
 
        err = tests.StringIOWrapper()
58
 
        from sphinx import application
59
 
        app = application.Sphinx(
60
 
            '.', confdir=os.path.dirname(conf.__file__), outdir='.',
61
 
            doctreedir='.',
62
 
            buildername='texinfo',
63
 
            confoverrides={},
64
 
            status=out, warning=err,
65
 
            freshenv=True)
66
 
        return app, out, err
67
 
 
68
 
    def build(self, app, all_files=True, file_names=None):
69
 
        if file_names is None:
70
 
            file_names = []
71
 
        app.build(all_files, file_names)
72
 
 
73
 
    # FIXME: something smells wrong here as we can't process a single file
74
 
    # alone. On top of that, it seems the doc tree must contain an index.txt
75
 
    # file. We may need a texinfo builder ? -- vila 20100505
76
 
 
77
 
    def create_content(self, content):
78
 
        """Put content into a single file.
79
 
 
80
 
        This is appropriate for simple tests about the content of a single file.
81
 
        """
82
 
        app, out, err = self.make_sphinx()
83
 
        self.build_tree_contents([('index.txt', content),])
84
 
        self.build(app)
85
 
 
86
 
    def assertContent(self, expected, header=None, end=None):
87
 
        """Check the content of the file created with creste_content().
88
 
 
89
 
        Most texinfo constructs can be tested this way without caring for any
90
 
        boilerplate that texinfo may require at the beginning or the end of the
91
 
        file.
92
 
        """
93
 
        if header is None:
94
 
            # default boilerplate
95
 
            header = '''\
96
 
This file has been converted using a beta rst->texinfo converter. 
97
 
Most of the info links are currently bogus, don't report bugs about them,
98
 
this is currently worked on.
99
 
@node Top
100
 
@top Placeholder
101
 
'''
102
 
        if end is None:
103
 
            # By default we test constructs that are embedded into a paragraph
104
 
            # which always end with two \n (even if the input has none)
105
 
            end = '\n\n'
106
 
        self.assertFileEqual(header + expected + end, 'index.texi')
107
 
 
108