Commits

Georg Brandl committed d93ed8f

Skip pygments-related tests if it is not installed.

  • Participants
  • Parent commits 1fdca56

Comments (0)

Files changed (3)

File sphinx/environment.py

 
     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,

File tests/test_build.py

 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
         ".//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']": '',
     },
 }
 
+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."""
 

File tests/test_highlighting.py

 
 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
         ],
     }
 
-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())