sphinx/tests/test_build.py
Georg Brandl b4f71aa642 Merged revisions 65283,65303,65316-65317,65372-65375,65377,65380,65483-65485,65494 via svnmerge from
svn+ssh://pythondev@svn.python.org/doctools/branches/0.4.x

........
  r65283 | georg.brandl | 2008-07-29 10:07:26 +0000 (Tue, 29 Jul 2008) | 2 lines

  Update ez_setup.py.
........
  r65303 | benjamin.peterson | 2008-07-30 12:35:34 +0000 (Wed, 30 Jul 2008) | 1 line

  add a with_testapp decorator for test functions that passes the TestApp instance in a cleans up after it
........
  r65316 | benjamin.peterson | 2008-07-30 23:12:07 +0000 (Wed, 30 Jul 2008) | 1 line

  make the app for test_markup global to the module
........
  r65317 | benjamin.peterson | 2008-07-30 23:31:29 +0000 (Wed, 30 Jul 2008) | 1 line

  make TestApp.cleanup more aggressive
........
  r65372 | georg.brandl | 2008-08-01 19:11:22 +0000 (Fri, 01 Aug 2008) | 2 lines

  Add more tests, fix a few bugs in image handling.
........
  r65373 | georg.brandl | 2008-08-01 19:28:33 +0000 (Fri, 01 Aug 2008) | 2 lines

  Fix oversight.
........
  r65374 | benjamin.peterson | 2008-08-01 19:36:32 +0000 (Fri, 01 Aug 2008) | 1 line

  fix one broken test
........
  r65375 | georg.brandl | 2008-08-01 19:41:11 +0000 (Fri, 01 Aug 2008) | 2 lines

  Fix the handling of non-ASCII input in quickstart.
........
  r65377 | georg.brandl | 2008-08-01 19:48:24 +0000 (Fri, 01 Aug 2008) | 2 lines

  Allow REs in markup checks.
........
  r65380 | georg.brandl | 2008-08-01 20:31:18 +0000 (Fri, 01 Aug 2008) | 2 lines

  Don't rely on mtimes being different for changed files.
........
  r65483 | georg.brandl | 2008-08-04 09:01:40 +0000 (Mon, 04 Aug 2008) | 4 lines

  Add an "encoding" option to literalinclude.

  Add tests for include directives.
........
  r65484 | georg.brandl | 2008-08-04 09:11:17 +0000 (Mon, 04 Aug 2008) | 2 lines

  Add changelog entry.
........
  r65485 | georg.brandl | 2008-08-04 09:21:58 +0000 (Mon, 04 Aug 2008) | 2 lines

  Fix markup.
........
  r65494 | georg.brandl | 2008-08-04 16:34:59 +0000 (Mon, 04 Aug 2008) | 2 lines

  Correctly use HTML file suffix in templates.
........
2008-08-04 17:01:15 +00:00

96 lines
2.7 KiB
Python

# -*- coding: utf-8 -*-
"""
test_build
~~~~~~~~~~
Test the entire build process with the test root.
:copyright: 2008 by Georg Brandl.
:license: BSD.
"""
import os
import htmlentitydefs
from StringIO import StringIO
from etree13 import ElementTree as ET
from util import *
from sphinx.builder import StandaloneHTMLBuilder, LaTeXBuilder
html_warnfile = StringIO()
latex_warnfile = StringIO()
ENV_WARNINGS = """\
WARNING: %(root)s/images.txt:9: Image file not readable: foo.png
WARNING: %(root)s/images.txt:20: Nonlocal image URI found: http://www.python.org/logo.png
WARNING: %(root)s/includes.txt:: (WARNING/2) Encoding 'utf-8' used for reading included file u'wrongenc.inc' seems to be wrong, try giving an :encoding: option
"""
HTML_WARNINGS = ENV_WARNINGS + """\
WARNING: %(root)s/images.txt:: no matching candidate for image URI u'foo.*'
"""
LATEX_WARNINGS = ENV_WARNINGS + """\
WARNING: None:: no matching candidate for image URI u'foo.*'
"""
HTML_XPATH = {
'images.html': {
".//img[@src='_images/img.png']": '',
".//img[@src='_images/img1.png']": '',
},
'includes.html': {
".//pre/span[@class='s']": u'üöä',
".//pre": u'Max Strauß',
},
}
class NslessParser(ET.XMLParser):
"""XMLParser that throws away namespaces in tag names."""
def _fixname(self, key):
try:
return self._names[key]
except KeyError:
name = key
br = name.find('}')
if br > 0:
name = name[br+1:]
self._names[key] = name = self._fixtext(name)
return name
@with_testapp(buildername='html', warning=html_warnfile)
def test_html(app):
app.builder.build_all()
html_warnings = html_warnfile.getvalue().replace(os.sep, '/')
assert html_warnings == HTML_WARNINGS % {'root': app.srcdir}
if not ET:
return
for fname, paths in HTML_XPATH.iteritems():
parser = NslessParser()
parser.entity.update(htmlentitydefs.entitydefs)
etree = ET.parse(app.outdir / fname, parser)
for path, text in paths.iteritems():
nodes = list(etree.findall(path))
assert nodes != []
if not text:
# only check for node presence
continue
for node in nodes:
if node.text and text in node.text:
break
else:
assert False, ('%r not found in any node matching '
'path %s in %s' % (text, path, fname))
@with_testapp(buildername='latex', warning=latex_warnfile)
def test_latex(app):
app.builder.build_all()
latex_warnings = latex_warnfile.getvalue().replace(os.sep, '/')
assert latex_warnings == LATEX_WARNINGS % {'root': app.srcdir}