summaryrefslogtreecommitdiff
path: root/tests/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/util.py')
-rw-r--r--tests/util.py42
1 files changed, 31 insertions, 11 deletions
diff --git a/tests/util.py b/tests/util.py
index f7d8411c7..246b3728e 100644
--- a/tests/util.py
+++ b/tests/util.py
@@ -17,6 +17,9 @@ from six import StringIO
from nose import tools, SkipTest
+from docutils import nodes
+from docutils.parsers.rst import directives, roles
+
from sphinx import application
from sphinx.builders.latex import LaTeXBuilder
from sphinx.theming import Theme
@@ -91,14 +94,15 @@ def assert_startswith(thing, prefix):
assert False, '%r does not start with %r' % (thing, prefix)
-def assert_in(x, thing):
- if x not in thing:
- assert False, '%r is not in %r' % (x, thing)
-
-
-def assert_not_in(x, thing):
- if x in thing:
- assert False, '%r is in %r' % (x, thing)
+try:
+ from nose.tools import assert_in, assert_not_in
+except ImportError:
+ def assert_in(x, thing, msg=''):
+ if x not in thing:
+ assert False, msg or '%r is not in %r%r' % (x, thing)
+ def assert_not_in(x, thing, msg=''):
+ if x in thing:
+ assert False, msg or '%r is in %r%r' % (x, thing)
def skip_if(condition, msg=None):
@@ -195,10 +199,19 @@ class TestApp(application.Sphinx):
warningiserror = False
self._saved_path = sys.path[:]
+ self._saved_directives = directives._directives.copy()
+ self._saved_roles = roles._roles.copy()
+
+ self._saved_nodeclasses = set(v for v in dir(nodes.GenericNodeVisitor)
+ if v.startswith('visit_'))
- application.Sphinx.__init__(self, srcdir, confdir, outdir, doctreedir,
- buildername, confoverrides, status, warning,
- freshenv, warningiserror, tags)
+ try:
+ application.Sphinx.__init__(self, srcdir, confdir, outdir, doctreedir,
+ buildername, confoverrides, status, warning,
+ freshenv, warningiserror, tags)
+ except:
+ self.cleanup()
+ raise
def cleanup(self, doctrees=False):
Theme.themes.clear()
@@ -207,6 +220,13 @@ class TestApp(application.Sphinx):
LaTeXBuilder.usepackages = []
sys.path[:] = self._saved_path
sys.modules.pop('autodoc_fodder', None)
+ directives._directives = self._saved_directives
+ roles._roles = self._saved_roles
+ for method in dir(nodes.GenericNodeVisitor):
+ if method.startswith('visit_') and \
+ method not in self._saved_nodeclasses:
+ delattr(nodes.GenericNodeVisitor, 'visit_' + method[6:])
+ delattr(nodes.GenericNodeVisitor, 'depart_' + method[6:])
def __repr__(self):
return '<%s buildername=%r>' % (self.__class__.__name__, self.builder.name)