Rev 5220: Separate builder and writer tests. in file:///home/vila/src/bzr/bugs/219334-texinfo/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Tue Jul 6 14:22:33 BST 2010
At file:///home/vila/src/bzr/bugs/219334-texinfo/
------------------------------------------------------------
revno: 5220
revision-id: v.ladeuil+lp at free.fr-20100706132232-d9byjdy2i882asgr
parent: v.ladeuil+lp at free.fr-20100705170531-116pjmnksoysxr55
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: texinfo
timestamp: Tue 2010-07-06 15:22:32 +0200
message:
Separate builder and writer tests.
-------------- next part --------------
=== modified file 'bzrlib/tests/doc_generate/__init__.py'
--- a/bzrlib/tests/doc_generate/__init__.py 2010-04-29 15:41:20 +0000
+++ b/bzrlib/tests/doc_generate/__init__.py 2010-07-06 13:22:32 +0000
@@ -16,6 +16,16 @@
"""Documentation generation tests."""
+import os
+from bzrlib import tests
+from bzrlib.doc_generate import (
+ # FIXME: doc/en/conf.py should be used here, or rather merged into
+ # bzrlib/doc_generate/conf.py -- vila 20100429
+ conf,
+ )
+from bzrlib.tests import features
+
+
def load_tests(basic_tests, module, loader):
suite = loader.suiteClass()
# add the tests for this module
@@ -23,6 +33,7 @@
testmod_names = [
'builders',
+ 'writers',
]
# add the tests for the sub modules
suite.addTests(loader.loadTestsFromModuleNames(
@@ -30,3 +41,59 @@
for name in testmod_names]))
return suite
+
+
+class TestSphinx(tests.TestCaseInTempDir):
+ """Base class for sphinx tests.
+
+ This is used for both the builder and the writer until a better solution is
+ found to test at a lower level.
+ """
+
+ _test_needs_features = [features.sphinx]
+
+ def make_sphinx(self):
+ out = tests.StringIOWrapper()
+ err = tests.StringIOWrapper()
+ from sphinx import application
+ app = application.Sphinx(
+ '.', confdir=os.path.dirname(conf.__file__), outdir='.',
+ doctreedir='.',
+ buildername='texinfo',
+ confoverrides={},
+ status=out, warning=err,
+ freshenv=True)
+ return app, out, err
+
+ def build(self, app, all_files=True, file_names=None):
+ if file_names is None:
+ file_names = []
+ app.build(all_files, file_names)
+
+ # FIXME: something smells wrong here as we can't process a single file
+ # alone. On top of that, it seems the doc tree must contain an index.txt
+ # file. We may need a texinfo builder ? -- vila 20100505
+
+ def create_content(self, content):
+ """Put content into a single file.
+
+ This is appropriate for simple tests about the content of a single file.
+ """
+ app, out, err = self.make_sphinx()
+ self.build_tree_contents([('index.txt', content),])
+ self.build(app)
+
+ def assertContent(self, expected, end=None):
+ """Check the content of the file created with creste_content().
+
+ Most texinfo constructs can be tested this way without caring for any
+ boilerplate that texinfo may require at the beginning or the end of the
+ file.
+ """
+ if end is None:
+ # By default we test constructs that are embedded into a paragraph
+ # which always end with two \n (even if the input has none)
+ end = '\n\n'
+ self.assertFileEqual(expected + end, 'index.texi')
+
+
=== modified file 'bzrlib/tests/doc_generate/builders/test_texinfo.py'
--- a/bzrlib/tests/doc_generate/builders/test_texinfo.py 2010-07-05 17:05:31 +0000
+++ b/bzrlib/tests/doc_generate/builders/test_texinfo.py 2010-07-06 13:22:32 +0000
@@ -16,16 +16,15 @@
"""sphinx texinfo builder tests."""
-import os
-from sphinx import application
-
from bzrlib import tests
from bzrlib.doc_generate import (
# FIXME: doc/en/conf.py should be used here, or rather merged into
# bzrlib/doc_generate/conf.py -- vila 20100429
conf,
)
-from bzrlib.tests import features
+from bzrlib.tests import (
+ doc_generate as test_dg, # Avoid clash with from bzrlib import doc_generate
+ )
class TestBuilderDefined(tests.TestCase):
@@ -34,319 +33,14 @@
self.assertTrue('bzrlib.doc_generate.builders.texinfo'
in conf.extensions)
-class TestSphinx(tests.TestCaseInTempDir):
-
- def make_sphinx(self):
- out = tests.StringIOWrapper()
- err = tests.StringIOWrapper()
- app = application.Sphinx(
- '.', confdir=os.path.dirname(conf.__file__), outdir='.',
- doctreedir='.',
- buildername='texinfo',
- confoverrides={},
- status=out, warning=err,
- freshenv=True)
- return app, out, err
-
- def build(self, app, all_files=True, file_names=None):
- if file_names is None:
- file_names = []
- app.build(all_files, file_names)
-
- # FIXME: something smells wrong here as we can't process a single file
- # alone. On top of that, it seems the doc tree must contain an index.txt
- # file. We may need a texinfo builder ? -- vila 20100505
-
- def create_content(self, content):
- """Put content into a single file.
-
- This is appropriate for simple tests about the content of a single file.
- """
- app, out, err = self.make_sphinx()
- self.build_tree_contents([('index.txt', content),])
- self.build(app)
-
- def assertContent(self, expected, end=None):
- """Check the content of the file created with creste_content().
-
- Most texinfo constructs can be tested this way without caring for any
- boilerplate that texinfo may require at the beginning or the end of the
- file.
- """
- if end is None:
- # By default we test constructs that are embedded into a paragraph
- # which always end with two \n (even if the input has none)
- end = '\n\n'
- self.assertFileEqual(expected + end, 'index.texi')
-
-
-class TestBuilderLoaded(TestSphinx):
+class TestBuilderLoaded(test_dg.TestSphinx):
def test_builder_loaded(self):
app, out, err = self.make_sphinx()
self.assertTrue('texinfo' in app.builderclasses)
-class TestTextGeneration(TestSphinx):
-
- def test_special_chars(self):
- self.create_content("A '@' a '{' and a '}'")
- self.assertContent("A '@@' a '@{' and a '@}'")
-
- def test_emphasis(self):
- self.create_content('*important*')
- self.assertContent('@emph{important}')
-
- def test_strong(self):
- self.create_content('**very important**')
- self.assertContent('@strong{very important}')
-
- def test_literal(self):
- self.create_content('the command is ``foo``')
- self.assertContent('the command is @code{foo}')
-
- def test_paragraphs(self):
- self.create_content('''\
-This is a paragraph.
-
-This is another one.
-''')
- self.assertContent('''\
-This is a paragraph.
-
-This is another one.''')
-
- def test_literal_block(self):
- self.create_content('''\
-Do this::
-
- bzr xxx
- bzr yyy
-''')
- self.assertContent('''\
-Do this:
-
- at samp{bzr xxx
-bzr yyy}
-
-''',
- end='')
-
- def test_block_quote(self):
- self.create_content('''\
-This is an ordinary paragraph, introducing a block quote.
-
- "It is my business to know things. That is my trade."
-
-This is another ordinary paragraph.
-''')
- self.assertContent('''\
-This is an ordinary paragraph, introducing a block quote.
-
- at example
-"It is my business to know things. That is my trade."
-
- at end example
-
-This is another ordinary paragraph.
-
-''',
- # examples are not followed by an empty line
- end='')
-
-
-class TestDocumentAttributesGeneration(TestSphinx):
-
- def test_title(self):
- self.create_content('''\
-####################
-Bazaar Release Notes
-####################
-''')
- self.assertContent('@chapter Bazaar Release Notes\n', end='')
-
-
-class TestListGeneration(TestSphinx):
-
- def test_bullet_list(self):
- self.create_content('''\
-* This is a bulleted list.
-* It has two items, the second
- item uses two lines.
-''')
- self.assertContent('''\
- at itemize @bullet
- at item
-This is a bulleted list.
-
- at item
-It has two items, the second
-item uses two lines.
-
- at end itemize
-''',
- end='')
-
- def test_enumerated_list(self):
- self.create_content('''\
-#. This is a numbered list.
-#. It has two items, the second
- item uses two lines.
-''')
- self.assertContent('''\
- at enumerate
- at item
-This is a numbered list.
-
- at item
-It has two items, the second
-item uses two lines.
-
- at end enumerate
-''',
- end='')
-
-
-class TestTableGeneration(TestSphinx):
-
- def test_table(self):
- self.create_content('''\
- =========== ================
- Prefix Description
- =========== ================
- first The first
- second The second
- last The last
- =========== ================
-''')
- # FIXME: Sphinx bug ? Why are tables enclosed in a block_quote
- # (translated as an @example).
- self.assertContent('''\
- at example
- at multitable {xxxxxxxxxxx}{xxxxxxxxxxxxxxxx}
- at headitem Prefix @tab Description
- at item first
- at tab The first
- at item second
- at tab The second
- at item last
- at tab The last
- at end multitable
- at end example''')
-
-
-class TestTocTreeGeneration(TestSphinx):
-
- def test_toctree(self):
- self.build_tree_contents(
- [('index.txt', """
-Table of Contents
-=================
-
-.. toctree::
- :maxdepth: 1
-
- bzr 0.0.8 <bzr-0.0.8>
-"""),
- ('bzr-0.0.8.txt', """
-
-bzr 0.0.8
-*********
-
-Improvements
-============
-
-* Adding a file whose parent directory is not versioned will
- implicitly add the parent, and so on up to the root.
-"""),
- ])
- app, out, err = self.make_sphinx()
- self.build(app)
- self.assertFileEqual("""\
- at chapter Table of Contents
- at menu
-* bzr 0.0.8: (bzr-0.0.8.info)bzr 0.0.8.
- at end menu
-""",
- 'index.texi')
- self.assertFileEqual("""\
- at chapter bzr 0.0.8
- at section Improvements
- at itemize @bullet
- at item
-Adding a file whose parent directory is not versioned will
-implicitly add the parent, and so on up to the root.
-
- at end itemize
-""",
- 'bzr-0.0.8.texi')
-
-class TestSections(TestSphinx):
-
- def test_sections(self):
- self.create_content('''\
-###########
-Chapter one
-###########
-
-Chapter introduction.
-
-***********
-section one
-***********
-
-The first section.
-
-
-subsection one
-==============
-
-The first subsection.
-
-subsection two
-==============
-
-The second subsection.
-
-subsubsection one
------------------
-
-Here is sus sub section one.
-
-blob one
-^^^^^^^^
-
-Far tooo deep to get a name
-
-thing one
-"""""""""
-
-No idea how to call that, but sphinx says it's a paragraph.
-''')
- self.assertContent('''\
- at chapter Chapter one
-Chapter introduction.
-
- at section section one
-The first section.
-
- at subsection subsection one
-The first subsection.
-
- at subsection subsection two
-The second subsection.
-
- at subsubsection subsubsection one
-Here is sus sub section one.
-
- at heading blob one
-Far tooo deep to get a name
-
- at heading thing one
-No idea how to call that, but sphinx says it's a paragraph.''')
-
-
-class TestFileProduction(TestSphinx):
+class TestFileProduction(test_dg.TestSphinx):
def test_files_generated(self):
self.build_tree_contents(
@@ -375,13 +69,3 @@
self.build(app)
self.failUnlessExists('index.texi')
self.failUnlessExists('content.texi')
- # FIXME: When the content of the files becomes clearer replace the
- # assertion above by the ones below -- vila 20100504
-# self.assertFileEqual("""\
-# """,
-# 'content.texi')
-# self.assertFileEqual("""\
-# """,
-# 'index.texi')
-#
-
=== added directory 'bzrlib/tests/doc_generate/writers'
=== added file 'bzrlib/tests/doc_generate/writers/__init__.py'
--- a/bzrlib/tests/doc_generate/writers/__init__.py 1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/doc_generate/writers/__init__.py 2010-07-06 13:22:32 +0000
@@ -0,0 +1,36 @@
+# Copyright (C) 2010 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+"""Sphinx writers tests."""
+
+from bzrlib.tests import features
+
+def load_tests(basic_tests, module, loader):
+ suite = loader.suiteClass()
+ # add the tests for this module
+ suite.addTests(basic_tests)
+
+ if features.sphinx.available():
+ testmod_names = [
+ 'texinfo',
+ ]
+ # add the tests for the sub modules
+ suite.addTests(loader.loadTestsFromModuleNames(
+ ['bzrlib.tests.doc_generate.writers.test_' + name
+ for name in testmod_names]))
+
+ return suite
=== added file 'bzrlib/tests/doc_generate/writers/test_texinfo.py'
--- a/bzrlib/tests/doc_generate/writers/test_texinfo.py 1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/doc_generate/writers/test_texinfo.py 2010-07-06 13:22:32 +0000
@@ -0,0 +1,280 @@
+# Copyright (C) 2010 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+"""sphinx texinfo writer tests."""
+
+from bzrlib.tests import (
+ doc_generate as test_dg, # Avoid clash with from bzrlib import doc_generate
+ )
+
+
+class TestTextGeneration(test_dg.TestSphinx):
+
+ def test_special_chars(self):
+ self.create_content("A '@' a '{' and a '}'")
+ self.assertContent("A '@@' a '@{' and a '@}'")
+
+ def test_emphasis(self):
+ self.create_content('*important*')
+ self.assertContent('@emph{important}')
+
+ def test_strong(self):
+ self.create_content('**very important**')
+ self.assertContent('@strong{very important}')
+
+ def test_literal(self):
+ self.create_content('the command is ``foo``')
+ self.assertContent('the command is @code{foo}')
+
+ def test_paragraphs(self):
+ self.create_content('''\
+This is a paragraph.
+
+This is another one.
+''')
+ self.assertContent('''\
+This is a paragraph.
+
+This is another one.''')
+
+ def test_literal_block(self):
+ self.create_content('''\
+Do this::
+
+ bzr xxx
+ bzr yyy
+''')
+ self.assertContent('''\
+Do this:
+
+ at samp{bzr xxx
+bzr yyy}
+
+''',
+ end='')
+
+ def test_block_quote(self):
+ self.create_content('''\
+This is an ordinary paragraph, introducing a block quote.
+
+ "It is my business to know things. That is my trade."
+
+This is another ordinary paragraph.
+''')
+ self.assertContent('''\
+This is an ordinary paragraph, introducing a block quote.
+
+ at example
+"It is my business to know things. That is my trade."
+
+ at end example
+
+This is another ordinary paragraph.
+
+''',
+ # examples are not followed by an empty line
+ end='')
+
+
+class TestDocumentAttributesGeneration(test_dg.TestSphinx):
+
+ def test_title(self):
+ self.create_content('''\
+####################
+Bazaar Release Notes
+####################
+''')
+ self.assertContent('@chapter Bazaar Release Notes\n', end='')
+
+
+class TestListGeneration(test_dg.TestSphinx):
+
+ def test_bullet_list(self):
+ self.create_content('''\
+* This is a bulleted list.
+* It has two items, the second
+ item uses two lines.
+''')
+ self.assertContent('''\
+ at itemize @bullet
+ at item
+This is a bulleted list.
+
+ at item
+It has two items, the second
+item uses two lines.
+
+ at end itemize
+''',
+ end='')
+
+ def test_enumerated_list(self):
+ self.create_content('''\
+#. This is a numbered list.
+#. It has two items, the second
+ item uses two lines.
+''')
+ self.assertContent('''\
+ at enumerate
+ at item
+This is a numbered list.
+
+ at item
+It has two items, the second
+item uses two lines.
+
+ at end enumerate
+''',
+ end='')
+
+
+class TestTableGeneration(test_dg.TestSphinx):
+
+ def test_table(self):
+ self.create_content('''\
+ =========== ================
+ Prefix Description
+ =========== ================
+ first The first
+ second The second
+ last The last
+ =========== ================
+''')
+ # FIXME: Sphinx bug ? Why are tables enclosed in a block_quote
+ # (translated as an @example).
+ self.assertContent('''\
+ at example
+ at multitable {xxxxxxxxxxx}{xxxxxxxxxxxxxxxx}
+ at headitem Prefix @tab Description
+ at item first
+ at tab The first
+ at item second
+ at tab The second
+ at item last
+ at tab The last
+ at end multitable
+ at end example''')
+
+
+class TestTocTreeGeneration(test_dg.TestSphinx):
+
+ def test_toctree(self):
+ self.build_tree_contents(
+ [('index.txt', """
+Table of Contents
+=================
+
+.. toctree::
+ :maxdepth: 1
+
+ bzr 0.0.8 <bzr-0.0.8>
+"""),
+ ('bzr-0.0.8.txt', """
+
+bzr 0.0.8
+*********
+
+Improvements
+============
+
+* Adding a file whose parent directory is not versioned will
+ implicitly add the parent, and so on up to the root.
+"""),
+ ])
+ app, out, err = self.make_sphinx()
+ self.build(app)
+ self.assertFileEqual("""\
+ at chapter Table of Contents
+ at menu
+* bzr 0.0.8: (bzr-0.0.8.info)bzr 0.0.8.
+ at end menu
+""",
+ 'index.texi')
+ self.assertFileEqual("""\
+ at chapter bzr 0.0.8
+ at section Improvements
+ at itemize @bullet
+ at item
+Adding a file whose parent directory is not versioned will
+implicitly add the parent, and so on up to the root.
+
+ at end itemize
+""",
+ 'bzr-0.0.8.texi')
+
+class TestSections(test_dg.TestSphinx):
+
+ def test_sections(self):
+ self.create_content('''\
+###########
+Chapter one
+###########
+
+Chapter introduction.
+
+***********
+section one
+***********
+
+The first section.
+
+
+subsection one
+==============
+
+The first subsection.
+
+subsection two
+==============
+
+The second subsection.
+
+subsubsection one
+-----------------
+
+Here is sus sub section one.
+
+blob one
+^^^^^^^^
+
+Far tooo deep to get a name
+
+thing one
+"""""""""
+
+No idea how to call that, but sphinx says it's a paragraph.
+''')
+ self.assertContent('''\
+ at chapter Chapter one
+Chapter introduction.
+
+ at section section one
+The first section.
+
+ at subsection subsection one
+The first subsection.
+
+ at subsection subsection two
+The second subsection.
+
+ at subsubsection subsubsection one
+Here is sus sub section one.
+
+ at heading blob one
+Far tooo deep to get a name
+
+ at heading thing one
+No idea how to call that, but sphinx says it's a paragraph.''')
More information about the bazaar-commits
mailing list