2022-02-19 21:05:56 -06:00
|
|
|
"""Test all builders."""
|
Merged revisions 65283,65303,65316-65317,65372-65375,65377,65380,65483-65485,65494 via svnmerge from
svn+ssh://pythondev@svn.python.org/doctools/branches/0.4.x
........
r65283 | georg.brandl | 2008-07-29 10:07:26 +0000 (Tue, 29 Jul 2008) | 2 lines
Update ez_setup.py.
........
r65303 | benjamin.peterson | 2008-07-30 12:35:34 +0000 (Wed, 30 Jul 2008) | 1 line
add a with_testapp decorator for test functions that passes the TestApp instance in a cleans up after it
........
r65316 | benjamin.peterson | 2008-07-30 23:12:07 +0000 (Wed, 30 Jul 2008) | 1 line
make the app for test_markup global to the module
........
r65317 | benjamin.peterson | 2008-07-30 23:31:29 +0000 (Wed, 30 Jul 2008) | 1 line
make TestApp.cleanup more aggressive
........
r65372 | georg.brandl | 2008-08-01 19:11:22 +0000 (Fri, 01 Aug 2008) | 2 lines
Add more tests, fix a few bugs in image handling.
........
r65373 | georg.brandl | 2008-08-01 19:28:33 +0000 (Fri, 01 Aug 2008) | 2 lines
Fix oversight.
........
r65374 | benjamin.peterson | 2008-08-01 19:36:32 +0000 (Fri, 01 Aug 2008) | 1 line
fix one broken test
........
r65375 | georg.brandl | 2008-08-01 19:41:11 +0000 (Fri, 01 Aug 2008) | 2 lines
Fix the handling of non-ASCII input in quickstart.
........
r65377 | georg.brandl | 2008-08-01 19:48:24 +0000 (Fri, 01 Aug 2008) | 2 lines
Allow REs in markup checks.
........
r65380 | georg.brandl | 2008-08-01 20:31:18 +0000 (Fri, 01 Aug 2008) | 2 lines
Don't rely on mtimes being different for changed files.
........
r65483 | georg.brandl | 2008-08-04 09:01:40 +0000 (Mon, 04 Aug 2008) | 4 lines
Add an "encoding" option to literalinclude.
Add tests for include directives.
........
r65484 | georg.brandl | 2008-08-04 09:11:17 +0000 (Mon, 04 Aug 2008) | 2 lines
Add changelog entry.
........
r65485 | georg.brandl | 2008-08-04 09:21:58 +0000 (Mon, 04 Aug 2008) | 2 lines
Fix markup.
........
r65494 | georg.brandl | 2008-08-04 16:34:59 +0000 (Mon, 04 Aug 2008) | 2 lines
Correctly use HTML file suffix in templates.
........
2008-08-04 12:01:15 -05:00
|
|
|
|
2018-02-19 07:39:14 -06:00
|
|
|
import sys
|
|
|
|
from textwrap import dedent
|
2019-03-07 08:35:36 -06:00
|
|
|
from unittest import mock
|
2018-02-19 07:39:14 -06:00
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
import pytest
|
2018-02-19 07:39:14 -06:00
|
|
|
from docutils import nodes
|
2009-09-08 05:07:27 -05:00
|
|
|
|
2018-02-19 07:39:14 -06:00
|
|
|
from sphinx.errors import SphinxError
|
Merged revisions 65283,65303,65316-65317,65372-65375,65377,65380,65483-65485,65494 via svnmerge from
svn+ssh://pythondev@svn.python.org/doctools/branches/0.4.x
........
r65283 | georg.brandl | 2008-07-29 10:07:26 +0000 (Tue, 29 Jul 2008) | 2 lines
Update ez_setup.py.
........
r65303 | benjamin.peterson | 2008-07-30 12:35:34 +0000 (Wed, 30 Jul 2008) | 1 line
add a with_testapp decorator for test functions that passes the TestApp instance in a cleans up after it
........
r65316 | benjamin.peterson | 2008-07-30 23:12:07 +0000 (Wed, 30 Jul 2008) | 1 line
make the app for test_markup global to the module
........
r65317 | benjamin.peterson | 2008-07-30 23:31:29 +0000 (Wed, 30 Jul 2008) | 1 line
make TestApp.cleanup more aggressive
........
r65372 | georg.brandl | 2008-08-01 19:11:22 +0000 (Fri, 01 Aug 2008) | 2 lines
Add more tests, fix a few bugs in image handling.
........
r65373 | georg.brandl | 2008-08-01 19:28:33 +0000 (Fri, 01 Aug 2008) | 2 lines
Fix oversight.
........
r65374 | benjamin.peterson | 2008-08-01 19:36:32 +0000 (Fri, 01 Aug 2008) | 1 line
fix one broken test
........
r65375 | georg.brandl | 2008-08-01 19:41:11 +0000 (Fri, 01 Aug 2008) | 2 lines
Fix the handling of non-ASCII input in quickstart.
........
r65377 | georg.brandl | 2008-08-01 19:48:24 +0000 (Fri, 01 Aug 2008) | 2 lines
Allow REs in markup checks.
........
r65380 | georg.brandl | 2008-08-01 20:31:18 +0000 (Fri, 01 Aug 2008) | 2 lines
Don't rely on mtimes being different for changed files.
........
r65483 | georg.brandl | 2008-08-04 09:01:40 +0000 (Mon, 04 Aug 2008) | 4 lines
Add an "encoding" option to literalinclude.
Add tests for include directives.
........
r65484 | georg.brandl | 2008-08-04 09:11:17 +0000 (Mon, 04 Aug 2008) | 2 lines
Add changelog entry.
........
r65485 | georg.brandl | 2008-08-04 09:21:58 +0000 (Mon, 04 Aug 2008) | 2 lines
Fix markup.
........
r65494 | georg.brandl | 2008-08-04 16:34:59 +0000 (Mon, 04 Aug 2008) | 2 lines
Correctly use HTML file suffix in templates.
........
2008-08-04 12:01:15 -05:00
|
|
|
|
2008-08-04 16:48:12 -05:00
|
|
|
|
2016-09-10 02:49:17 -05:00
|
|
|
def request_session_head(url, **kwargs):
|
|
|
|
response = mock.Mock()
|
|
|
|
response.status_code = 200
|
|
|
|
response.url = url
|
|
|
|
return response
|
2009-12-28 10:09:09 -06:00
|
|
|
|
2010-01-17 09:48:02 -06:00
|
|
|
|
2017-01-06 09:46:26 -06:00
|
|
|
@pytest.fixture
|
2017-05-07 02:46:44 -05:00
|
|
|
def nonascii_srcdir(request, rootdir, sphinx_test_tempdir):
|
2014-09-21 10:17:02 -05:00
|
|
|
# If supported, build in a non-ASCII source dir
|
2018-12-15 08:02:28 -06:00
|
|
|
test_name = '\u65e5\u672c\u8a9e'
|
2017-05-07 02:46:44 -05:00
|
|
|
basedir = sphinx_test_tempdir / request.node.originalname
|
2014-09-21 10:17:02 -05:00
|
|
|
try:
|
2017-01-06 09:46:26 -06:00
|
|
|
srcdir = basedir / test_name
|
|
|
|
if not srcdir.exists():
|
2017-05-07 02:46:44 -05:00
|
|
|
(rootdir / 'test-root').copytree(srcdir)
|
2014-09-21 10:17:02 -05:00
|
|
|
except UnicodeEncodeError:
|
2020-12-19 10:01:56 -06:00
|
|
|
# Now Python 3.7+ follows PEP-540 and uses utf-8 encoding for filesystem by default.
|
|
|
|
# So this error handling will be no longer used (after dropping python 3.6 support).
|
2017-01-06 09:46:26 -06:00
|
|
|
srcdir = basedir / 'all'
|
2020-11-30 15:11:19 -06:00
|
|
|
if not srcdir.exists():
|
|
|
|
(rootdir / 'test-root').copytree(srcdir)
|
2014-09-21 10:17:02 -05:00
|
|
|
else:
|
|
|
|
# add a doc with a non-ASCII file name to the source dir
|
|
|
|
(srcdir / (test_name + '.txt')).write_text(dedent("""
|
|
|
|
nonascii file name page
|
|
|
|
=======================
|
|
|
|
"""))
|
|
|
|
|
2020-11-24 09:50:36 -06:00
|
|
|
root_doc = srcdir / 'index.txt'
|
|
|
|
root_doc.write_text(root_doc.read_text() + dedent("""
|
|
|
|
.. toctree::
|
2014-09-21 10:17:02 -05:00
|
|
|
|
2020-11-24 09:50:36 -06:00
|
|
|
%(test_name)s/%(test_name)s
|
|
|
|
""" % {'test_name': test_name}))
|
2017-01-06 09:46:26 -06:00
|
|
|
return srcdir
|
2014-09-21 10:17:02 -05:00
|
|
|
|
2016-09-10 02:49:17 -05:00
|
|
|
|
2017-12-15 06:14:20 -06:00
|
|
|
# note: this test skips building docs for some builders because they have independent testcase.
|
2019-03-04 09:58:12 -06:00
|
|
|
# (html, changes, epub, latex, texinfo and manpage)
|
2017-01-06 09:46:26 -06:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"buildername",
|
2019-03-09 03:12:33 -06:00
|
|
|
['dirhtml', 'singlehtml', 'text', 'xml', 'pseudoxml', 'linkcheck'],
|
2017-01-06 09:46:26 -06:00
|
|
|
)
|
|
|
|
@mock.patch('sphinx.builders.linkcheck.requests.head',
|
|
|
|
side_effect=request_session_head)
|
2017-06-14 16:36:52 -05:00
|
|
|
@pytest.mark.xfail(sys.platform == 'win32', reason="Not working on windows")
|
2017-01-06 09:46:26 -06:00
|
|
|
def test_build_all(requests_head, make_app, nonascii_srcdir, buildername):
|
|
|
|
app = make_app(buildername, srcdir=nonascii_srcdir)
|
|
|
|
app.build()
|
|
|
|
|
|
|
|
|
2020-11-24 09:50:36 -06:00
|
|
|
def test_root_doc_not_found(tempdir, make_app):
|
2019-01-02 07:20:22 -06:00
|
|
|
(tempdir / 'conf.py').write_text('')
|
2017-01-03 07:24:00 -06:00
|
|
|
assert tempdir.listdir() == ['conf.py']
|
2016-07-13 11:10:57 -05:00
|
|
|
|
2017-01-06 09:46:26 -06:00
|
|
|
app = make_app('dummy', srcdir=tempdir)
|
|
|
|
with pytest.raises(SphinxError):
|
2019-01-02 07:20:22 -06:00
|
|
|
app.builder.build_all() # no index.rst
|
2016-01-03 05:26:38 -06:00
|
|
|
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx(buildername='text', testroot='circular')
|
2014-09-21 10:17:02 -05:00
|
|
|
def test_circular_toctree(app, status, warning):
|
2014-08-18 20:44:09 -05:00
|
|
|
app.builder.build_all()
|
2014-09-21 10:17:02 -05:00
|
|
|
warnings = warning.getvalue()
|
2014-10-09 09:53:33 -05:00
|
|
|
assert (
|
|
|
|
'circular toctree references detected, ignoring: '
|
2018-09-03 07:38:31 -05:00
|
|
|
'sub <- index <- sub') in warnings
|
2014-10-09 09:53:33 -05:00
|
|
|
assert (
|
|
|
|
'circular toctree references detected, ignoring: '
|
2018-09-03 07:38:31 -05:00
|
|
|
'index <- sub <- index') in warnings
|
2014-08-18 20:44:09 -05:00
|
|
|
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx(buildername='text', testroot='numbered-circular')
|
2014-09-21 10:17:02 -05:00
|
|
|
def test_numbered_circular_toctree(app, status, warning):
|
2014-08-18 20:44:09 -05:00
|
|
|
app.builder.build_all()
|
2014-09-21 10:17:02 -05:00
|
|
|
warnings = warning.getvalue()
|
2014-10-09 09:53:33 -05:00
|
|
|
assert (
|
|
|
|
'circular toctree references detected, ignoring: '
|
2018-09-03 07:38:31 -05:00
|
|
|
'sub <- index <- sub') in warnings
|
2014-10-09 09:53:33 -05:00
|
|
|
assert (
|
|
|
|
'circular toctree references detected, ignoring: '
|
2018-09-03 07:38:31 -05:00
|
|
|
'index <- sub <- index') in warnings
|
2016-01-26 10:27:05 -06:00
|
|
|
|
|
|
|
|
2017-03-27 09:46:10 -05:00
|
|
|
@pytest.mark.sphinx(buildername='dummy', testroot='images')
|
2016-01-26 10:27:05 -06:00
|
|
|
def test_image_glob(app, status, warning):
|
|
|
|
app.builder.build_all()
|
|
|
|
|
|
|
|
# index.rst
|
2019-02-17 04:52:08 -06:00
|
|
|
doctree = app.env.get_doctree('index')
|
2016-01-26 10:27:05 -06:00
|
|
|
|
|
|
|
assert isinstance(doctree[0][1], nodes.image)
|
|
|
|
assert doctree[0][1]['candidates'] == {'*': 'rimg.png'}
|
|
|
|
assert doctree[0][1]['uri'] == 'rimg.png'
|
|
|
|
|
|
|
|
assert isinstance(doctree[0][2], nodes.figure)
|
|
|
|
assert isinstance(doctree[0][2][0], nodes.image)
|
|
|
|
assert doctree[0][2][0]['candidates'] == {'*': 'rimg.png'}
|
|
|
|
assert doctree[0][2][0]['uri'] == 'rimg.png'
|
|
|
|
|
|
|
|
assert isinstance(doctree[0][3], nodes.image)
|
|
|
|
assert doctree[0][3]['candidates'] == {'application/pdf': 'img.pdf',
|
|
|
|
'image/gif': 'img.gif',
|
|
|
|
'image/png': 'img.png'}
|
|
|
|
assert doctree[0][3]['uri'] == 'img.*'
|
|
|
|
|
|
|
|
assert isinstance(doctree[0][4], nodes.figure)
|
|
|
|
assert isinstance(doctree[0][4][0], nodes.image)
|
|
|
|
assert doctree[0][4][0]['candidates'] == {'application/pdf': 'img.pdf',
|
|
|
|
'image/gif': 'img.gif',
|
|
|
|
'image/png': 'img.png'}
|
|
|
|
assert doctree[0][4][0]['uri'] == 'img.*'
|
|
|
|
|
|
|
|
# subdir/index.rst
|
2019-02-17 04:52:08 -06:00
|
|
|
doctree = app.env.get_doctree('subdir/index')
|
2016-01-26 10:27:05 -06:00
|
|
|
|
|
|
|
assert isinstance(doctree[0][1], nodes.image)
|
2021-03-06 09:30:43 -06:00
|
|
|
assert doctree[0][1]['candidates'] == {'*': 'subdir/rimg.png'}
|
|
|
|
assert doctree[0][1]['uri'] == 'subdir/rimg.png'
|
2016-01-26 10:36:43 -06:00
|
|
|
|
|
|
|
assert isinstance(doctree[0][2], nodes.image)
|
|
|
|
assert doctree[0][2]['candidates'] == {'application/pdf': 'subdir/svgimg.pdf',
|
2016-01-26 10:27:05 -06:00
|
|
|
'image/svg+xml': 'subdir/svgimg.svg'}
|
2021-03-06 09:30:43 -06:00
|
|
|
assert doctree[0][2]['uri'] == 'subdir/svgimg.*'
|
2016-01-26 10:27:05 -06:00
|
|
|
|
2016-01-26 10:36:43 -06:00
|
|
|
assert isinstance(doctree[0][3], nodes.figure)
|
|
|
|
assert isinstance(doctree[0][3][0], nodes.image)
|
|
|
|
assert doctree[0][3][0]['candidates'] == {'application/pdf': 'subdir/svgimg.pdf',
|
2016-01-26 10:27:05 -06:00
|
|
|
'image/svg+xml': 'subdir/svgimg.svg'}
|
2021-03-06 09:30:43 -06:00
|
|
|
assert doctree[0][3][0]['uri'] == 'subdir/svgimg.*'
|