summaryrefslogtreecommitdiff
path: root/tests/test_build_html.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_build_html.py')
-rw-r--r--tests/test_build_html.py52
1 files changed, 42 insertions, 10 deletions
diff --git a/tests/test_build_html.py b/tests/test_build_html.py
index f27832c82..def6722c3 100644
--- a/tests/test_build_html.py
+++ b/tests/test_build_html.py
@@ -16,6 +16,7 @@ from itertools import cycle, chain
from six import PY3
from sphinx import __display_version__
+from sphinx.util.inventory import InventoryFile
from util import remove_unicode_literals, strip_escseq
import xml.etree.cElementTree as ElementTree
from html5lib import getTreeBuilder, HTMLParser
@@ -39,10 +40,10 @@ with "\\?": b?'here: >>>(\\\\|/)xbb<<<((\\\\|/)r)?'
"""
HTML_WARNINGS = ENV_WARNINGS + """\
-%(root)s/index.rst:\\d+: WARNING: no matching candidate for image URI u'foo.\\*'
-%(root)s/index.rst:\\d+: WARNING: Could not lex literal_block as "c". Highlighting skipped.
%(root)s/index.rst:\\d+: WARNING: unknown option: &option
%(root)s/index.rst:\\d+: WARNING: citation not found: missing
+%(root)s/index.rst:\\d+: WARNING: no matching candidate for image URI u'foo.\\*'
+%(root)s/index.rst:\\d+: WARNING: Could not lex literal_block as "c". Highlighting skipped.
"""
if PY3:
@@ -109,9 +110,9 @@ def check_xpath(etree, fname, path, check, be_found=True):
# Since pygments-2.1.1, empty <span> tag is inserted at top of
# highlighting block
if len(node) == 1 and node[0].tag == 'span' and node[0].text is None:
- return node[0].tail
- else:
- return ''
+ if node[0].tail is not None:
+ return node[0].tail
+ return ''
rex = re.compile(check)
if be_found:
@@ -346,7 +347,7 @@ def test_static_output(app):
(".//a[@class='reference internal'][@href='#cmdoption-perl-arg-p']/code/span",
'perl'),
(".//a[@class='reference internal'][@href='#cmdoption-perl-arg-p']/code/span",
- '\+p'),
+ '\\+p'),
(".//a[@class='reference internal'][@href='#cmdoption-perl-objc']/code/span",
'--ObjC\\+\\+'),
(".//a[@class='reference internal'][@href='#cmdoption-perl-plugin-option']/code/span",
@@ -415,18 +416,19 @@ def test_static_output(app):
(".//li/a", "double"),
],
'footnote.html': [
- (".//a[@class='footnote-reference'][@href='#id7'][@id='id1']", r"\[1\]"),
- (".//a[@class='footnote-reference'][@href='#id8'][@id='id2']", r"\[2\]"),
+ (".//a[@class='footnote-reference'][@href='#id8'][@id='id1']", r"\[1\]"),
+ (".//a[@class='footnote-reference'][@href='#id9'][@id='id2']", r"\[2\]"),
(".//a[@class='footnote-reference'][@href='#foo'][@id='id3']", r"\[3\]"),
(".//a[@class='reference internal'][@href='#bar'][@id='id4']", r"\[bar\]"),
- (".//a[@class='footnote-reference'][@href='#id9'][@id='id5']", r"\[4\]"),
- (".//a[@class='footnote-reference'][@href='#id10'][@id='id6']", r"\[5\]"),
+ (".//a[@class='footnote-reference'][@href='#id10'][@id='id5']", r"\[4\]"),
+ (".//a[@class='footnote-reference'][@href='#id11'][@id='id6']", r"\[5\]"),
(".//a[@class='fn-backref'][@href='#id1']", r"\[1\]"),
(".//a[@class='fn-backref'][@href='#id2']", r"\[2\]"),
(".//a[@class='fn-backref'][@href='#id3']", r"\[3\]"),
(".//a[@class='fn-backref'][@href='#id4']", r"\[bar\]"),
(".//a[@class='fn-backref'][@href='#id5']", r"\[4\]"),
(".//a[@class='fn-backref'][@href='#id6']", r"\[5\]"),
+ (".//a[@class='fn-backref'][@href='#id7']", r"\[6\]"),
],
'otherext.html': [
(".//h1", "Generated section"),
@@ -440,6 +442,10 @@ def test_html_output(app, cached_etree_parse, fname, expect):
app.build()
check_xpath(cached_etree_parse(app.outdir / fname), fname, *expect)
+@pytest.mark.sphinx('html', testroot='build-html-translator')
+def test_html_translator(app):
+ app.build()
+ assert app.builder.docwriter.visitor.depart_with_node == 10
@pytest.mark.parametrize("fname,expect", flat_dict({
'index.html': [
@@ -1148,3 +1154,29 @@ def test_html_entity(app):
content = (app.outdir / 'index.html').text()
for entity in re.findall(r'&([a-z]+);', content, re.M):
assert entity not in valid_entities
+
+
+@pytest.mark.sphinx('html', testroot='basic')
+def test_html_inventory(app):
+ app.builder.build_all()
+ with open(app.outdir / 'objects.inv', 'rb') as f:
+ invdata = InventoryFile.load(f, 'http://example.com', os.path.join)
+ assert set(invdata.keys()) == {'std:label', 'std:doc'}
+ assert set(invdata['std:label'].keys()) == {'modindex', 'genindex', 'search'}
+ assert invdata['std:label']['modindex'] == ('Python',
+ '',
+ 'http://example.com/py-modindex.html',
+ 'Module Index')
+ assert invdata['std:label']['genindex'] == ('Python',
+ '',
+ 'http://example.com/genindex.html',
+ 'Index')
+ assert invdata['std:label']['search'] == ('Python',
+ '',
+ 'http://example.com/search.html',
+ 'Search Page')
+ assert set(invdata['std:doc'].keys()) == {'index'}
+ assert invdata['std:doc']['index'] == ('Python',
+ '',
+ 'http://example.com/index.html',
+ 'The basic Sphinx documentation for testing')