diff options
author | shimizukawa <shimizukawa@gmail.com> | 2017-01-03 22:24:00 +0900 |
---|---|---|
committer | shimizukawa <shimizukawa@gmail.com> | 2017-01-04 00:59:30 +0900 |
commit | 5b7d237db380a75c27137fb37f0396f4a3dc3ecd (patch) | |
tree | f309a2fd9356e185d55b4937afb515c394066f35 /tests/test_setup_command.py | |
parent | 54c8c012228559c3bf30011977984a60a9299e9b (diff) | |
download | sphinx-git-5b7d237db380a75c27137fb37f0396f4a3dc3ecd.tar.gz |
pytest migration
Diffstat (limited to 'tests/test_setup_command.py')
-rw-r--r-- | tests/test_setup_command.py | 99 |
1 files changed, 50 insertions, 49 deletions
diff --git a/tests/test_setup_command.py b/tests/test_setup_command.py index c92f6220f..c7874eb25 100644 --- a/tests/test_setup_command.py +++ b/tests/test_setup_command.py @@ -12,12 +12,13 @@ import os import sys import subprocess -from functools import wraps -import tempfile +from collections import namedtuple import sphinx -from util import rootdir, tempdir, SkipTest -from path import path +import pytest + +from sphinx.util.osutil import cd +from util import rootdir, tempdir from textwrap import dedent root = tempdir / 'test-setup' @@ -28,57 +29,52 @@ def setup_module(): (rootdir / 'roots' / 'test-setup').copytree(root) -def with_setup_command(root, *args, **kwds): +@pytest.fixture +def setup_command(request, tempdir): """ Run `setup.py build_sphinx` with args and kwargs, pass it to the test and clean up properly. """ - def generator(func): - @wraps(func) - def deco(*args2, **kwargs2): - tempdir = path(tempfile.mkdtemp()) - pkgrootdir = (tempdir / 'root') - root.copytree(pkgrootdir) - cwd = os.getcwd() - os.chdir(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) - try: - proc = subprocess.Popen( - command, - env=dict(os.environ, PYTHONPATH=pythonpath), - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - func(pkgrootdir, proc) - finally: - tempdir.rmtree(ignore_errors=True) - os.chdir(cwd) - return deco - return generator - - -@with_setup_command(root) -def test_build_sphinx(pkgroot, proc): + marker = request.node.get_marker('setup_command') + args = marker.args if marker else [] + + pkgrootdir = tempdir / 'root' + root.copytree(pkgrootdir) + + 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 out, err = proc.communicate() print(out) print(err) assert proc.returncode == 0 -@with_setup_command(root) -def test_build_sphinx_with_nonascii_path(pkgroot, proc): +@pytest.fixture +def nonascii_srcdir(request, setup_command): mb_name = u'\u65e5\u672c\u8a9e' - srcdir = (pkgroot / 'doc') + srcdir = (setup_command.pkgroot / 'doc') try: (srcdir / mb_name).makedirs() except UnicodeEncodeError: from path import FILESYSTEMENCODING - raise SkipTest( + pytest.skip( 'non-ASCII filename not supported on this filesystem encoding: ' - '%s', FILESYSTEMENCODING) + '%s' % FILESYSTEMENCODING) (srcdir / mb_name / (mb_name + '.txt')).write_text(dedent(""" multi byte file name page @@ -91,41 +87,46 @@ def test_build_sphinx_with_nonascii_path(pkgroot, proc): %(mb_name)s/%(mb_name)s """ % locals()) - ).encode('utf-8')) + ).encode('utf-8')) + +def test_build_sphinx_with_nonascii_path(setup_command, nonascii_srcdir): + proc = setup_command.proc out, err = proc.communicate() print(out) print(err) assert proc.returncode == 0 -@with_setup_command(root, '-b', 'linkcheck') -def test_build_sphinx_return_nonzero_status(pkgroot, proc): - srcdir = (pkgroot / 'doc') +@pytest.mark.setup_command('-b', 'linkcheck') +def test_build_sphinx_return_nonzero_status(setup_command): + srcdir = (setup_command.pkgroot / 'doc') (srcdir / 'contents.txt').write_text( 'http://localhost.unexistentdomain/index.html') + proc = setup_command.proc out, err = proc.communicate() print(out) print(err) assert proc.returncode != 0, 'expect non-zero status for setup.py' -@with_setup_command(root) -def test_build_sphinx_warning_return_zero_status(pkgroot, proc): - srcdir = (pkgroot / 'doc') +def test_build_sphinx_warning_return_zero_status(setup_command): + srcdir = (setup_command.pkgroot / 'doc') (srcdir / 'contents.txt').write_text( 'See :ref:`unexisting-reference-label`') + proc = setup_command.proc out, err = proc.communicate() print(out) print(err) assert proc.returncode == 0 -@with_setup_command(root, '--warning-is-error') -def test_build_sphinx_warning_is_error_return_nonzero_status(pkgroot, proc): - srcdir = (pkgroot / 'doc') +@pytest.mark.setup_command('--warning-is-error') +def test_build_sphinx_warning_is_error_return_nonzero_status(setup_command): + srcdir = (setup_command.pkgroot / 'doc') (srcdir / 'contents.txt').write_text( 'See :ref:`unexisting-reference-label`') + proc = setup_command.proc out, err = proc.communicate() print(out) print(err) |