2013-09-18 03:51:20 -05:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
test_setup_command
|
|
|
|
~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Test setup_command for distutils.
|
|
|
|
|
2017-12-31 10:06:58 -06:00
|
|
|
:copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS.
|
2013-09-18 03:51:20 -05:00
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import subprocess
|
2018-02-19 07:39:14 -06:00
|
|
|
import sys
|
2017-01-03 07:24:00 -06:00
|
|
|
from collections import namedtuple
|
2018-02-19 07:39:14 -06:00
|
|
|
from textwrap import dedent
|
2013-09-18 03:51:20 -05:00
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
import pytest
|
|
|
|
|
2018-02-19 07:39:14 -06:00
|
|
|
import sphinx
|
2017-01-03 07:24:00 -06:00
|
|
|
from sphinx.util.osutil import cd
|
2013-09-18 03:51:20 -05:00
|
|
|
|
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
@pytest.fixture
|
2017-05-07 02:46:44 -05:00
|
|
|
def setup_command(request, tempdir, rootdir):
|
2013-09-18 03:51:20 -05:00
|
|
|
"""
|
|
|
|
Run `setup.py build_sphinx` with args and kwargs,
|
|
|
|
pass it to the test and clean up properly.
|
|
|
|
"""
|
2018-06-01 00:39:43 -05:00
|
|
|
if hasattr(request.node, 'get_closest_marker'): # pytest-3.6.0 or newer
|
|
|
|
marker = request.node.get_closest_marker('setup_command')
|
|
|
|
else:
|
|
|
|
marker = request.node.get_marker('setup_command')
|
2017-01-03 07:24:00 -06:00
|
|
|
args = marker.args if marker else []
|
|
|
|
|
2017-05-07 02:46:44 -05:00
|
|
|
pkgrootdir = tempdir / 'test-setup'
|
|
|
|
(rootdir / 'test-setup').copytree(pkgrootdir)
|
2017-01-03 07:24:00 -06:00
|
|
|
|
|
|
|
with cd(pkgrootdir):
|
|
|
|
pythonpath = os.path.dirname(os.path.dirname(sphinx.__file__))
|
|
|
|
if os.getenv('PYTHONPATH'):
|
|
|
|
pythonpath = os.getenv('PYTHONPATH') + os.pathsep + pythonpath
|
|
|
|
command = [sys.executable, 'setup.py', 'build_sphinx']
|
|
|
|
command.extend(args)
|
|
|
|
|
|
|
|
proc = subprocess.Popen(
|
|
|
|
command,
|
|
|
|
env=dict(os.environ, PYTHONPATH=pythonpath),
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE)
|
|
|
|
yield namedtuple('setup', 'pkgroot,proc')(pkgrootdir, proc)
|
|
|
|
|
|
|
|
|
|
|
|
def test_build_sphinx(setup_command):
|
|
|
|
proc = setup_command.proc
|
2013-09-18 03:51:20 -05:00
|
|
|
out, err = proc.communicate()
|
2018-11-12 13:21:22 -06:00
|
|
|
print(out.decode())
|
|
|
|
print(err.decode())
|
2013-09-18 03:51:20 -05:00
|
|
|
assert proc.returncode == 0
|
|
|
|
|
|
|
|
|
2017-02-27 08:57:34 -06:00
|
|
|
@pytest.mark.setup_command('-b', 'html,man')
|
|
|
|
def test_build_sphinx_multiple_builders(setup_command):
|
|
|
|
proc = setup_command.proc
|
|
|
|
out, err = proc.communicate()
|
2018-11-12 13:21:22 -06:00
|
|
|
print(out.decode())
|
|
|
|
print(err.decode())
|
2017-02-27 08:57:34 -06:00
|
|
|
assert proc.returncode == 0
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.setup_command('-b', 'html,bar')
|
|
|
|
def test_build_sphinx_multiple_invalid_builders(setup_command):
|
|
|
|
proc = setup_command.proc
|
|
|
|
out, err = proc.communicate()
|
2018-11-12 13:21:22 -06:00
|
|
|
print(out.decode())
|
|
|
|
print(err.decode())
|
2017-02-27 08:57:34 -06:00
|
|
|
assert proc.returncode == 1
|
|
|
|
|
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
@pytest.fixture
|
|
|
|
def nonascii_srcdir(request, setup_command):
|
2013-09-18 03:51:20 -05:00
|
|
|
mb_name = u'\u65e5\u672c\u8a9e'
|
2017-01-03 07:24:00 -06:00
|
|
|
srcdir = (setup_command.pkgroot / 'doc')
|
2013-09-28 07:51:20 -05:00
|
|
|
try:
|
|
|
|
(srcdir / mb_name).makedirs()
|
|
|
|
except UnicodeEncodeError:
|
2017-05-07 02:46:44 -05:00
|
|
|
from sphinx.testing.path import FILESYSTEMENCODING
|
2017-01-03 07:24:00 -06:00
|
|
|
pytest.skip(
|
2013-10-03 01:43:22 -05:00
|
|
|
'non-ASCII filename not supported on this filesystem encoding: '
|
2017-01-03 07:24:00 -06:00
|
|
|
'%s' % FILESYSTEMENCODING)
|
2013-09-28 07:51:20 -05:00
|
|
|
|
2013-09-18 03:51:20 -05:00
|
|
|
(srcdir / mb_name / (mb_name + '.txt')).write_text(dedent("""
|
|
|
|
multi byte file name page
|
|
|
|
==========================
|
|
|
|
"""))
|
|
|
|
|
2018-09-03 07:38:31 -05:00
|
|
|
master_doc = srcdir / 'index.txt'
|
2013-09-18 03:51:20 -05:00
|
|
|
master_doc.write_bytes((master_doc.text() + dedent("""
|
2017-01-25 10:13:17 -06:00
|
|
|
.. toctree::
|
2013-09-18 03:51:20 -05:00
|
|
|
|
2017-01-25 10:13:17 -06:00
|
|
|
%(mb_name)s/%(mb_name)s
|
2018-12-15 17:43:44 -06:00
|
|
|
""" % locals())).encode())
|
2017-01-03 07:24:00 -06:00
|
|
|
|
2013-09-18 03:51:20 -05:00
|
|
|
|
2017-01-05 09:26:31 -06:00
|
|
|
@pytest.mark.usefixtures('nonascii_srcdir')
|
|
|
|
def test_build_sphinx_with_nonascii_path(setup_command):
|
2017-01-03 07:24:00 -06:00
|
|
|
proc = setup_command.proc
|
2013-09-18 03:51:20 -05:00
|
|
|
out, err = proc.communicate()
|
2018-11-12 13:21:22 -06:00
|
|
|
print(out.decode())
|
|
|
|
print(err.decode())
|
2013-09-18 03:51:20 -05:00
|
|
|
assert proc.returncode == 0
|
2014-08-28 11:14:54 -05:00
|
|
|
|
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
@pytest.mark.setup_command('-b', 'linkcheck')
|
|
|
|
def test_build_sphinx_return_nonzero_status(setup_command):
|
|
|
|
srcdir = (setup_command.pkgroot / 'doc')
|
2014-08-28 11:14:54 -05:00
|
|
|
(srcdir / 'contents.txt').write_text(
|
|
|
|
'http://localhost.unexistentdomain/index.html')
|
2017-01-03 07:24:00 -06:00
|
|
|
proc = setup_command.proc
|
2014-08-28 11:14:54 -05:00
|
|
|
out, err = proc.communicate()
|
2018-11-12 13:21:22 -06:00
|
|
|
print(out.decode())
|
|
|
|
print(err.decode())
|
2014-08-28 11:14:54 -05:00
|
|
|
assert proc.returncode != 0, 'expect non-zero status for setup.py'
|
2016-06-10 02:45:22 -05:00
|
|
|
|
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
def test_build_sphinx_warning_return_zero_status(setup_command):
|
|
|
|
srcdir = (setup_command.pkgroot / 'doc')
|
2016-06-10 02:45:22 -05:00
|
|
|
(srcdir / 'contents.txt').write_text(
|
|
|
|
'See :ref:`unexisting-reference-label`')
|
2017-01-03 07:24:00 -06:00
|
|
|
proc = setup_command.proc
|
2016-06-10 02:45:22 -05:00
|
|
|
out, err = proc.communicate()
|
2018-11-12 13:21:22 -06:00
|
|
|
print(out.decode())
|
|
|
|
print(err.decode())
|
2016-06-10 02:45:22 -05:00
|
|
|
assert proc.returncode == 0
|
|
|
|
|
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
@pytest.mark.setup_command('--warning-is-error')
|
|
|
|
def test_build_sphinx_warning_is_error_return_nonzero_status(setup_command):
|
|
|
|
srcdir = (setup_command.pkgroot / 'doc')
|
2016-06-10 02:45:22 -05:00
|
|
|
(srcdir / 'contents.txt').write_text(
|
|
|
|
'See :ref:`unexisting-reference-label`')
|
2017-01-03 07:24:00 -06:00
|
|
|
proc = setup_command.proc
|
2016-06-10 02:45:22 -05:00
|
|
|
out, err = proc.communicate()
|
2018-11-12 13:21:22 -06:00
|
|
|
print(out.decode())
|
|
|
|
print(err.decode())
|
2016-06-10 02:45:22 -05:00
|
|
|
assert proc.returncode != 0, 'expect non-zero status for setup.py'
|