Rev 5214: Refactor tests. in file:///home/vila/src/bzr/bugs/219334-texinfo/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Fri May 7 22:50:14 BST 2010
At file:///home/vila/src/bzr/bugs/219334-texinfo/
------------------------------------------------------------
revno: 5214
revision-id: v.ladeuil+lp at free.fr-20100507215014-ee2mzr80gua5669c
parent: v.ladeuil+lp at free.fr-20100507183032-64eligeqyxpqe44c
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: texinfo
timestamp: Fri 2010-05-07 23:50:14 +0200
message:
Refactor tests.
* bzrlib/tests/doc_generate/builders/test_texinfo.py:
(TestSphinx.build, TestSphinx.create_content)
(TestSphinx.assertContent): Some helpers to reduce duplication and
better document the intent.
* bzrlib/doc_generate/writers/texinfo.py:
(TexinfoTranslator.depart_block_quote): Make it paragraph-like
with a final newline.
(TexinfoTranslator.depart_tgroup): The table is now followed by a
new line.
-------------- next part --------------
=== modified file 'bzrlib/doc_generate/writers/texinfo.py'
--- a/bzrlib/doc_generate/writers/texinfo.py 2010-05-07 18:30:32 +0000
+++ b/bzrlib/doc_generate/writers/texinfo.py 2010-05-07 21:50:14 +0000
@@ -172,7 +172,7 @@
def depart_block_quote(self, node):
node.parent.collect_chunk('@example\n')
node.parent.collect_chunk(''.join(node['chunk']))
- node.parent.collect_chunk('@end example\n')
+ node.parent.collect_chunk('@end example\n\n')
def visit_note(self, node):
pass
@@ -269,9 +269,9 @@
if self.in_toctree:
self._decorate_list(node['list_item'], node.parent.collect_text)
else:
- # FIXME: Should respect the 'bullet' attribute
self._decorate_list(node['list_item'], node.parent.collect_chunk,
'@item\n%s',
+ # FIXME: Should respect the 'bullet' attribute
'@itemize @bullet\n', '@end itemize\n')
def visit_enumerated_list(self, node):
@@ -403,8 +403,7 @@
for r in body_rows:
self._decorate_list(r[1:], rows.append,
'@tab %s\n', '@item %s\n' % r[0])
- # Leave a blank line after a table
- footer = '@end multitable\n\n'
+ footer = '@end multitable\n'
node.parent.collect_table(header + ''.join(rows) + footer)
def visit_colspec(self, node):
=== modified file 'bzrlib/tests/doc_generate/builders/test_texinfo.py'
--- a/bzrlib/tests/doc_generate/builders/test_texinfo.py 2010-05-07 18:30:32 +0000
+++ b/bzrlib/tests/doc_generate/builders/test_texinfo.py 2010-05-07 21:50:14 +0000
@@ -48,6 +48,38 @@
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):
def test_builder_loaded(self):
@@ -57,122 +89,92 @@
class TestTextGeneration(TestSphinx):
- # 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 test_special_chars(self):
- self.build_tree_contents([('index.txt', """A '@' a '{' and a '}'"""),])
- app, out, err = self.make_sphinx()
- app.build(True, [])
- # Note that since the input is a paragraph, we get two \n (even if the
- # input has none)
- self.assertFileEqual("""A '@@' a '@{' and a '@}'\n\n""", 'index.texi')
+ self.create_content("A '@' a '{' and a '}'")
+ self.assertContent("A '@@' a '@{' and a '@}'")
def test_emphasis(self):
- self.build_tree_contents([('index.txt', """*important*"""),])
- app, out, err = self.make_sphinx()
- app.build(True, [])
- # Note that since the input is a paragraph, we get two \n (even if the
- # input has none)
- self.assertFileEqual("""@emph{important}\n\n""", 'index.texi')
+ self.create_content('*important*')
+ self.assertContent('@emph{important}')
def test_strong(self):
- self.build_tree_contents([('index.txt', """**very important**"""),])
- app, out, err = self.make_sphinx()
- app.build(True, [])
- # Note that since the input is a paragraph, we get two \n (even if the
- # input has none)
- self.assertFileEqual("""@strong{very important}\n\n""", 'index.texi')
+ self.create_content('**very important**')
+ self.assertContent('@strong{very important}')
def test_literal(self):
- self.build_tree_contents([('index.txt', """the command is ``foo``"""),])
- app, out, err = self.make_sphinx()
- app.build(True, [])
- # Note that since the input is a paragraph, we get two \n (even if the
- # input has none)
- self.assertFileEqual("""the command is @code{foo}\n\n""", 'index.texi')
+ self.create_content('the command is ``foo``')
+ self.assertContent('the command is @code{foo}')
def test_paragraphs(self):
- self.build_tree_contents([('index.txt', """\
-This is a paragraph.
-
-This is another one.
-"""),])
- app, out, err = self.make_sphinx()
- app.build(True, [])
- self.assertFileEqual("""\
-This is a paragraph.
-
-This is another one.
-
-""",
- 'index.texi')
+ 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.build_tree_contents([('index.txt', """\
+ self.create_content('''\
Do this::
bzr xxx
bzr yyy
-"""),])
- app, out, err = self.make_sphinx()
- app.build(True, [])
- self.assertFileEqual("""\
+''')
+ self.assertContent('''\
Do this:
@samp{bzr xxx
bzr yyy}
-""",
- 'index.texi')
+''',
+ end='')
def test_block_quote(self):
- self.build_tree_contents([('index.txt', """\
+ self.create_content('''\
This is an ordinary paragraph, introducing a block quote.
"It is my business to know things. That is my trade."
-"""),])
- app, out, err = self.make_sphinx()
- app.build(True, [])
- self.assertFileEqual("""\
+This is another ordinary paragraph.
+''')
+ self.assertContent('''\
This is an ordinary paragraph, introducing a block quote.
@example
"It is my business to know things. That is my trade."
@end example
-""",
- 'index.texi')
+
+This is another ordinary paragraph.
+
+''',
+ # examples are not followed by an empty line
+ end='')
class TestDocumentAttributesGeneration(TestSphinx):
def test_title(self):
- self.build_tree_contents([('index.txt', """\
+ self.create_content('''\
####################
Bazaar Release Notes
####################
-"""),])
- app, out, err = self.make_sphinx()
- app.build(True, [])
- self.assertFileEqual("""@chapter Bazaar Release Notes\n""",
- 'index.texi')
+''')
+ self.assertContent('''@chapter Bazaar Release Notes\n''', end='')
class TestListGeneration(TestSphinx):
def test_bullet_list(self):
- self.build_tree_contents([('index.txt', """\
+ self.create_content('''\
* This is a bulleted list.
* It has two items, the second
item uses two lines.
-"""),])
- app, out, err = self.make_sphinx()
- app.build(True, [])
- print err.getvalue()
- self.assertFileEqual("""\
+''')
+ self.assertContent('''\
@itemize @bullet
@item
This is a bulleted list.
@@ -182,19 +184,16 @@
item uses two lines.
@end itemize
-""",
- 'index.texi')
+''',
+ end='')
def test_enumerated_list(self):
- self.build_tree_contents([('index.txt', """\
+ self.create_content('''\
#. This is a numbered list.
#. It has two items, the second
item uses two lines.
-"""),])
- app, out, err = self.make_sphinx()
- app.build(True, [])
- print err.getvalue()
- self.assertFileEqual("""\
+''')
+ self.assertContent('''\
@enumerate
@item
This is a numbered list.
@@ -204,14 +203,14 @@
item uses two lines.
@end enumerate
-""",
- 'index.texi')
+''',
+ end='')
class TestTableGeneration(TestSphinx):
def test_table(self):
- self.build_tree_contents([('index.txt', """\
+ self.create_content('''\
=========== ================
Prefix Description
=========== ================
@@ -219,13 +218,10 @@
second The second
last The last
=========== ================
-"""),])
- app, out, err = self.make_sphinx()
- app.build(True, [])
- print err.getvalue()
+''')
# FIXME: Sphinx bug ? Why are tables enclosed in a block_quote
# (translated as an @example).
- self.assertFileEqual("""\
+ self.assertContent('''\
@example
@multitable {xxxxxxxxxxx}{xxxxxxxxxxxxxxxx}
@headitem Prefix @tab Description
@@ -236,10 +232,7 @@
@item last
@tab The last
@end multitable
-
- at end example
-""",
- 'index.texi')
+ at end example''')
class TestTocTreeGeneration(TestSphinx):
@@ -268,7 +261,7 @@
"""),
])
app, out, err = self.make_sphinx()
- app.build(True, [])
+ self.build(app)
self.assertFileEqual("""\
@chapter Table of Contents
@menu
@@ -291,7 +284,7 @@
class TestSections(TestSphinx):
def test_sections(self):
- self.build_tree_contents([('index.txt', '''\
+ self.create_content('''\
###########
Chapter one
###########
@@ -329,11 +322,8 @@
"""""""""
No idea how to call that, but sphinx says it's a paragraph.
-'''),])
- app, out, err = self.make_sphinx()
- app.build(True, [])
- print err.getvalue()
- self.assertFileEqual("""\
+''')
+ self.assertContent('''\
@chapter Chapter one
Chapter introduction.
@@ -353,10 +343,7 @@
Far tooo deep to get a name
@heading thing one
-No idea how to call that, but sphinx says it's a paragraph.
-
-""",
- 'index.texi')
+No idea how to call that, but sphinx says it's a paragraph.''')
class TestFileProduction(TestSphinx):
@@ -385,7 +372,7 @@
"""),
])
app, out, err = self.make_sphinx()
- app.build(True, [])
+ self.build(app)
self.failUnlessExists('index.texi')
self.failUnlessExists('content.texi')
# FIXME: When the content of the files becomes clearer replace the
More information about the bazaar-commits
mailing list