Skip pygments-related tests if it is not installed.

This commit is contained in:
Georg Brandl 2009-02-06 22:18:16 +01:00
parent e15b26866e
commit 1e347aba51
3 changed files with 29 additions and 15 deletions

View File

@ -832,8 +832,6 @@ class BuildEnvironment:
def get_toctree_for(self, docname, builder): def get_toctree_for(self, docname, builder):
"""Return the global TOC nodetree.""" """Return the global TOC nodetree."""
# XXX why master_doc?
doctree = self.get_doctree(self.config.master_doc) doctree = self.get_doctree(self.config.master_doc)
for toctreenode in doctree.traverse(addnodes.toctree): for toctreenode in doctree.traverse(addnodes.toctree):
result = self.resolve_toctree(docname, builder, toctreenode, result = self.resolve_toctree(docname, builder, toctreenode,

View File

@ -20,6 +20,11 @@ from subprocess import Popen, PIPE
from util import * from util import *
from etree13 import ElementTree as ET from etree13 import ElementTree as ET
try:
import pygments
except ImportError:
pygments = None
from sphinx.builders.html import StandaloneHTMLBuilder from sphinx.builders.html import StandaloneHTMLBuilder
from sphinx.builders.latex import LaTeXBuilder from sphinx.builders.latex import LaTeXBuilder
from sphinx.writers.latex import LaTeXTranslator from sphinx.writers.latex import LaTeXTranslator
@ -58,18 +63,9 @@ HTML_XPATH = {
".//img[@src='../_images/img1.png']": '', ".//img[@src='../_images/img1.png']": '',
}, },
'includes.html': { 'includes.html': {
".//pre/span[@class='s']": u'üöä',
".//pre": u'Max Strauß', ".//pre": u'Max Strauß',
".//a[@href='_downloads/img.png']": '', ".//a[@href='_downloads/img.png']": '',
".//a[@href='_downloads/img1.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': { 'autodoc.html': {
".//dt[@id='test_autodoc.Class']": '', ".//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): class NslessParser(ET.XMLParser):
"""XMLParser that throws away namespaces in tag names.""" """XMLParser that throws away namespaces in tag names."""

View File

@ -11,6 +11,12 @@
from util import * 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.lexer import RegexLexer
from pygments.token import Text, Name from pygments.token import Text, Name
from pygments.formatters.html import HtmlFormatter 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): class MyFormatter(HtmlFormatter):
def format(self, tokensource, outfile): def format(self, tokensource, outfile):
outfile.write('test') outfile.write('test')
class ComplainOnUnhighlighted(PygmentsBridge):
def unhighlighted(self, source):
raise AssertionError("should highlight %r" % source)
@with_app() @with_app()
def test_add_lexer(app): def test_add_lexer(app):
app.add_lexer('test', MyLexer()) app.add_lexer('test', MyLexer())