mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
#130: Fix obscure IndexError in doctest extension.
This commit is contained in:
parent
5e927d724d
commit
06ef375ccb
2
CHANGES
2
CHANGES
@ -1,6 +1,8 @@
|
|||||||
Release 0.6.2 (in development)
|
Release 0.6.2 (in development)
|
||||||
==============================
|
==============================
|
||||||
|
|
||||||
|
* #130: Fix obscure IndexError in doctest extension.
|
||||||
|
|
||||||
* #167: Make glossary sorting case-independent.
|
* #167: Make glossary sorting case-independent.
|
||||||
|
|
||||||
* #196: Add a warning if an extension module doesn't have a
|
* #196: Add a warning if an extension module doesn't have a
|
||||||
|
@ -159,6 +159,23 @@ class SphinxDocTestRunner(doctest.DocTestRunner):
|
|||||||
out(io.getvalue())
|
out(io.getvalue())
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def _DocTestRunner__patched_linecache_getlines(self, filename,
|
||||||
|
module_globals=None):
|
||||||
|
# this is overridden from DocTestRunner adding the try-except below
|
||||||
|
m = self._DocTestRunner__LINECACHE_FILENAME_RE.match(filename)
|
||||||
|
if m and m.group('name') == self.test.name:
|
||||||
|
try:
|
||||||
|
example = self.test.examples[int(m.group('examplenum'))]
|
||||||
|
# because we compile multiple doctest blocks with the same name
|
||||||
|
# (viz. the group name) this might, for outer stack frames in a
|
||||||
|
# traceback, get the wrong test which might not have enough examples
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
return example.source.splitlines(True)
|
||||||
|
return self.save_linecache_getlines(filename, module_globals)
|
||||||
|
|
||||||
|
|
||||||
# the new builder -- use sphinx-build.py -b doctest to run
|
# the new builder -- use sphinx-build.py -b doctest to run
|
||||||
|
|
||||||
class DocTestBuilder(Builder):
|
class DocTestBuilder(Builder):
|
||||||
@ -302,13 +319,13 @@ Doctest summary
|
|||||||
|
|
||||||
def test_group(self, group, filename):
|
def test_group(self, group, filename):
|
||||||
ns = {}
|
ns = {}
|
||||||
examples = []
|
setup_examples = []
|
||||||
for setup in group.setup:
|
for setup in group.setup:
|
||||||
examples.append(doctest.Example(setup.code, '',
|
setup_examples.append(doctest.Example(setup.code, '',
|
||||||
lineno=setup.lineno))
|
lineno=setup.lineno))
|
||||||
if examples:
|
if setup_examples:
|
||||||
# simulate a doctest with the setup code
|
# simulate a doctest with the setup code
|
||||||
setup_doctest = doctest.DocTest(examples, {},
|
setup_doctest = doctest.DocTest(setup_examples, {},
|
||||||
'%s (setup code)' % group.name,
|
'%s (setup code)' % group.name,
|
||||||
filename, 0, None)
|
filename, 0, None)
|
||||||
setup_doctest.globs = ns
|
setup_doctest.globs = ns
|
||||||
@ -321,8 +338,9 @@ Doctest summary
|
|||||||
return
|
return
|
||||||
for code in group.tests:
|
for code in group.tests:
|
||||||
if len(code) == 1:
|
if len(code) == 1:
|
||||||
test = parser.get_doctest(code[0].code, {},
|
# ordinary doctests (code/output interleaved)
|
||||||
group.name, filename, code[0].lineno)
|
test = parser.get_doctest(code[0].code, {}, group.name,
|
||||||
|
filename, code[0].lineno)
|
||||||
if not test.examples:
|
if not test.examples:
|
||||||
continue
|
continue
|
||||||
for example in test.examples:
|
for example in test.examples:
|
||||||
@ -330,8 +348,9 @@ Doctest summary
|
|||||||
new_opt = code[0].options.copy()
|
new_opt = code[0].options.copy()
|
||||||
new_opt.update(example.options)
|
new_opt.update(example.options)
|
||||||
example.options = new_opt
|
example.options = new_opt
|
||||||
self.type = 'single' # ordinary doctests
|
self.type = 'single' # as for ordinary doctests
|
||||||
else:
|
else:
|
||||||
|
# testcode and output separate
|
||||||
output = code[1] and code[1].code or ''
|
output = code[1] and code[1].code or ''
|
||||||
options = code[1] and code[1].options or {}
|
options = code[1] and code[1].options or {}
|
||||||
# disable <BLANKLINE> processing as it is not needed
|
# disable <BLANKLINE> processing as it is not needed
|
||||||
|
Loading…
Reference in New Issue
Block a user