2008-06-05 03:58:43 -05:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
Sphinx test suite utilities
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
:copyright: 2008 by Georg Brandl.
|
|
|
|
:license: BSD.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import StringIO
|
|
|
|
import tempfile
|
|
|
|
|
|
|
|
from sphinx import application, builder
|
|
|
|
|
|
|
|
from path import path
|
|
|
|
|
|
|
|
|
|
|
|
__all__ = [
|
Merged revisions 65138,65145-65146,65268-65273 via svnmerge from
svn+ssh://pythondev@svn.python.org/doctools/branches/0.4.x
........
r65138 | georg.brandl | 2008-07-19 15:42:35 +0200 (Sat, 19 Jul 2008) | 2 lines
#3416: fix missing parameter.
........
r65145 | georg.brandl | 2008-07-19 20:01:25 +0200 (Sat, 19 Jul 2008) | 2 lines
Now that we don't ship Jinja anymore by default the comment can go.
........
r65146 | georg.brandl | 2008-07-19 20:01:51 +0200 (Sat, 19 Jul 2008) | 2 lines
Reread documents with globbed toctrees when files are removed/added.
........
r65268 | georg.brandl | 2008-07-29 10:21:33 +0200 (Tue, 29 Jul 2008) | 2 lines
Fix by Markus Gritsch to place correct links to headings.
........
r65269 | georg.brandl | 2008-07-29 10:21:59 +0200 (Tue, 29 Jul 2008) | 2 lines
Make the writer's settings public.
........
r65270 | georg.brandl | 2008-07-29 10:22:28 +0200 (Tue, 29 Jul 2008) | 2 lines
Export test_root.
........
r65271 | georg.brandl | 2008-07-29 10:22:47 +0200 (Tue, 29 Jul 2008) | 2 lines
Add a markup test.
........
r65272 | georg.brandl | 2008-07-29 10:27:19 +0200 (Tue, 29 Jul 2008) | 2 lines
Bump version number.
........
r65273 | georg.brandl | 2008-07-29 11:05:37 +0200 (Tue, 29 Jul 2008) | 2 lines
Correct rendering of ``samp``.
........
2008-07-29 04:07:37 -05:00
|
|
|
'test_root',
|
2008-06-05 03:58:43 -05:00
|
|
|
'raises', 'raises_msg',
|
|
|
|
'ErrorOutput', 'TestApp',
|
Merged revisions 64808,65013,65076,65100-65101,65119,65121-65123 via svnmerge from
svn+ssh://pythondev@svn.python.org/doctools/branches/0.4.x
........
r64808 | georg.brandl | 2008-07-08 21:39:33 +0200 (Tue, 08 Jul 2008) | 2 lines
Allow relocation of source and doctree dir.
........
r65013 | georg.brandl | 2008-07-16 15:25:30 +0200 (Wed, 16 Jul 2008) | 2 lines
Remove curious quote.
........
r65076 | georg.brandl | 2008-07-17 22:43:01 +0200 (Thu, 17 Jul 2008) | 2 lines
Add a test for sphinx.quickstart.
........
r65100 | georg.brandl | 2008-07-18 14:41:54 +0200 (Fri, 18 Jul 2008) | 2 lines
Fix phony targets.
........
r65101 | georg.brandl | 2008-07-18 14:55:03 +0200 (Fri, 18 Jul 2008) | 2 lines
Fix problems in "make check".
........
r65119 | georg.brandl | 2008-07-18 23:06:42 +0200 (Fri, 18 Jul 2008) | 2 lines
Emit a more precise error message in autodoc.
........
r65121 | georg.brandl | 2008-07-18 23:41:35 +0200 (Fri, 18 Jul 2008) | 2 lines
Warn if a toctree-included document doesn't contain a title.
........
r65122 | georg.brandl | 2008-07-18 23:51:28 +0200 (Fri, 18 Jul 2008) | 2 lines
Don't use \samp{} for code with whitespaces, only for :samp:`code`.
........
r65123 | georg.brandl | 2008-07-19 00:49:46 +0200 (Sat, 19 Jul 2008) | 2 lines
Put inheritance info always on its own line.
........
2008-07-18 17:55:36 -05:00
|
|
|
'path', 'with_tempdir', 'write_file',
|
2008-06-05 03:58:43 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
|
Merged revisions 65138,65145-65146,65268-65273 via svnmerge from
svn+ssh://pythondev@svn.python.org/doctools/branches/0.4.x
........
r65138 | georg.brandl | 2008-07-19 15:42:35 +0200 (Sat, 19 Jul 2008) | 2 lines
#3416: fix missing parameter.
........
r65145 | georg.brandl | 2008-07-19 20:01:25 +0200 (Sat, 19 Jul 2008) | 2 lines
Now that we don't ship Jinja anymore by default the comment can go.
........
r65146 | georg.brandl | 2008-07-19 20:01:51 +0200 (Sat, 19 Jul 2008) | 2 lines
Reread documents with globbed toctrees when files are removed/added.
........
r65268 | georg.brandl | 2008-07-29 10:21:33 +0200 (Tue, 29 Jul 2008) | 2 lines
Fix by Markus Gritsch to place correct links to headings.
........
r65269 | georg.brandl | 2008-07-29 10:21:59 +0200 (Tue, 29 Jul 2008) | 2 lines
Make the writer's settings public.
........
r65270 | georg.brandl | 2008-07-29 10:22:28 +0200 (Tue, 29 Jul 2008) | 2 lines
Export test_root.
........
r65271 | georg.brandl | 2008-07-29 10:22:47 +0200 (Tue, 29 Jul 2008) | 2 lines
Add a markup test.
........
r65272 | georg.brandl | 2008-07-29 10:27:19 +0200 (Tue, 29 Jul 2008) | 2 lines
Bump version number.
........
r65273 | georg.brandl | 2008-07-29 11:05:37 +0200 (Tue, 29 Jul 2008) | 2 lines
Correct rendering of ``samp``.
........
2008-07-29 04:07:37 -05:00
|
|
|
test_root = path(__file__).parent.joinpath('root').abspath()
|
|
|
|
|
|
|
|
|
2008-06-05 03:58:43 -05:00
|
|
|
def _excstr(exc):
|
|
|
|
if type(exc) is tuple:
|
|
|
|
return str(tuple(map(_excstr, exc)))
|
|
|
|
return exc.__name__
|
|
|
|
|
|
|
|
def raises(exc, func, *args, **kwds):
|
|
|
|
"""
|
|
|
|
Raise :exc:`AssertionError` if ``func(*args, **kwds)`` does not
|
|
|
|
raise *exc*.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
func(*args, **kwds)
|
|
|
|
except exc:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
raise AssertionError('%s did not raise %s' %
|
|
|
|
(func.__name__, _excstr(exc)))
|
|
|
|
|
|
|
|
def raises_msg(exc, msg, func, *args, **kwds):
|
|
|
|
"""
|
|
|
|
Raise :exc:`AssertionError` if ``func(*args, **kwds)`` does not
|
|
|
|
raise *exc*, and check if the message contains *msg*.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
func(*args, **kwds)
|
|
|
|
except exc, err:
|
|
|
|
assert msg in str(err)
|
|
|
|
else:
|
|
|
|
raise AssertionError('%s did not raise %s' %
|
|
|
|
(func.__name__, _excstr(exc)))
|
|
|
|
|
|
|
|
|
|
|
|
class ErrorOutput(object):
|
|
|
|
"""
|
|
|
|
File-like object that raises :exc:`AssertionError` on ``write()``.
|
|
|
|
"""
|
|
|
|
def __init__(self, name):
|
|
|
|
self.name = name
|
|
|
|
|
|
|
|
def write(self, text):
|
|
|
|
assert False, 'tried to write %r to %s' % (text, self.name)
|
|
|
|
|
|
|
|
|
|
|
|
class TestApp(application.Sphinx):
|
|
|
|
"""
|
|
|
|
A subclass of :class:`Sphinx` that runs on the test root, with some
|
|
|
|
better default values for the initialization parameters.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, srcdir=None, confdir=None, outdir=None, doctreedir=None,
|
|
|
|
buildername='html', confoverrides=None, status=None, warning=None,
|
|
|
|
freshenv=None, confname='conf.py'):
|
|
|
|
|
|
|
|
application.CONFIG_FILENAME = confname
|
|
|
|
|
|
|
|
if srcdir is None:
|
Merged revisions 65138,65145-65146,65268-65273 via svnmerge from
svn+ssh://pythondev@svn.python.org/doctools/branches/0.4.x
........
r65138 | georg.brandl | 2008-07-19 15:42:35 +0200 (Sat, 19 Jul 2008) | 2 lines
#3416: fix missing parameter.
........
r65145 | georg.brandl | 2008-07-19 20:01:25 +0200 (Sat, 19 Jul 2008) | 2 lines
Now that we don't ship Jinja anymore by default the comment can go.
........
r65146 | georg.brandl | 2008-07-19 20:01:51 +0200 (Sat, 19 Jul 2008) | 2 lines
Reread documents with globbed toctrees when files are removed/added.
........
r65268 | georg.brandl | 2008-07-29 10:21:33 +0200 (Tue, 29 Jul 2008) | 2 lines
Fix by Markus Gritsch to place correct links to headings.
........
r65269 | georg.brandl | 2008-07-29 10:21:59 +0200 (Tue, 29 Jul 2008) | 2 lines
Make the writer's settings public.
........
r65270 | georg.brandl | 2008-07-29 10:22:28 +0200 (Tue, 29 Jul 2008) | 2 lines
Export test_root.
........
r65271 | georg.brandl | 2008-07-29 10:22:47 +0200 (Tue, 29 Jul 2008) | 2 lines
Add a markup test.
........
r65272 | georg.brandl | 2008-07-29 10:27:19 +0200 (Tue, 29 Jul 2008) | 2 lines
Bump version number.
........
r65273 | georg.brandl | 2008-07-29 11:05:37 +0200 (Tue, 29 Jul 2008) | 2 lines
Correct rendering of ``samp``.
........
2008-07-29 04:07:37 -05:00
|
|
|
srcdir = test_root
|
2008-06-05 03:58:43 -05:00
|
|
|
else:
|
|
|
|
srcdir = path(srcdir)
|
|
|
|
if confdir is None:
|
|
|
|
confdir = srcdir
|
|
|
|
if outdir is None:
|
|
|
|
outdir = srcdir.joinpath('_build', buildername)
|
|
|
|
if doctreedir is None:
|
|
|
|
doctreedir = srcdir.joinpath(srcdir, '_build', 'doctrees')
|
|
|
|
if confoverrides is None:
|
|
|
|
confoverrides = {}
|
|
|
|
if status is None:
|
|
|
|
status = StringIO.StringIO()
|
|
|
|
if warning is None:
|
|
|
|
warning = ErrorOutput('stderr')
|
|
|
|
if freshenv is None:
|
|
|
|
freshenv = True
|
|
|
|
|
|
|
|
application.Sphinx.__init__(self, srcdir, confdir, outdir, doctreedir,
|
|
|
|
buildername, confoverrides, status, warning,
|
|
|
|
freshenv)
|
|
|
|
|
|
|
|
|
|
|
|
def with_tempdir(func):
|
|
|
|
def new_func():
|
|
|
|
tempdir = path(tempfile.mkdtemp())
|
|
|
|
func(tempdir)
|
|
|
|
tempdir.rmtree()
|
|
|
|
new_func.__name__ = func.__name__
|
|
|
|
return new_func
|
|
|
|
|
|
|
|
|
|
|
|
def write_file(name, contents):
|
|
|
|
f = open(str(name), 'wb')
|
|
|
|
f.write(contents)
|
|
|
|
f.close()
|