Merged revisions 65640,65675,65699,65701 via svnmerge from

svn+ssh://pythondev@svn.python.org/doctools/branches/0.4.x

........
  r65640 | georg.brandl | 2008-08-11 16:11:17 +0200 (Mon, 11 Aug 2008) | 2 lines

  More info in intro.
........
  r65675 | georg.brandl | 2008-08-14 13:53:02 +0200 (Thu, 14 Aug 2008) | 2 lines

  #3546: add missing linebreak.
........
  r65699 | benjamin.peterson | 2008-08-15 23:02:22 +0200 (Fri, 15 Aug 2008) | 4 lines

  rename util.with_testapp to util.with_app; nose was running it

  also make an assert more informative
........
  r65701 | benjamin.peterson | 2008-08-16 00:00:54 +0200 (Sat, 16 Aug 2008) | 1 line

  add some tests for sphinx.application
........
This commit is contained in:
Georg Brandl 2008-08-23 15:04:45 +00:00
parent 5f0c30ac90
commit f0605a40a4
7 changed files with 77 additions and 15 deletions

View File

@ -3,15 +3,18 @@ Introduction
This is the documentation for the Sphinx documentation builder. Sphinx is a
tool that translates a set of reStructuredText_ source files into various output
formats, automatically producing cross-references, indices etc.
formats, automatically producing cross-references, indices etc. That is, if
you have a directory containing a bunch of reST-formatted documents (and
possibly subdirectories of docs in there as well), Sphinx can generate a
nicely-organized arrangement of HTML files (in some other directory) for easy
browsing and navigation. But from the same source, it can also generate a
LaTeX file that you can compile into a PDF version of the documents.
The focus is on hand-written documentation, rather than auto-generated API docs.
Though there is limited support for that kind of docs as well (which is intended
to be freely mixed with hand-written content), if you need pure API docs have a
look at `Epydoc <http://epydoc.sf.net/>`_, which also understands reST.
.. XXX web app
Prerequisites
-------------

View File

@ -285,7 +285,7 @@ Doctest summary
group.name, filename, code[0].lineno)
if not test.examples:
self._out('WARNING: no examples in doctest block at '
+ filename + ', line %s' % code[0].lineno)
+ filename + ', line %s\n' % code[0].lineno)
continue
for example in test.examples:
# apply directive's comparison options

59
tests/test_application.py Normal file
View File

@ -0,0 +1,59 @@
# -*- coding: utf-8 -*-
"""
test_application
~~~~~~~~~~~~~~~~
Test the Sphinx class.
:copyright: 2008 by Benjamin Peterson.
:license: BSD.
"""
from StringIO import StringIO
from sphinx.application import ExtensionError
from util import *
@with_app()
def test_events(app):
def empty(): pass
raises_msg(ExtensionError, "Unknown event name: invalid",
app.connect, "invalid", empty)
app.add_event("my_event")
raises_msg(ExtensionError, "Event 'my_event' already present",
app.add_event, "my_event")
def mock_callback(a_app, *args):
assert a_app is app
assert emit_args == args
return "ret"
emit_args = (1, 3, "string")
listener_id = app.connect("my_event", mock_callback)
assert app.emit("my_event", *emit_args) == ["ret"], "Callback not called"
app.disconnect(listener_id)
assert app.emit("my_event", *emit_args) == [], \
"Callback called when disconnected"
def test_output():
status, warnings = StringIO(), StringIO()
app = TestApp(status=status, warning=warnings)
try:
status.truncate(0) # __init__ writes to status
app.info("Nothing here...")
assert status.getvalue() == "Nothing here...\n"
status.truncate(0)
app.info("Nothing here...", True)
assert status.getvalue() == "Nothing here..."
old_count = app._warncount
app.warn("Bad news!")
assert warnings.getvalue() == "WARNING: Bad news!\n"
assert app._warncount == old_count + 1
finally:
app.cleanup()

View File

@ -65,7 +65,7 @@ class NslessParser(ET.XMLParser):
return name
@with_testapp(buildername='html', warning=html_warnfile)
@with_app(buildername='html', warning=html_warnfile)
def test_html(app):
app.builder.build_all()
html_warnings = html_warnfile.getvalue().replace(os.sep, '/')
@ -94,7 +94,7 @@ def test_html(app):
'path %s in %s' % (text, path, fname))
@with_testapp(buildername='latex', warning=latex_warnfile)
@with_app(buildername='latex', warning=latex_warnfile)
def test_latex(app):
LaTeXTranslator.ignore_missing_images = True
app.builder.build_all()
@ -124,14 +124,14 @@ def test_latex(app):
# just let the remaining ones run for now
@with_testapp(buildername='linkcheck')
@with_app(buildername='linkcheck')
def test_linkcheck(app):
app.builder.build_all()
@with_testapp(buildername='text')
@with_app(buildername='text')
def test_text(app):
app.builder.build_all()
@with_testapp(buildername='changes', cleanenv=True)
@with_app(buildername='changes', cleanenv=True)
def test_changes(app):
app.builder.build_all()

View File

@ -15,7 +15,7 @@ from util import *
from sphinx.application import ExtensionError
@with_testapp(confoverrides={'master_doc': 'master', 'nonexisting_value': 'True'})
@with_app(confoverrides={'master_doc': 'master', 'nonexisting_value': 'True'})
def test_core_config(app):
cfg = app.config
@ -61,7 +61,7 @@ def test_core_config(app):
assert cfg['project'] == cfg.project == 'Sphinx Tests'
@with_testapp()
@with_app()
def test_extension_values(app):
cfg = app.config

View File

@ -12,6 +12,6 @@
from util import *
@with_testapp(confoverrides={'language': 'de'})
@with_app(confoverrides={'language': 'de'})
def test_i18n(app):
app.builder.build_all()

View File

@ -25,7 +25,7 @@ from nose import tools
__all__ = [
'test_root',
'raises', 'raises_msg', 'Struct',
'ListOutput', 'TestApp', 'with_testapp',
'ListOutput', 'TestApp', 'with_app',
'path', 'with_tempdir', 'write_file',
'sprint',
]
@ -60,7 +60,7 @@ def raises_msg(exc, msg, func, *args, **kwds):
try:
func(*args, **kwds)
except exc, err:
assert msg in str(err)
assert msg in str(err), "\"%s\" not in \"%s\"" % (msg, err)
else:
raise AssertionError('%s did not raise %s' %
(func.__name__, _excstr(exc)))
@ -140,7 +140,7 @@ class TestApp(application.Sphinx):
shutil.rmtree(tree, True)
def with_testapp(*args, **kwargs):
def with_app(*args, **kwargs):
"""
Make a TestApp with args and kwargs, pass it to the test and clean up
properly.