mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge remote-tracking branch 'upstream/master'
Conflicts: tests/test_build_html.py
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
Test the HTML builder and check output against XPath.
|
||||
|
||||
:copyright: Copyright 2007-2015 by the Sphinx team, see AUTHORS.
|
||||
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
@@ -16,7 +16,7 @@ from six import PY3, iteritems
|
||||
from six.moves import html_entities
|
||||
|
||||
from sphinx import __display_version__
|
||||
from util import remove_unicode_literals, gen_with_app
|
||||
from util import remove_unicode_literals, gen_with_app, with_app
|
||||
from etree13 import ElementTree as ET
|
||||
|
||||
|
||||
@@ -31,18 +31,16 @@ http://www.python.org/logo.png
|
||||
reading included file u'.*?wrongenc.inc' seems to be wrong, try giving an \
|
||||
:encoding: option\\n?
|
||||
%(root)s/includes.txt:4: WARNING: download file not readable: .*?nonexisting.png
|
||||
(%(root)s/markup.txt:\\d+: WARNING: Malformed :option: u'&option', does \
|
||||
not contain option marker - or -- or / or \\+
|
||||
%(root)s/undecodable.txt:3: WARNING: undecodable source characters, replacing \
|
||||
(%(root)s/markup.txt:357: WARNING: invalid single index entry u'')?
|
||||
(%(root)s/undecodable.txt:3: WARNING: undecodable source characters, replacing \
|
||||
with "\\?": b?'here: >>>(\\\\|/)xbb<<<'
|
||||
)?"""
|
||||
|
||||
HTML_WARNINGS = ENV_WARNINGS + """\
|
||||
%(root)s/images.txt:20: WARNING: no matching candidate for image URI u'foo.\\*'
|
||||
None:\\d+: WARNING: citation not found: missing
|
||||
%(root)s/markup.txt:: WARNING: invalid single index entry u''
|
||||
%(root)s/markup.txt:: WARNING: invalid pair index entry u''
|
||||
%(root)s/markup.txt:: WARNING: invalid pair index entry u'keyword; '
|
||||
%(root)s/markup.txt:269: WARNING: Could not parse literal_block as "c". highlighting skipped.
|
||||
%(root)s/footnote.txt:60: WARNING: citation not found: missing
|
||||
%(root)s/markup.txt:158: WARNING: unknown option: &option
|
||||
"""
|
||||
|
||||
if PY3:
|
||||
@@ -85,7 +83,7 @@ HTML_XPATH = {
|
||||
(".//a[@href='_downloads/img1.png']", ''),
|
||||
(".//pre", u'"quotes"'),
|
||||
(".//pre", u"'included'"),
|
||||
(".//pre/span[@class='s']", u'üöä'),
|
||||
(".//pre/span[@class='s2']", u'üöä'),
|
||||
(".//div[@class='inc-pyobj1 highlight-text']//pre",
|
||||
r'^class Foo:\n pass\n\s*$'),
|
||||
(".//div[@class='inc-pyobj2 highlight-text']//pre",
|
||||
@@ -234,6 +232,23 @@ HTML_XPATH = {
|
||||
(".//td[@class='field-body']/ul/li/strong", '^hour$'),
|
||||
(".//td[@class='field-body']/ul/li/em", '^DuplicateType$'),
|
||||
(".//td[@class='field-body']/ul/li/em", tail_check(r'.* Some parameter')),
|
||||
# others
|
||||
(".//a[@class='reference internal'][@href='#cmdoption-perl-arg-+p']/code/span",
|
||||
'perl'),
|
||||
(".//a[@class='reference internal'][@href='#cmdoption-perl-arg-+p']/code/span",
|
||||
'\+p'),
|
||||
(".//a[@class='reference internal'][@href='#cmdoption-perl-arg-arg']/code/span",
|
||||
'arg'),
|
||||
(".//a[@class='reference internal'][@href='#cmdoption-hg-arg-commit']/code/span",
|
||||
'hg'),
|
||||
(".//a[@class='reference internal'][@href='#cmdoption-hg-arg-commit']/code/span",
|
||||
'commit'),
|
||||
(".//a[@class='reference internal'][@href='#cmdoption-git-commit-p']/code/span",
|
||||
'git'),
|
||||
(".//a[@class='reference internal'][@href='#cmdoption-git-commit-p']/code/span",
|
||||
'commit'),
|
||||
(".//a[@class='reference internal'][@href='#cmdoption-git-commit-p']/code/span",
|
||||
'-p'),
|
||||
],
|
||||
'contents.html': [
|
||||
(".//meta[@name='hc'][@content='hcval']", ''),
|
||||
@@ -360,7 +375,7 @@ def check_extra_entries(outdir):
|
||||
assert (outdir / 'robots.txt').isfile()
|
||||
|
||||
|
||||
@gen_with_app(buildername='html',
|
||||
@gen_with_app(buildername='html', freshenv=True, # use freshenv to check warnings
|
||||
confoverrides={'html_context.hckey_co': 'hcval_co'},
|
||||
tags=['testtag'])
|
||||
def test_html_output(app, status, warning):
|
||||
@@ -376,11 +391,8 @@ def test_html_output(app, status, warning):
|
||||
for fname, paths in iteritems(HTML_XPATH):
|
||||
parser = NslessParser()
|
||||
parser.entity.update(html_entities.entitydefs)
|
||||
fp = open(os.path.join(app.outdir, fname), 'rb')
|
||||
try:
|
||||
with (app.outdir / fname).open('rb') as fp:
|
||||
etree = ET.parse(fp, parser)
|
||||
finally:
|
||||
fp.close()
|
||||
for path, check in paths:
|
||||
yield check_xpath, etree, fname, path, check
|
||||
|
||||
@@ -429,11 +441,8 @@ def test_tocdepth(app, status, warning):
|
||||
for fname, paths in iteritems(expects):
|
||||
parser = NslessParser()
|
||||
parser.entity.update(html_entities.entitydefs)
|
||||
fp = open(os.path.join(app.outdir, fname), 'rb')
|
||||
try:
|
||||
with (app.outdir / fname).open('rb') as fp:
|
||||
etree = ET.parse(fp, parser)
|
||||
finally:
|
||||
fp.close()
|
||||
|
||||
for xpath, check, be_found in paths:
|
||||
yield check_xpath, etree, fname, xpath, check, be_found
|
||||
@@ -474,11 +483,8 @@ def test_tocdepth_singlehtml(app, status, warning):
|
||||
for fname, paths in iteritems(expects):
|
||||
parser = NslessParser()
|
||||
parser.entity.update(html_entities.entitydefs)
|
||||
fp = open(os.path.join(app.outdir, fname), 'rb')
|
||||
try:
|
||||
with (app.outdir / fname).open('rb') as fp:
|
||||
etree = ET.parse(fp, parser)
|
||||
finally:
|
||||
fp.close()
|
||||
|
||||
for xpath, check, be_found in paths:
|
||||
yield check_xpath, etree, fname, xpath, check, be_found
|
||||
@@ -488,8 +494,10 @@ def test_tocdepth_singlehtml(app, status, warning):
|
||||
def test_numfig_disabled(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
assert 'WARNING: invalid numfig_format: invalid' not in warning.getvalue()
|
||||
assert 'WARNING: invalid numfig_format: Fig %s %s' not in warning.getvalue()
|
||||
assert ('index.rst:45: WARNING: numfig is disabled. :numref: is ignored.'
|
||||
in warning.getvalue())
|
||||
assert 'index.rst:51: WARNING: invalid numfig_format: invalid' not in warning.getvalue()
|
||||
assert 'index.rst:52: WARNING: invalid numfig_format: Fig %s %s' not in warning.getvalue()
|
||||
|
||||
expects = {
|
||||
'index.html': [
|
||||
@@ -531,11 +539,8 @@ def test_numfig_disabled(app, status, warning):
|
||||
for fname, paths in iteritems(expects):
|
||||
parser = NslessParser()
|
||||
parser.entity.update(html_entities.entitydefs)
|
||||
fp = open(os.path.join(app.outdir, fname), 'rb')
|
||||
try:
|
||||
with (app.outdir / fname).open('rb') as fp:
|
||||
etree = ET.parse(fp, parser)
|
||||
finally:
|
||||
fp.close()
|
||||
|
||||
for xpath, check, be_found in paths:
|
||||
yield check_xpath, etree, fname, xpath, check, be_found
|
||||
@@ -550,8 +555,10 @@ def test_numfig_without_numbered_toctree(app, status, warning):
|
||||
(app.srcdir / 'index.rst').write_text(index, encoding='utf-8')
|
||||
app.builder.build_all()
|
||||
|
||||
assert 'WARNING: invalid numfig_format: invalid' in warning.getvalue()
|
||||
assert 'WARNING: invalid numfig_format: Fig %s %s' in warning.getvalue()
|
||||
assert ('index.rst:45: WARNING: numfig is disabled. :numref: is ignored.'
|
||||
not in warning.getvalue())
|
||||
assert 'index.rst:51: WARNING: invalid numfig_format: invalid' in warning.getvalue()
|
||||
assert 'index.rst:52: WARNING: invalid numfig_format: Fig %s %s' in warning.getvalue()
|
||||
|
||||
expects = {
|
||||
'index.html': [
|
||||
@@ -633,11 +640,8 @@ def test_numfig_without_numbered_toctree(app, status, warning):
|
||||
for fname, paths in iteritems(expects):
|
||||
parser = NslessParser()
|
||||
parser.entity.update(html_entities.entitydefs)
|
||||
fp = open(os.path.join(app.outdir, fname), 'rb')
|
||||
try:
|
||||
with (app.outdir / fname).open('rb') as fp:
|
||||
etree = ET.parse(fp, parser)
|
||||
finally:
|
||||
fp.close()
|
||||
|
||||
for xpath, check, be_found in paths:
|
||||
yield check_xpath, etree, fname, xpath, check, be_found
|
||||
@@ -648,8 +652,10 @@ def test_numfig_without_numbered_toctree(app, status, warning):
|
||||
def test_numfig_with_numbered_toctree(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
assert 'WARNING: invalid numfig_format: invalid' in warning.getvalue()
|
||||
assert 'WARNING: invalid numfig_format: Fig %s %s' in warning.getvalue()
|
||||
assert ('index.rst:45: WARNING: numfig is disabled. :numref: is ignored.'
|
||||
not in warning.getvalue())
|
||||
assert 'index.rst:51: WARNING: invalid numfig_format: invalid' in warning.getvalue()
|
||||
assert 'index.rst:52: WARNING: invalid numfig_format: Fig %s %s' in warning.getvalue()
|
||||
|
||||
expects = {
|
||||
'index.html': [
|
||||
@@ -731,11 +737,8 @@ def test_numfig_with_numbered_toctree(app, status, warning):
|
||||
for fname, paths in iteritems(expects):
|
||||
parser = NslessParser()
|
||||
parser.entity.update(html_entities.entitydefs)
|
||||
fp = open(os.path.join(app.outdir, fname), 'rb')
|
||||
try:
|
||||
with (app.outdir / fname).open('rb') as fp:
|
||||
etree = ET.parse(fp, parser)
|
||||
finally:
|
||||
fp.close()
|
||||
|
||||
for xpath, check, be_found in paths:
|
||||
yield check_xpath, etree, fname, xpath, check, be_found
|
||||
@@ -749,8 +752,10 @@ def test_numfig_with_numbered_toctree(app, status, warning):
|
||||
def test_numfig_with_prefix(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
assert 'WARNING: invalid numfig_format: invalid' in warning.getvalue()
|
||||
assert 'WARNING: invalid numfig_format: Fig %s %s' in warning.getvalue()
|
||||
assert ('index.rst:45: WARNING: numfig is disabled. :numref: is ignored.'
|
||||
not in warning.getvalue())
|
||||
assert 'index.rst:51: WARNING: invalid numfig_format: invalid' in warning.getvalue()
|
||||
assert 'index.rst:52: WARNING: invalid numfig_format: Fig %s %s' in warning.getvalue()
|
||||
|
||||
expects = {
|
||||
'index.html': [
|
||||
@@ -832,11 +837,8 @@ def test_numfig_with_prefix(app, status, warning):
|
||||
for fname, paths in iteritems(expects):
|
||||
parser = NslessParser()
|
||||
parser.entity.update(html_entities.entitydefs)
|
||||
fp = open(os.path.join(app.outdir, fname), 'rb')
|
||||
try:
|
||||
with (app.outdir / fname).open('rb') as fp:
|
||||
etree = ET.parse(fp, parser)
|
||||
finally:
|
||||
fp.close()
|
||||
|
||||
for xpath, check, be_found in paths:
|
||||
yield check_xpath, etree, fname, xpath, check, be_found
|
||||
@@ -847,8 +849,10 @@ def test_numfig_with_prefix(app, status, warning):
|
||||
def test_numfig_with_secnum_depth(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
assert 'WARNING: invalid numfig_format: invalid' in warning.getvalue()
|
||||
assert 'WARNING: invalid numfig_format: Fig %s %s' in warning.getvalue()
|
||||
assert ('index.rst:45: WARNING: numfig is disabled. :numref: is ignored.'
|
||||
not in warning.getvalue())
|
||||
assert 'index.rst:51: WARNING: invalid numfig_format: invalid' in warning.getvalue()
|
||||
assert 'index.rst:52: WARNING: invalid numfig_format: Fig %s %s' in warning.getvalue()
|
||||
|
||||
expects = {
|
||||
'index.html': [
|
||||
@@ -930,15 +934,40 @@ def test_numfig_with_secnum_depth(app, status, warning):
|
||||
for fname, paths in iteritems(expects):
|
||||
parser = NslessParser()
|
||||
parser.entity.update(html_entities.entitydefs)
|
||||
fp = open(os.path.join(app.outdir, fname), 'rb')
|
||||
try:
|
||||
with (app.outdir / fname).open('rb') as fp:
|
||||
etree = ET.parse(fp, parser)
|
||||
finally:
|
||||
fp.close()
|
||||
|
||||
for xpath, check, be_found in paths:
|
||||
yield check_xpath, etree, fname, xpath, check, be_found
|
||||
|
||||
|
||||
@with_app(buildername='html')
|
||||
def test_jsmath(app, status, warning):
|
||||
app.builder.build_all()
|
||||
content = (app.outdir / 'math.html').text()
|
||||
|
||||
assert '<div class="math">\na^2 + b^2 = c^2</div>' in content
|
||||
assert '<div class="math">\n\\begin{split}a + 1 < b\\end{split}</div>' in content
|
||||
assert ('<span class="eqno">(1)</span><div class="math" id="equation-foo">\n'
|
||||
'e^{i\\pi} = 1</div>' in content)
|
||||
assert ('<span class="eqno">(2)</span><div class="math">\n'
|
||||
'e^{ix} = \\cos x + i\\sin x</div>' in content)
|
||||
assert '<div class="math">\nn \\in \\mathbb N</div>' in content
|
||||
assert '<div class="math">\na + 1 < b</div>' in content
|
||||
|
||||
|
||||
@with_app(buildername='html', testroot='html_extra_path')
|
||||
def test_html_extra_path(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
assert (app.outdir / '.htaccess').exists()
|
||||
assert not (app.outdir / '.htpasswd').exists()
|
||||
assert (app.outdir / 'API.html_t').exists()
|
||||
assert (app.outdir / 'css/style.css').exists()
|
||||
assert (app.outdir / 'rimg.png').exists()
|
||||
assert not (app.outdir / '_build/index.html').exists()
|
||||
assert (app.outdir / 'background.png').exists()
|
||||
|
||||
@gen_with_app(buildername='html', testroot='stylesheets')
|
||||
def test_alternate_stylesheets(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
Reference in New Issue
Block a user