diff --git a/sphinx/environment.py b/sphinx/environment.py index 991fab72d..4aa32ed08 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -832,8 +832,6 @@ class BuildEnvironment: def get_toctree_for(self, docname, builder): """Return the global TOC nodetree.""" - - # XXX why master_doc? doctree = self.get_doctree(self.config.master_doc) for toctreenode in doctree.traverse(addnodes.toctree): result = self.resolve_toctree(docname, builder, toctreenode, diff --git a/tests/test_build.py b/tests/test_build.py index ed2d9982d..21d829cb8 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -20,6 +20,11 @@ from subprocess import Popen, PIPE from util import * from etree13 import ElementTree as ET +try: + import pygments +except ImportError: + pygments = None + from sphinx.builders.html import StandaloneHTMLBuilder from sphinx.builders.latex import LaTeXBuilder from sphinx.writers.latex import LaTeXTranslator @@ -58,18 +63,9 @@ HTML_XPATH = { ".//img[@src='../_images/img1.png']": '', }, 'includes.html': { - ".//pre/span[@class='s']": u'üöä', ".//pre": u'Max Strauß', ".//a[@href='_downloads/img.png']": '', ".//a[@href='_downloads/img1.png']": '', - ".//div[@class='inc-pyobj1 highlight-text']/div/pre": - r'^class Foo:\n pass\n\s*$', - ".//div[@class='inc-pyobj2 highlight-text']/div/pre": - r'^ def baz\(\):\n pass\n\s*$', - ".//div[@class='inc-lines highlight-text']/div/pre": - r'^class Foo:\n pass\nclass Bar:\n$', - ".//div[@class='inc-startend highlight-text']/div/pre": - ur'^foo = u"Including Unicode characters: üöä"\n$', }, 'autodoc.html': { ".//dt[@id='test_autodoc.Class']": '', @@ -99,6 +95,19 @@ HTML_XPATH = { }, } +if pygments: + HTML_XPATH['includes.html'].update({ + ".//pre/span[@class='s']": u'üöä', + ".//div[@class='inc-pyobj1 highlight-text']/div/pre": + r'^class Foo:\n pass\n\s*$', + ".//div[@class='inc-pyobj2 highlight-text']/div/pre": + r'^ def baz\(\):\n pass\n\s*$', + ".//div[@class='inc-lines highlight-text']/div/pre": + r'^class Foo:\n pass\nclass Bar:\n$', + ".//div[@class='inc-startend highlight-text']/div/pre": + ur'^foo = u"Including Unicode characters: üöä"\n$', + }) + class NslessParser(ET.XMLParser): """XMLParser that throws away namespaces in tag names.""" diff --git a/tests/test_highlighting.py b/tests/test_highlighting.py index 198f7a0a0..ea1f25f14 100644 --- a/tests/test_highlighting.py +++ b/tests/test_highlighting.py @@ -11,6 +11,12 @@ from util import * +try: + import pygments +except ImportError: + from nose.plugins.skip import SkipTest + raise SkipTest('pygments not available') + from pygments.lexer import RegexLexer from pygments.token import Text, Name from pygments.formatters.html import HtmlFormatter @@ -28,16 +34,17 @@ class MyLexer(RegexLexer): ], } -class ComplainOnUnhighlighted(PygmentsBridge): - - def unhighlighted(self, source): - raise AssertionError("should highlight %r" % source) class MyFormatter(HtmlFormatter): def format(self, tokensource, outfile): outfile.write('test') +class ComplainOnUnhighlighted(PygmentsBridge): + def unhighlighted(self, source): + raise AssertionError("should highlight %r" % source) + + @with_app() def test_add_lexer(app): app.add_lexer('test', MyLexer())