2009-09-08 05:07:27 -05:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
test_build_html
|
|
|
|
~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Test the HTML builder and check output against XPath.
|
|
|
|
|
2014-03-01 01:18:16 -06:00
|
|
|
:copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS.
|
2009-09-08 05:07:27 -05:00
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
2014-04-28 21:46:47 -05:00
|
|
|
|
2014-09-21 13:28:37 -05:00
|
|
|
from six import PY3, iteritems
|
2014-04-30 06:39:26 -05:00
|
|
|
from six.moves import html_entities
|
2009-09-08 05:07:27 -05:00
|
|
|
|
2010-01-07 09:20:52 -06:00
|
|
|
from sphinx import __version__
|
2014-09-21 10:17:02 -05:00
|
|
|
from util import remove_unicode_literals, gen_with_app
|
2009-09-08 05:07:27 -05:00
|
|
|
from etree13 import ElementTree as ET
|
|
|
|
|
|
|
|
|
2010-01-17 05:29:00 -06:00
|
|
|
ENV_WARNINGS = """\
|
2014-09-21 11:41:08 -05:00
|
|
|
(%(root)s/autodoc_fodder.py:docstring of autodoc_fodder\\.MarkupError:2: \
|
2011-09-23 02:46:24 -05:00
|
|
|
WARNING: Explicit markup ends without a blank line; unexpected \
|
2011-01-03 08:55:30 -06:00
|
|
|
unindent\\.\\n?
|
2014-09-21 11:41:08 -05:00
|
|
|
)?%(root)s/images.txt:9: WARNING: image file not readable: foo.png
|
2010-01-17 05:29:00 -06:00
|
|
|
%(root)s/images.txt:23: WARNING: nonlocal image URI found: \
|
|
|
|
http://www.python.org/logo.png
|
2011-09-23 02:46:24 -05:00
|
|
|
%(root)s/includes.txt:\\d*: WARNING: Encoding 'utf-8-sig' used for \
|
2010-08-23 11:48:51 -05:00
|
|
|
reading included file u'.*?wrongenc.inc' seems to be wrong, try giving an \
|
2010-07-27 12:19:29 -05:00
|
|
|
:encoding: option\\n?
|
2010-08-25 06:33:25 -05:00
|
|
|
%(root)s/includes.txt:4: WARNING: download file not readable: .*?nonexisting.png
|
2014-09-21 11:41:08 -05:00
|
|
|
(%(root)s/markup.txt:\\d+: WARNING: Malformed :option: u'Python c option', does \
|
2014-09-20 13:54:23 -05:00
|
|
|
not contain option marker - or -- or / or \\+
|
2014-09-21 10:17:02 -05:00
|
|
|
%(root)s/undecodable.txt:3: WARNING: undecodable source characters, replacing \
|
2014-09-23 11:41:01 -05:00
|
|
|
with "\\?": b?'here: >>>(\\\\|/)xbb<<<'
|
2014-09-21 11:41:08 -05:00
|
|
|
)?"""
|
2010-01-17 05:29:00 -06:00
|
|
|
|
2009-09-08 05:07:27 -05:00
|
|
|
HTML_WARNINGS = ENV_WARNINGS + """\
|
2010-06-03 10:25:16 -05:00
|
|
|
%(root)s/images.txt:20: WARNING: no matching candidate for image URI u'foo.\\*'
|
2013-05-01 20:37:12 -05:00
|
|
|
None:\\d+: WARNING: citation not found: missing
|
2011-01-07 12:00:29 -06:00
|
|
|
%(root)s/markup.txt:: WARNING: invalid single index entry u''
|
2009-09-08 05:07:27 -05:00
|
|
|
%(root)s/markup.txt:: WARNING: invalid pair index entry u''
|
|
|
|
%(root)s/markup.txt:: WARNING: invalid pair index entry u'keyword; '
|
|
|
|
"""
|
|
|
|
|
2014-04-30 07:30:46 -05:00
|
|
|
if PY3:
|
2010-07-28 12:49:06 -05:00
|
|
|
ENV_WARNINGS = remove_unicode_literals(ENV_WARNINGS)
|
|
|
|
HTML_WARNINGS = remove_unicode_literals(HTML_WARNINGS)
|
|
|
|
|
|
|
|
|
2010-07-27 12:19:29 -05:00
|
|
|
def tail_check(check):
|
|
|
|
rex = re.compile(check)
|
2014-09-21 10:17:02 -05:00
|
|
|
|
2010-07-27 12:19:29 -05:00
|
|
|
def checker(nodes):
|
|
|
|
for node in nodes:
|
|
|
|
if node.tail and rex.search(node.tail):
|
|
|
|
return True
|
|
|
|
assert False, '%r not found in tail of any nodes %s' % (check, nodes)
|
|
|
|
return checker
|
|
|
|
|
|
|
|
|
2009-09-08 05:07:27 -05:00
|
|
|
HTML_XPATH = {
|
2010-07-21 05:33:24 -05:00
|
|
|
'images.html': [
|
|
|
|
(".//img[@src='_images/img.png']", ''),
|
|
|
|
(".//img[@src='_images/img1.png']", ''),
|
|
|
|
(".//img[@src='_images/simg.png']", ''),
|
2011-09-19 02:19:35 -05:00
|
|
|
(".//img[@src='_images/svgimg.svg']", ''),
|
2010-07-21 05:33:24 -05:00
|
|
|
],
|
|
|
|
'subdir/images.html': [
|
|
|
|
(".//img[@src='../_images/img1.png']", ''),
|
|
|
|
(".//img[@src='../_images/rimg.png']", ''),
|
|
|
|
],
|
|
|
|
'subdir/includes.html': [
|
|
|
|
(".//a[@href='../_downloads/img.png']", ''),
|
|
|
|
(".//img[@src='../_images/img.png']", ''),
|
|
|
|
(".//p", 'This is an include file.'),
|
2014-09-21 10:17:02 -05:00
|
|
|
(".//pre/span", 'line 1'),
|
|
|
|
(".//pre/span", 'line 2'),
|
2010-07-21 05:33:24 -05:00
|
|
|
],
|
|
|
|
'includes.html': [
|
|
|
|
(".//pre", u'Max Strauß'),
|
|
|
|
(".//a[@href='_downloads/img.png']", ''),
|
|
|
|
(".//a[@href='_downloads/img1.png']", ''),
|
|
|
|
(".//pre", u'"quotes"'),
|
|
|
|
(".//pre", u"'included'"),
|
2014-09-21 10:17:02 -05:00
|
|
|
(".//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'-| |-'),
|
2010-07-21 05:33:24 -05:00
|
|
|
],
|
|
|
|
'autodoc.html': [
|
|
|
|
(".//dt[@id='test_autodoc.Class']", ''),
|
|
|
|
(".//dt[@id='test_autodoc.function']/em", r'\*\*kwds'),
|
|
|
|
(".//dd/p", r'Return spam\.'),
|
|
|
|
],
|
|
|
|
'extapi.html': [
|
|
|
|
(".//strong", 'from function: Foo'),
|
|
|
|
(".//strong", 'from class: Bar'),
|
|
|
|
],
|
|
|
|
'markup.html': [
|
|
|
|
(".//title", 'set by title directive'),
|
|
|
|
(".//p/em", 'Section author: Georg Brandl'),
|
|
|
|
(".//p/em", 'Module author: Georg Brandl'),
|
2009-09-08 05:07:27 -05:00
|
|
|
# created by the meta directive
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//meta[@name='author'][@content='Me']", ''),
|
|
|
|
(".//meta[@name='keywords'][@content='docs, sphinx']", ''),
|
2009-09-08 05:07:27 -05:00
|
|
|
# a label created by ``.. _label:``
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//div[@id='label']", ''),
|
2009-09-08 05:07:27 -05:00
|
|
|
# code with standard code blocks
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//pre", '^some code$'),
|
2009-09-08 05:07:27 -05:00
|
|
|
# an option list
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//span[@class='option']", '--help'),
|
2009-09-08 05:07:27 -05:00
|
|
|
# admonitions
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//p[@class='first admonition-title']", 'My Admonition'),
|
|
|
|
(".//p[@class='last']", 'Note text.'),
|
|
|
|
(".//p[@class='last']", 'Warning text.'),
|
2009-09-08 05:07:27 -05:00
|
|
|
# inline markup
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//li/strong", r'^command\\n$'),
|
|
|
|
(".//li/strong", r'^program\\n$'),
|
|
|
|
(".//li/em", r'^dfn\\n$'),
|
2014-08-11 22:12:10 -05:00
|
|
|
(".//li/code/span[@class='pre']", r'^kbd\\n$'),
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//li/em", u'File \N{TRIANGULAR BULLET} Close'),
|
2014-08-11 22:12:10 -05:00
|
|
|
(".//li/code/span[@class='pre']", '^a/$'),
|
|
|
|
(".//li/code/em/span[@class='pre']", '^varpart$'),
|
|
|
|
(".//li/code/em/span[@class='pre']", '^i$'),
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//a[@href='http://www.python.org/dev/peps/pep-0008']"
|
|
|
|
"[@class='pep reference external']/strong", 'PEP 8'),
|
2014-08-19 22:27:08 -05:00
|
|
|
(".//a[@href='http://www.python.org/dev/peps/pep-0008']"
|
|
|
|
"[@class='pep reference external']/strong", 'Python Enhancement Proposal #8'),
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//a[@href='http://tools.ietf.org/html/rfc1.html']"
|
|
|
|
"[@class='rfc reference external']/strong", 'RFC 1'),
|
2014-08-19 22:27:08 -05:00
|
|
|
(".//a[@href='http://tools.ietf.org/html/rfc1.html']"
|
|
|
|
"[@class='rfc reference external']/strong", 'Request for Comments #1'),
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//a[@href='objects.html#envvar-HOME']"
|
2014-08-11 22:12:10 -05:00
|
|
|
"[@class='reference internal']/code/span[@class='pre']", 'HOME'),
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//a[@href='#with']"
|
2014-08-11 22:12:10 -05:00
|
|
|
"[@class='reference internal']/code/span[@class='pre']", '^with$'),
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//a[@href='#grammar-token-try_stmt']"
|
2014-08-11 22:12:10 -05:00
|
|
|
"[@class='reference internal']/code/span", '^statement$'),
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//a[@href='subdir/includes.html']"
|
|
|
|
"[@class='reference internal']/em", 'Including in subdir'),
|
|
|
|
(".//a[@href='objects.html#cmdoption-python-c']"
|
2014-09-20 13:54:23 -05:00
|
|
|
"[@class='reference internal']/code/span[@class='pre']", '-c'),
|
2009-09-08 05:07:27 -05:00
|
|
|
# abbreviations
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//abbr[@title='abbreviation']", '^abbr$'),
|
2009-09-08 05:07:27 -05:00
|
|
|
# version stuff
|
2013-01-06 03:37:21 -06:00
|
|
|
(".//div[@class='versionadded']/p/span", 'New in version 0.6: '),
|
|
|
|
(".//div[@class='versionadded']/p/span",
|
2013-01-06 03:05:49 -06:00
|
|
|
tail_check('First paragraph of versionadded')),
|
2013-01-06 03:37:21 -06:00
|
|
|
(".//div[@class='versionchanged']/p/span",
|
2013-01-06 03:05:49 -06:00
|
|
|
tail_check('First paragraph of versionchanged')),
|
2013-01-06 03:37:21 -06:00
|
|
|
(".//div[@class='versionchanged']/p",
|
|
|
|
'Second paragraph of versionchanged'),
|
2009-09-08 05:07:27 -05:00
|
|
|
# footnote reference
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//a[@class='footnote-reference']", r'\[1\]'),
|
2009-09-08 05:07:27 -05:00
|
|
|
# created by reference lookup
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//a[@href='contents.html#ref1']", ''),
|
2009-09-08 05:07:27 -05:00
|
|
|
# ``seealso`` directive
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//div/p[@class='first admonition-title']", 'See also'),
|
2009-09-08 05:07:27 -05:00
|
|
|
# a ``hlist`` directive
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//table[@class='hlist']/tr/td/ul/li", '^This$'),
|
2009-09-08 05:07:27 -05:00
|
|
|
# a ``centered`` directive
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//p[@class='centered']/strong", 'LICENSE'),
|
2009-09-08 05:07:27 -05:00
|
|
|
# a glossary
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//dl/dt[@id='term-boson']", 'boson'),
|
2009-09-08 05:07:27 -05:00
|
|
|
# a production list
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//pre/strong", 'try_stmt'),
|
2014-08-11 22:12:10 -05:00
|
|
|
(".//pre/a[@href='#grammar-token-try1_stmt']/code/span", 'try1_stmt'),
|
2009-09-08 05:07:27 -05:00
|
|
|
# tests for ``only`` directive
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//p", 'A global substitution.'),
|
|
|
|
(".//p", 'In HTML.'),
|
|
|
|
(".//p", 'In both.'),
|
|
|
|
(".//p", 'Always present'),
|
2014-09-19 07:17:36 -05:00
|
|
|
# tests for ``any`` role
|
|
|
|
(".//a[@href='#with']/em", 'headings'),
|
|
|
|
(".//a[@href='objects.html#func_without_body']/code/span", 'objects'),
|
2010-07-21 05:33:24 -05:00
|
|
|
],
|
|
|
|
'objects.html': [
|
|
|
|
(".//dt[@id='mod.Cls.meth1']", ''),
|
|
|
|
(".//dt[@id='errmod.Error']", ''),
|
2014-08-11 22:12:10 -05:00
|
|
|
(".//dt/code", r'long\(parameter,\s* list\)'),
|
|
|
|
(".//dt/code", 'another one'),
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//a[@href='#mod.Cls'][@class='reference internal']", ''),
|
|
|
|
(".//dl[@class='userdesc']", ''),
|
|
|
|
(".//dt[@id='userdesc-myobj']", ''),
|
2010-08-14 09:51:04 -05:00
|
|
|
(".//a[@href='#userdesc-myobj'][@class='reference internal']", ''),
|
2009-09-08 05:07:27 -05:00
|
|
|
# C references
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//span[@class='pre']", 'CFunction()'),
|
2014-01-17 00:08:32 -06:00
|
|
|
(".//a[@href='#c.Sphinx_DoSomething']", ''),
|
|
|
|
(".//a[@href='#c.SphinxStruct.member']", ''),
|
|
|
|
(".//a[@href='#c.SPHINX_USE_PYTHON']", ''),
|
|
|
|
(".//a[@href='#c.SphinxType']", ''),
|
|
|
|
(".//a[@href='#c.sphinx_global']", ''),
|
2009-09-09 08:56:52 -05:00
|
|
|
# test global TOC created by toctree()
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//ul[@class='current']/li[@class='toctree-l1 current']/a[@href='']",
|
|
|
|
'Testing object descriptions'),
|
|
|
|
(".//li[@class='toctree-l1']/a[@href='markup.html']",
|
|
|
|
'Testing various markup'),
|
2013-06-23 15:06:45 -05:00
|
|
|
# test unknown field names
|
|
|
|
(".//th[@class='field-name']", 'Field_name:'),
|
|
|
|
(".//th[@class='field-name']", 'Field_name all lower:'),
|
|
|
|
(".//th[@class='field-name']", 'FIELD_NAME:'),
|
|
|
|
(".//th[@class='field-name']", 'FIELD_NAME ALL CAPS:'),
|
|
|
|
(".//th[@class='field-name']", 'Field_Name:'),
|
|
|
|
(".//th[@class='field-name']", 'Field_Name All Word Caps:'),
|
|
|
|
(".//th[@class='field-name']", 'Field_name:'),
|
|
|
|
(".//th[@class='field-name']", 'Field_name First word cap:'),
|
|
|
|
(".//th[@class='field-name']", 'FIELd_name:'),
|
|
|
|
(".//th[@class='field-name']", 'FIELd_name PARTial caps:'),
|
2010-01-07 10:56:09 -06:00
|
|
|
# custom sidebar
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//h4", 'Custom sidebar'),
|
2010-07-27 12:19:29 -05:00
|
|
|
# docfields
|
2011-01-03 17:23:27 -06:00
|
|
|
(".//td[@class='field-body']/strong", '^moo$'),
|
2014-09-21 10:17:02 -05:00
|
|
|
(".//td[@class='field-body']/strong", tail_check(r'\(Moo\) .* Moo')),
|
2011-01-03 17:23:27 -06:00
|
|
|
(".//td[@class='field-body']/ul/li/strong", '^hour$'),
|
|
|
|
(".//td[@class='field-body']/ul/li/em", '^DuplicateType$'),
|
2014-09-21 10:17:02 -05:00
|
|
|
(".//td[@class='field-body']/ul/li/em", tail_check(r'.* Some parameter')),
|
2010-07-21 05:33:24 -05:00
|
|
|
],
|
|
|
|
'contents.html': [
|
|
|
|
(".//meta[@name='hc'][@content='hcval']", ''),
|
|
|
|
(".//meta[@name='hc_co'][@content='hcval_co']", ''),
|
|
|
|
(".//meta[@name='testopt'][@content='testoverride']", ''),
|
|
|
|
(".//td[@class='label']", r'\[Ref1\]'),
|
|
|
|
(".//td[@class='label']", ''),
|
|
|
|
(".//li[@class='toctree-l1']/a", 'Testing various markup'),
|
|
|
|
(".//li[@class='toctree-l2']/a", 'Inline markup'),
|
|
|
|
(".//title", 'Sphinx <Tests>'),
|
|
|
|
(".//div[@class='footer']", 'Georg Brandl & Team'),
|
|
|
|
(".//a[@href='http://python.org/']"
|
|
|
|
"[@class='reference external']", ''),
|
|
|
|
(".//li/a[@href='genindex.html']/em", 'Index'),
|
|
|
|
(".//li/a[@href='py-modindex.html']/em", 'Module Index'),
|
|
|
|
(".//li/a[@href='search.html']/em", 'Search Page'),
|
2010-01-07 10:56:09 -06:00
|
|
|
# custom sidebar only for contents
|
2010-07-21 05:33:24 -05:00
|
|
|
(".//h4", 'Contents sidebar'),
|
2010-08-25 05:26:15 -05:00
|
|
|
# custom JavaScript
|
|
|
|
(".//script[@src='file://moo.js']", ''),
|
2014-09-21 10:17:02 -05:00
|
|
|
# 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'),
|
2010-07-21 05:33:24 -05:00
|
|
|
],
|
|
|
|
'bom.html': [
|
|
|
|
(".//title", " File with UTF-8 BOM"),
|
|
|
|
],
|
|
|
|
'extensions.html': [
|
|
|
|
(".//a[@href='http://python.org/dev/']", "http://python.org/dev/"),
|
|
|
|
(".//a[@href='http://bugs.python.org/issue1000']", "issue 1000"),
|
|
|
|
(".//a[@href='http://bugs.python.org/issue1042']", "explicit caption"),
|
|
|
|
],
|
|
|
|
'_static/statictmpl.html': [
|
|
|
|
(".//project", 'Sphinx <Tests>'),
|
|
|
|
],
|
2011-01-07 12:00:29 -06:00
|
|
|
'genindex.html': [
|
|
|
|
# index entries
|
|
|
|
(".//a/strong", "Main"),
|
|
|
|
(".//a/strong", "[1]"),
|
|
|
|
(".//a/strong", "Other"),
|
|
|
|
(".//a", "entry"),
|
|
|
|
(".//dt/a", "double"),
|
2014-09-21 10:17:02 -05:00
|
|
|
],
|
|
|
|
'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\]"),
|
|
|
|
],
|
2009-09-08 05:07:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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:]
|
2010-07-10 17:57:08 -05:00
|
|
|
self._names[key] = name = self._fixtext(name)
|
2009-09-08 05:07:27 -05:00
|
|
|
return name
|
|
|
|
|
|
|
|
|
2014-08-02 04:10:41 -05:00
|
|
|
def check_xpath(etree, fname, path, check, be_found=True):
|
2009-09-08 05:07:27 -05:00
|
|
|
nodes = list(etree.findall(path))
|
|
|
|
assert nodes != [], ('did not find any node matching xpath '
|
|
|
|
'%r in file %s' % (path, fname))
|
|
|
|
if hasattr(check, '__call__'):
|
|
|
|
check(nodes)
|
|
|
|
elif not check:
|
|
|
|
# only check for node presence
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
rex = re.compile(check)
|
|
|
|
for node in nodes:
|
2014-08-02 04:10:41 -05:00
|
|
|
if node.text and (bool(rex.search(node.text)) ^ (not be_found)):
|
2009-09-08 05:07:27 -05:00
|
|
|
break
|
|
|
|
else:
|
|
|
|
assert False, ('%r not found in any node matching '
|
|
|
|
'path %s in %s: %r' % (check, path, fname,
|
2014-09-21 10:17:02 -05:00
|
|
|
[node.text for node in nodes]))
|
|
|
|
|
2009-09-08 05:07:27 -05:00
|
|
|
|
2010-01-07 09:20:52 -06:00
|
|
|
def check_static_entries(outdir):
|
|
|
|
staticdir = outdir / '_static'
|
|
|
|
assert staticdir.isdir()
|
|
|
|
# a file from a directory entry in html_static_path
|
|
|
|
assert (staticdir / 'README').isfile()
|
|
|
|
# a directory from a directory entry in html_static_path
|
|
|
|
assert (staticdir / 'subdir' / 'foo.css').isfile()
|
|
|
|
# a file from a file entry in html_static_path
|
|
|
|
assert (staticdir / 'templated.css').isfile()
|
|
|
|
assert (staticdir / 'templated.css').text().splitlines()[1] == __version__
|
|
|
|
# a file from _static, but matches exclude_patterns
|
2010-01-07 09:39:59 -06:00
|
|
|
assert not (staticdir / 'excluded.css').exists()
|
2010-01-07 09:20:52 -06:00
|
|
|
|
2014-09-21 10:17:02 -05:00
|
|
|
|
2013-08-22 03:24:00 -05:00
|
|
|
def check_extra_entries(outdir):
|
|
|
|
assert (outdir / 'robots.txt').isfile()
|
|
|
|
|
2014-09-21 10:17:02 -05:00
|
|
|
|
2014-09-21 11:41:08 -05:00
|
|
|
@gen_with_app(buildername='html',
|
2009-12-31 11:40:58 -06:00
|
|
|
confoverrides={'html_context.hckey_co': 'hcval_co'},
|
2009-09-08 05:07:27 -05:00
|
|
|
tags=['testtag'])
|
2014-09-21 10:17:02 -05:00
|
|
|
def test_html_output(app, status, warning):
|
2009-09-08 05:07:27 -05:00
|
|
|
app.builder.build_all()
|
2014-09-21 10:17:02 -05:00
|
|
|
html_warnings = warning.getvalue().replace(os.sep, '/')
|
2012-05-01 22:05:41 -05:00
|
|
|
html_warnings_exp = HTML_WARNINGS % {
|
2014-09-21 10:17:02 -05:00
|
|
|
'root': re.escape(app.srcdir.replace(os.sep, '/'))}
|
2010-06-03 10:25:16 -05:00
|
|
|
assert re.match(html_warnings_exp + '$', html_warnings), \
|
2014-09-21 10:17:02 -05:00
|
|
|
'Warnings don\'t match:\n' + \
|
|
|
|
'--- Expected (regex):\n' + html_warnings_exp + \
|
|
|
|
'--- Got:\n' + html_warnings
|
2009-09-08 05:07:27 -05:00
|
|
|
|
2014-04-29 07:20:56 -05:00
|
|
|
for fname, paths in iteritems(HTML_XPATH):
|
2009-09-08 05:07:27 -05:00
|
|
|
parser = NslessParser()
|
2014-04-30 06:39:26 -05:00
|
|
|
parser.entity.update(html_entities.entitydefs)
|
2012-05-02 01:55:11 -05:00
|
|
|
fp = open(os.path.join(app.outdir, fname), 'rb')
|
2012-01-29 05:23:17 -06:00
|
|
|
try:
|
|
|
|
etree = ET.parse(fp, parser)
|
|
|
|
finally:
|
|
|
|
fp.close()
|
2010-07-21 05:33:24 -05:00
|
|
|
for path, check in paths:
|
2009-09-08 05:07:27 -05:00
|
|
|
yield check_xpath, etree, fname, path, check
|
2010-01-07 09:20:52 -06:00
|
|
|
|
|
|
|
check_static_entries(app.builder.outdir)
|
2013-08-22 03:24:00 -05:00
|
|
|
check_extra_entries(app.builder.outdir)
|
2013-04-30 09:36:27 -05:00
|
|
|
|
2014-08-02 04:10:41 -05:00
|
|
|
|
2014-09-21 10:17:02 -05:00
|
|
|
@gen_with_app(buildername='html', testroot='tocdepth')
|
|
|
|
def test_tocdepth(app, status, warning):
|
2014-08-02 04:10:41 -05:00
|
|
|
# issue #1251
|
|
|
|
app.builder.build_all()
|
|
|
|
|
|
|
|
expects = {
|
|
|
|
'index.html': [
|
|
|
|
(".//li[@class='toctree-l3']/a", '1.1.1. Foo A1', True),
|
|
|
|
(".//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),
|
2014-09-21 10:17:02 -05:00
|
|
|
],
|
2014-08-02 04:10:41 -05:00
|
|
|
'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),
|
2014-09-21 10:17:02 -05:00
|
|
|
],
|
2014-08-02 04:10:41 -05:00
|
|
|
'bar.html': [
|
|
|
|
(".//h1", '2. Bar', True),
|
|
|
|
(".//h2", '2.1. Bar A', True),
|
|
|
|
(".//h2", '2.2. Bar B', True),
|
|
|
|
(".//h3", '2.2.1. Bar B1', True),
|
|
|
|
],
|
2014-08-18 08:06:30 -05:00
|
|
|
'baz.html': [
|
|
|
|
(".//h1", '2.1.1. Baz A', True),
|
|
|
|
],
|
2014-08-02 04:10:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for fname, paths in iteritems(expects):
|
|
|
|
parser = NslessParser()
|
|
|
|
parser.entity.update(html_entities.entitydefs)
|
|
|
|
fp = open(os.path.join(app.outdir, fname), 'rb')
|
|
|
|
try:
|
|
|
|
etree = ET.parse(fp, parser)
|
|
|
|
finally:
|
|
|
|
fp.close()
|
|
|
|
|
|
|
|
for xpath, check, be_found in paths:
|
|
|
|
yield check_xpath, etree, fname, xpath, check, be_found
|
2014-08-11 21:22:34 -05:00
|
|
|
|
|
|
|
|
2014-09-21 10:17:02 -05:00
|
|
|
@gen_with_app(buildername='singlehtml', testroot='tocdepth')
|
|
|
|
def test_tocdepth_singlehtml(app, status, warning):
|
2014-08-11 21:22:34 -05:00
|
|
|
app.builder.build_all()
|
|
|
|
|
|
|
|
expects = {
|
|
|
|
'index.html': [
|
|
|
|
(".//li[@class='toctree-l3']/a", '1.1.1. Foo A1', True),
|
|
|
|
(".//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),
|
|
|
|
|
|
|
|
# index.rst
|
|
|
|
(".//h1", 'test-tocdepth', True),
|
|
|
|
|
|
|
|
# foo.rst
|
|
|
|
(".//h2", '1. Foo', True),
|
|
|
|
(".//h3", '1.1. Foo A', True),
|
|
|
|
(".//h4", '1.1.1. Foo A1', True),
|
|
|
|
(".//h3", '1.2. Foo B', True),
|
|
|
|
(".//h4", '1.2.1. Foo B1', True),
|
|
|
|
|
|
|
|
# bar.rst
|
|
|
|
(".//h2", '2. Bar', True),
|
|
|
|
(".//h3", '2.1. Bar A', True),
|
|
|
|
(".//h3", '2.2. Bar B', True),
|
|
|
|
(".//h4", '2.2.1. Bar B1', True),
|
2014-08-18 08:06:30 -05:00
|
|
|
|
|
|
|
# baz.rst
|
|
|
|
(".//h4", '2.1.1. Baz A', True),
|
2014-08-11 21:22:34 -05:00
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
for fname, paths in iteritems(expects):
|
|
|
|
parser = NslessParser()
|
|
|
|
parser.entity.update(html_entities.entitydefs)
|
|
|
|
fp = open(os.path.join(app.outdir, fname), 'rb')
|
|
|
|
try:
|
|
|
|
etree = ET.parse(fp, parser)
|
|
|
|
finally:
|
|
|
|
fp.close()
|
|
|
|
|
|
|
|
for xpath, check, be_found in paths:
|
|
|
|
yield check_xpath, etree, fname, xpath, check, be_found
|