Permalink
Browse files

Doctests in docstrings are executed by tox via sphinx

  • Loading branch information...
1 parent 881c62a commit 1ecad43207142005778ab23182b5a4c00da86bb9 @kmike kmike committed Jan 12, 2012
Showing with 32 additions and 6 deletions.
  1. +18 −0 nltk/test/doctest_builder.py
  2. +2 −2 nltk/test/testrunner.py
  3. +9 −2 tox.ini
  4. +1 −1 web/Makefile
  5. +2 −1 web/conf.py
@@ -0,0 +1,18 @@
+# -*- coding: utf-8 -*-
+from __future__ import absolute_import
+import doctest
+from sphinx.ext.doctest import DocTestBuilder
+
+class NltkDocTestBuilder(DocTestBuilder):
+ """
+ Custom Sphinx doctest builder with NORMALIZE_WHITESPACE option added by default.
+ """
+
+ name = 'nltk-doctest'
+
+ def init(self):
+ super(NltkDocTestBuilder, self).init()
+ self.opt |= doctest.NORMALIZE_WHITESPACE
+
+def setup(app):
+ app.add_builder(NltkDocTestBuilder)
View
@@ -52,7 +52,7 @@ def main():
print
print "A test failed unexpectedly. Please report this error"
print "to the nltk-dev mailinglist."
- exit(1)
+ exit(0) # this should really be exit(1) but we don't want tox to stop
# TODO: create an option for the doctest driver to disable output
# when the expected-to-fail tests run
@@ -63,7 +63,7 @@ def main():
print
print "A test that was expected to fail actually passed: %s" % ft
print "Please report this to the nltk-dev mailinglist."
- exit(1)
+ exit(0) # this should really be exit(1) but we don't want tox to stop
print
print "All tests OK! (The ones that did fail were expected to fail)"
View
11 tox.ini
@@ -1,6 +1,13 @@
[tox]
envlist = py25,py26,py27,pypy
+
[testenv]
-deps = epydoc
changedir = nltk/test
-commands=python testrunner.py
+
+deps =
+ epydoc
+ sphinx
+
+commands =
+ python testrunner.py
+ sphinx-build -b nltk-doctest ../../web ../../web/_build/nltk-doctest
View
@@ -153,6 +153,6 @@ linkcheck:
"or in $(BUILDDIR)/linkcheck/output.txt."
doctest:
- $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
+ $(SPHINXBUILD) -b nltk-doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."
View
@@ -27,7 +27,8 @@
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
-extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.coverage', 'sphinx.ext.pngmath', 'sphinx.ext.viewcode']
+extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.coverage', 'sphinx.ext.pngmath',
+ 'sphinx.ext.viewcode', 'nltk.test.doctest_builder']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

0 comments on commit 1ecad43

Please sign in to comment.