1
# Copyright (C) 2010, 2011 Canonical Ltd
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.
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.
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
17
"""Documentation generation tests."""
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
26
from bzrlib.tests import features
29
def load_tests(basic_tests, module, loader):
30
suite = loader.suiteClass()
31
# add the tests for this module
32
suite.addTests(basic_tests)
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]))
46
class TestSphinx(tests.TestCaseInTempDir):
47
"""Base class for sphinx tests.
49
This is used for both the builder and the writer until a better solution is
50
found to test at a lower level.
53
_test_needs_features = [features.sphinx]
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) )
58
return tuple(map(int, features.sphinx.module.__version__.split('.')))
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='.',
67
buildername='texinfo',
69
status=out, warning=err,
73
def build(self, app, all_files=True, file_names=None):
74
if file_names is None:
76
app.build(all_files, file_names)
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
82
def create_content(self, content):
83
"""Put content into a single file.
85
This is appropriate for simple tests about the content of a single file.
87
app, out, err = self.make_sphinx()
88
self.build_tree_contents([('index.txt', content),])
91
def assertContent(self, expected, header=None, end=None):
92
"""Check the content of the file created with creste_content().
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
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.
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)
111
self.assertFileEqual(header + expected + end, 'index.texi')