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.py159
1 files changed, 68 insertions, 91 deletions
diff --git a/tests/test_build_html.py b/tests/test_build_html.py
index 17a09eae..62dcccd2 100644
--- a/tests/test_build_html.py
+++ b/tests/test_build_html.py
@@ -12,39 +12,30 @@
import os
import re
-from six import PY3, iteritems, StringIO
+from six import PY3, iteritems
from six.moves import html_entities
-try:
- import pygments
-except ImportError:
- pygments = None
-
from sphinx import __version__
-from util import test_root, test_roots, remove_unicode_literals, gen_with_app, with_app
+from util import remove_unicode_literals, gen_with_app
from etree13 import ElementTree as ET
-def teardown_module():
- (test_root / '_build').rmtree(True)
-
-
-html_warnfile = StringIO()
-
ENV_WARNINGS = """\
-%(root)s/autodoc_fodder.py:docstring of autodoc_fodder\\.MarkupError:2: \
+(%(root)s/autodoc_fodder.py:docstring of autodoc_fodder\\.MarkupError:2: \
WARNING: Explicit markup ends without a blank line; unexpected \
unindent\\.\\n?
-%(root)s/images.txt:9: WARNING: image file not readable: foo.png
+)?%(root)s/images.txt:9: WARNING: image file not readable: foo.png
%(root)s/images.txt:23: WARNING: nonlocal image URI found: \
http://www.python.org/logo.png
%(root)s/includes.txt:\\d*: WARNING: Encoding 'utf-8-sig' used for \
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'Python c option', does \
-not contain option marker - or -- or /
-"""
+(%(root)s/markup.txt:\\d+: WARNING: Malformed :option: u'Python c option', does \
+not contain option marker - or -- or / or \\+
+%(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.\\*'
@@ -61,6 +52,7 @@ if PY3:
def tail_check(check):
rex = re.compile(check)
+
def checker(nodes):
for node in nodes:
if node.tail and rex.search(node.tail):
@@ -84,6 +76,8 @@ HTML_XPATH = {
(".//a[@href='../_downloads/img.png']", ''),
(".//img[@src='../_images/img.png']", ''),
(".//p", 'This is an include file.'),
+ (".//pre/span", 'line 1'),
+ (".//pre/span", 'line 2'),
],
'includes.html': [
(".//pre", u'Max Strauß'),
@@ -91,6 +85,23 @@ HTML_XPATH = {
(".//a[@href='_downloads/img1.png']", ''),
(".//pre", u'"quotes"'),
(".//pre", u"'included'"),
+ (".//pre/span[@class='s']", u'üöä'),
+ (".//div[@class='inc-pyobj1 highlight-text']//pre",
+ r'^class Foo:\n pass\n\s*$'),
+ (".//div[@class='inc-pyobj2 highlight-text']//pre",
+ r'^ def baz\(\):\n pass\n\s*$'),
+ (".//div[@class='inc-lines highlight-text']//pre",
+ r'^class Foo:\n pass\nclass Bar:\n$'),
+ (".//div[@class='inc-startend highlight-text']//pre",
+ u'^foo = "Including Unicode characters: üöä"\\n$'),
+ (".//div[@class='inc-preappend highlight-text']//pre",
+ r'(?m)^START CODE$'),
+ (".//div[@class='inc-pyobj-dedent highlight-python']//span",
+ r'def'),
+ (".//div[@class='inc-tab3 highlight-text']//pre",
+ r'-| |-'),
+ (".//div[@class='inc-tab8 highlight-python']//pre/span",
+ r'-| |-'),
],
'autodoc.html': [
(".//dt[@id='test_autodoc.Class']", ''),
@@ -144,7 +155,7 @@ HTML_XPATH = {
(".//a[@href='subdir/includes.html']"
"[@class='reference internal']/em", 'Including in subdir'),
(".//a[@href='objects.html#cmdoption-python-c']"
- "[@class='reference internal']/em", 'Python -c option'),
+ "[@class='reference internal']/code/span[@class='pre']", '-c'),
# abbreviations
(".//abbr[@title='abbreviation']", '^abbr$'),
# version stuff
@@ -175,6 +186,9 @@ HTML_XPATH = {
(".//p", 'In HTML.'),
(".//p", 'In both.'),
(".//p", 'Always present'),
+ # tests for ``any`` role
+ (".//a[@href='#with']/em", 'headings'),
+ (".//a[@href='objects.html#func_without_body']/code/span", 'objects'),
],
'objects.html': [
(".//dt[@id='mod.Cls.meth1']", ''),
@@ -212,12 +226,10 @@ HTML_XPATH = {
(".//h4", 'Custom sidebar'),
# docfields
(".//td[@class='field-body']/strong", '^moo$'),
- (".//td[@class='field-body']/strong",
- tail_check(r'\(Moo\) .* Moo')),
+ (".//td[@class='field-body']/strong", tail_check(r'\(Moo\) .* Moo')),
(".//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')),
+ (".//td[@class='field-body']/ul/li/em", tail_check(r'.* Some parameter')),
],
'contents.html': [
(".//meta[@name='hc'][@content='hcval']", ''),
@@ -238,6 +250,11 @@ HTML_XPATH = {
(".//h4", 'Contents sidebar'),
# custom JavaScript
(".//script[@src='file://moo.js']", ''),
+ # URL in contents
+ (".//a[@class='reference external'][@href='http://sphinx-doc.org/']",
+ 'http://sphinx-doc.org/'),
+ (".//a[@class='reference external'][@href='http://sphinx-doc.org/latest/']",
+ 'Latest reference'),
],
'bom.html': [
(".//title", " File with UTF-8 BOM"),
@@ -257,33 +274,19 @@ HTML_XPATH = {
(".//a/strong", "Other"),
(".//a", "entry"),
(".//dt/a", "double"),
- ]
+ ],
+ 'footnote.html': [
+ (".//a[@class='footnote-reference'][@href='#id5'][@id='id1']", r"\[1\]"),
+ (".//a[@class='footnote-reference'][@href='#id6'][@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='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\]"),
+ ],
}
-if pygments:
- HTML_XPATH['includes.html'].extend([
- (".//pre/span[@class='s']", u'üöä'),
- (".//div[@class='inc-pyobj1 highlight-text']//pre",
- r'^class Foo:\n pass\n\s*$'),
- (".//div[@class='inc-pyobj2 highlight-text']//pre",
- r'^ def baz\(\):\n pass\n\s*$'),
- (".//div[@class='inc-lines highlight-text']//pre",
- r'^class Foo:\n pass\nclass Bar:\n$'),
- (".//div[@class='inc-startend highlight-text']//pre",
- u'^foo = "Including Unicode characters: üöä"\\n$'),
- (".//div[@class='inc-preappend highlight-text']//pre",
- r'(?m)^START CODE$'),
- (".//div[@class='inc-pyobj-dedent highlight-python']//span",
- r'def'),
- (".//div[@class='inc-tab3 highlight-text']//pre",
- r'-| |-'),
- (".//div[@class='inc-tab8 highlight-python']//pre/span",
- r'-| |-'),
- ])
- HTML_XPATH['subdir/includes.html'].extend([
- (".//pre/span", 'line 1'),
- (".//pre/span", 'line 2'),
- ])
class NslessParser(ET.XMLParser):
"""XMLParser that throws away namespaces in tag names."""
@@ -317,7 +320,8 @@ def check_xpath(etree, fname, path, check, be_found=True):
else:
assert False, ('%r not found in any node matching '
'path %s in %s: %r' % (check, path, fname,
- [node.text for node in nodes]))
+ [node.text for node in nodes]))
+
def check_static_entries(outdir):
staticdir = outdir / '_static'
@@ -332,21 +336,23 @@ def check_static_entries(outdir):
# a file from _static, but matches exclude_patterns
assert not (staticdir / 'excluded.css').exists()
+
def check_extra_entries(outdir):
assert (outdir / 'robots.txt').isfile()
-@gen_with_app(buildername='html', warning=html_warnfile, cleanenv=True,
+
+@gen_with_app(buildername='html',
confoverrides={'html_context.hckey_co': 'hcval_co'},
tags=['testtag'])
-def test_html(app):
+def test_html_output(app, status, warning):
app.builder.build_all()
- html_warnings = html_warnfile.getvalue().replace(os.sep, '/')
+ html_warnings = warning.getvalue().replace(os.sep, '/')
html_warnings_exp = HTML_WARNINGS % {
- 'root': re.escape(app.srcdir.replace(os.sep, '/'))}
+ 'root': re.escape(app.srcdir.replace(os.sep, '/'))}
assert re.match(html_warnings_exp + '$', html_warnings), \
- 'Warnings don\'t match:\n' + \
- '--- Expected (regex):\n' + html_warnings_exp + \
- '--- Got:\n' + html_warnings
+ 'Warnings don\'t match:\n' + \
+ '--- Expected (regex):\n' + html_warnings_exp + \
+ '--- Got:\n' + html_warnings
for fname, paths in iteritems(HTML_XPATH):
parser = NslessParser()
@@ -362,23 +368,9 @@ def test_html(app):
check_static_entries(app.builder.outdir)
check_extra_entries(app.builder.outdir)
-@with_app(buildername='html', srcdir='(empty)',
- confoverrides={'html_sidebars': {'*': ['globaltoc.html']}},
- )
-def test_html_with_globaltoc_and_hidden_toctree(app):
- # issue #1157: combination of 'globaltoc.html' and hidden toctree cause
- # exception.
- (app.srcdir / 'contents.rst').write_text(
- '\n.. toctree::'
- '\n'
- '\n.. toctree::'
- '\n :hidden:'
- '\n')
- app.builder.build_all()
-
-@gen_with_app(buildername='html', srcdir=(test_roots / 'test-tocdepth'))
-def test_tocdepth(app):
+@gen_with_app(buildername='html', testroot='tocdepth')
+def test_tocdepth(app, status, warning):
# issue #1251
app.builder.build_all()
@@ -388,14 +380,14 @@ def test_tocdepth(app):
(".//li[@class='toctree-l3']/a", '1.2.1. Foo B1', True),
(".//li[@class='toctree-l3']/a", '2.1.1. Bar A1', False),
(".//li[@class='toctree-l3']/a", '2.2.1. Bar B1', False),
- ],
+ ],
'foo.html': [
(".//h1", '1. Foo', True),
(".//h2", '1.1. Foo A', True),
(".//h3", '1.1.1. Foo A1', True),
(".//h2", '1.2. Foo B', True),
(".//h3", '1.2.1. Foo B1', True),
- ],
+ ],
'bar.html': [
(".//h1", '2. Bar', True),
(".//h2", '2.1. Bar A', True),
@@ -420,8 +412,8 @@ def test_tocdepth(app):
yield check_xpath, etree, fname, xpath, check, be_found
-@gen_with_app(buildername='singlehtml', srcdir=(test_roots / 'test-tocdepth'))
-def test_tocdepth_singlehtml(app):
+@gen_with_app(buildername='singlehtml', testroot='tocdepth')
+def test_tocdepth_singlehtml(app, status, warning):
app.builder.build_all()
expects = {
@@ -463,18 +455,3 @@ def test_tocdepth_singlehtml(app):
for xpath, check, be_found in paths:
yield check_xpath, etree, fname, xpath, check, be_found
-
-
-@with_app(buildername='html', srcdir='(empty)')
-def test_url_in_toctree(app):
- contents = (".. toctree::\n"
- "\n"
- " http://sphinx-doc.org/\n"
- " Latest reference <http://sphinx-doc.org/latest/>\n")
-
- (app.srcdir / 'contents.rst').write_text(contents, encoding='utf-8')
- app.builder.build_all()
-
- result = (app.outdir / 'contents.html').text(encoding='utf-8')
- assert '<a class="reference external" href="http://sphinx-doc.org/">http://sphinx-doc.org/</a>' in result
- assert '<a class="reference external" href="http://sphinx-doc.org/latest/">Latest reference</a>' in result