mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-09-03 20:52:55 -05:00
Complete test suite overhaul.
* rename a few test modules to make the names more consistent * do not copy/use Sphinx from build/ (unnecessary without 2to3) * use a temporary dir for *all* test projects, the source tree will stay pristine that way (default is tests/build) * speed up tests by ~3x by splitting up test projects and avoiding rebuilds
This commit is contained in:
+58
-84
@@ -15,22 +15,11 @@ import re
|
||||
from six import PY3, iteritems, StringIO
|
||||
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: \
|
||||
WARNING: Explicit markup ends without a blank line; unexpected \
|
||||
@@ -44,6 +33,8 @@ reading included file u'.*?wrongenc.inc' seems to be wrong, try giving an \
|
||||
%(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 / or \\+
|
||||
%(root)s/undecodable.txt:3: WARNING: undecodable source characters, replacing \
|
||||
with "\\?": b?'here: >>>\\\\xbb<<<'
|
||||
"""
|
||||
|
||||
HTML_WARNINGS = ENV_WARNINGS + """\
|
||||
@@ -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']", ''),
|
||||
@@ -215,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']", ''),
|
||||
@@ -241,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"),
|
||||
@@ -260,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."""
|
||||
@@ -320,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'
|
||||
@@ -335,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', freshenv=True,
|
||||
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()
|
||||
@@ -365,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()
|
||||
|
||||
@@ -391,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),
|
||||
@@ -423,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 = {
|
||||
@@ -466,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
|
||||
|
||||
Reference in New Issue
Block a user