Remove deprecated testing utilities

This commit is contained in:
Takeshi KOMIYA 2017-04-27 23:38:42 +09:00
parent 8d5d70ba62
commit 8fda21099d
8 changed files with 18 additions and 187 deletions

View File

@ -14,19 +14,13 @@
:license: BSD, see LICENSE for details. :license: BSD, see LICENSE for details.
""" """
import os
import re
from itertools import cycle, chain
import xml.etree.cElementTree as ElementTree import xml.etree.cElementTree as ElementTree
from six import PY3
import pytest import pytest
from html5lib import getTreeBuilder, HTMLParser from html5lib import getTreeBuilder, HTMLParser
from sphinx import __display_version__
from sphinx.util.docutils import is_html5_writer_available from sphinx.util.docutils import is_html5_writer_available
from util import remove_unicode_literals, strip_escseq, skip_unless
from test_build_html import flat_dict, tail_check, check_xpath from test_build_html import flat_dict, tail_check, check_xpath
TREE_BUILDER = getTreeBuilder('etree', implementation=ElementTree) TREE_BUILDER = getTreeBuilder('etree', implementation=ElementTree)
@ -35,7 +29,8 @@ HTML_PARSER = HTMLParser(TREE_BUILDER, namespaceHTMLElements=False)
etree_cache = {} etree_cache = {}
@skip_unless(is_html5_writer_available())
@pytest.mark.skipif(not is_html5_writer_available(), reason='HTML5 writer is not available')
@pytest.fixture(scope='module') @pytest.fixture(scope='module')
def cached_etree_parse(): def cached_etree_parse():
def parse(fname): def parse(fname):
@ -50,7 +45,7 @@ def cached_etree_parse():
etree_cache.clear() etree_cache.clear()
@skip_unless(is_html5_writer_available()) @pytest.mark.skipif(not is_html5_writer_available(), reason='HTML5 writer is not available')
@pytest.mark.parametrize("fname,expect", flat_dict({ @pytest.mark.parametrize("fname,expect", flat_dict({
'images.html': [ 'images.html': [
(".//img[@src='_images/img.png']", ''), (".//img[@src='_images/img.png']", ''),

View File

@ -24,7 +24,7 @@ from sphinx.util.osutil import cd, ensuredir
from sphinx.util import docutils from sphinx.util import docutils
from sphinx.writers.latex import LaTeXTranslator from sphinx.writers.latex import LaTeXTranslator
from util import SkipTest, remove_unicode_literals, strip_escseq, skip_if from util import remove_unicode_literals, strip_escseq
from test_build_html import ENV_WARNINGS from test_build_html import ENV_WARNINGS
@ -77,7 +77,7 @@ def compile_latex_document(app):
'SphinxTests.tex'], 'SphinxTests.tex'],
stdout=PIPE, stderr=PIPE) stdout=PIPE, stderr=PIPE)
except OSError: # most likely the latex executable was not found except OSError: # most likely the latex executable was not found
raise SkipTest raise pytest.skip.Exception
else: else:
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
if p.returncode != 0: if p.returncode != 0:
@ -90,7 +90,7 @@ def compile_latex_document(app):
def skip_if_requested(testfunc): def skip_if_requested(testfunc):
if 'SKIP_LATEX_BUILD' in os.environ: if 'SKIP_LATEX_BUILD' in os.environ:
msg = 'Skip LaTeX builds because SKIP_LATEX_BUILD is set' msg = 'Skip LaTeX builds because SKIP_LATEX_BUILD is set'
return skip_if(True, msg)(testfunc) return pytest.mark.skipif(True, reason=msg)(testfunc)
else: else:
return testfunc return testfunc
@ -98,7 +98,7 @@ def skip_if_requested(testfunc):
def skip_if_stylefiles_notfound(testfunc): def skip_if_stylefiles_notfound(testfunc):
if kpsetest(*STYLEFILES) is False: if kpsetest(*STYLEFILES) is False:
msg = 'not running latex, the required styles do not seem to be installed' msg = 'not running latex, the required styles do not seem to be installed'
return skip_if(True, msg)(testfunc) return pytest.mark.skipif(True, reason=msg)(testfunc)
else: else:
return testfunc return testfunc

View File

@ -19,7 +19,7 @@ import pytest
from sphinx.writers.texinfo import TexinfoTranslator from sphinx.writers.texinfo import TexinfoTranslator
from util import SkipTest, remove_unicode_literals, strip_escseq from util import remove_unicode_literals, strip_escseq
from test_build_html import ENV_WARNINGS from test_build_html import ENV_WARNINGS
@ -58,7 +58,7 @@ def test_texinfo(app, status, warning):
p = Popen(['makeinfo', '--no-split', 'SphinxTests.texi'], p = Popen(['makeinfo', '--no-split', 'SphinxTests.texi'],
stdout=PIPE, stderr=PIPE) stdout=PIPE, stderr=PIPE)
except OSError: except OSError:
raise SkipTest # most likely makeinfo was not found raise pytest.skip.Exception # most likely makeinfo was not found
else: else:
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
retcode = p.returncode retcode = p.returncode

View File

@ -8,12 +8,11 @@
:copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS. :copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details. :license: BSD, see LICENSE for details.
""" """
import pytest
from docutils.utils import column_width from docutils.utils import column_width
from sphinx.writers.text import MAXWIDTH from sphinx.writers.text import MAXWIDTH
from util import with_app
def with_text_app(*args, **kw): def with_text_app(*args, **kw):
default_kw = { default_kw = {
@ -21,7 +20,7 @@ def with_text_app(*args, **kw):
'testroot': 'build-text', 'testroot': 'build-text',
} }
default_kw.update(kw) default_kw.update(kw)
return with_app(*args, **default_kw) return pytest.mark.sphinx(*args, **default_kw)
@with_text_app() @with_text_app()

View File

@ -12,7 +12,7 @@
import re import re
import pytest import pytest
from util import path, SkipTest from util import path
def regex_count(expr, result): def regex_count(expr, result):
@ -78,7 +78,7 @@ def test_docutils_source_link_with_nonascii_file(app, status, warning):
(srcdir / (mb_name + '.txt')).write_text('') (srcdir / (mb_name + '.txt')).write_text('')
except UnicodeEncodeError: except UnicodeEncodeError:
from path import FILESYSTEMENCODING from path import FILESYSTEMENCODING
raise SkipTest( raise pytest.skip.Exception(
'nonascii filename not supported on this filesystem encoding: ' 'nonascii filename not supported on this filesystem encoding: '
'%s', FILESYSTEMENCODING) '%s', FILESYSTEMENCODING)

View File

@ -12,7 +12,6 @@
import re import re
import pytest import pytest
from util import SkipTest
@pytest.mark.sphinx( @pytest.mark.sphinx(
@ -40,9 +39,9 @@ def test_jsmath(app, status, warning):
def test_imgmath_png(app, status, warning): def test_imgmath_png(app, status, warning):
app.builder.build_all() app.builder.build_all()
if "LaTeX command 'latex' cannot be run" in warning.getvalue(): if "LaTeX command 'latex' cannot be run" in warning.getvalue():
raise SkipTest('LaTeX command "latex" is not available') raise pytest.skip.Exception('LaTeX command "latex" is not available')
if "dvipng command 'dvipng' cannot be run" in warning.getvalue(): if "dvipng command 'dvipng' cannot be run" in warning.getvalue():
raise SkipTest('dvipng command "dvipng" is not available') raise pytest.skip.Exception('dvipng command "dvipng" is not available')
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').text()
html = (r'<div class="math">\s*<p>\s*<img src="_images/math/\w+.png"' html = (r'<div class="math">\s*<p>\s*<img src="_images/math/\w+.png"'
@ -56,9 +55,9 @@ def test_imgmath_png(app, status, warning):
def test_imgmath_svg(app, status, warning): def test_imgmath_svg(app, status, warning):
app.builder.build_all() app.builder.build_all()
if "LaTeX command 'latex' cannot be run" in warning.getvalue(): if "LaTeX command 'latex' cannot be run" in warning.getvalue():
raise SkipTest('LaTeX command "latex" is not available') raise pytest.skip.Exception('LaTeX command "latex" is not available')
if "dvisvgm command 'dvisvgm' cannot be run" in warning.getvalue(): if "dvisvgm command 'dvisvgm' cannot be run" in warning.getvalue():
raise SkipTest('dvisvgm command "dvisvgm" is not available') raise pytest.skip.Exception('dvisvgm command "dvisvgm" is not available')
content = (app.outdir / 'index.html').text() content = (app.outdir / 'index.html').text()
html = (r'<div class="math">\s*<p>\s*<img src="_images/math/\w+.svg"' html = (r'<div class="math">\s*<p>\s*<img src="_images/math/\w+.svg"'

View File

@ -16,8 +16,6 @@ from six import PY2, text_type, StringIO
from six.moves import input from six.moves import input
import pytest import pytest
from util import SkipTest
from sphinx import application from sphinx import application
from sphinx import quickstart as qs from sphinx import quickstart as qs
from sphinx.util.console import nocolor, coloron from sphinx.util.console import nocolor, coloron
@ -121,7 +119,7 @@ def test_do_prompt_with_nonascii():
try: try:
qs.do_prompt(d, 'k1', 'Q1', default=u'\u65e5\u672c') qs.do_prompt(d, 'k1', 'Q1', default=u'\u65e5\u672c')
except UnicodeEncodeError: except UnicodeEncodeError:
raise SkipTest( raise pytest.skip.Exception(
'non-ASCII console input not supported on this encoding: %s', 'non-ASCII console input not supported on this encoding: %s',
qs.TERM_ENCODING) qs.TERM_ENCODING)
assert d['k1'] == u'\u30c9\u30a4\u30c4' assert d['k1'] == u'\u30c9\u30a4\u30c4'

View File

@ -11,11 +11,9 @@ import os
import re import re
import sys import sys
import warnings import warnings
from functools import wraps
from xml.etree import ElementTree from xml.etree import ElementTree
from six import string_types from six import string_types
from six import StringIO
import pytest import pytest
@ -26,7 +24,6 @@ from sphinx import application
from sphinx.builders.latex import LaTeXBuilder from sphinx.builders.latex import LaTeXBuilder
from sphinx.ext.autodoc import AutoDirective from sphinx.ext.autodoc import AutoDirective
from sphinx.pycode import ModuleAnalyzer from sphinx.pycode import ModuleAnalyzer
from sphinx.deprecation import RemovedInSphinx17Warning
from path import path from path import path
@ -201,160 +198,3 @@ def find_files(root, suffix=None):
def strip_escseq(text): def strip_escseq(text):
return re.sub('\x1b.*?m', '', text) return re.sub('\x1b.*?m', '', text)
# #############################################
# DEPRECATED implementations
def gen_with_app(*args, **kwargs):
"""
**DEPRECATED**: use pytest.mark.parametrize instead.
Decorate a test generator to pass a SphinxTestApp as the first argument to
the test generator when it's executed.
"""
def generator(func):
@wraps(func)
def deco(*args2, **kwargs2):
status, warning = StringIO(), StringIO()
kwargs['status'] = status
kwargs['warning'] = warning
app = SphinxTestApp(*args, **kwargs)
try:
for item in func(app, status, warning, *args2, **kwargs2):
yield item
finally:
app.cleanup()
return deco
return generator
def skip_if(condition, msg=None):
"""
**DEPRECATED**: use pytest.mark.skipif instead.
Decorator to skip test if condition is true.
"""
return pytest.mark.skipif(condition, reason=(msg or 'conditional skip'))
def skip_unless(condition, msg=None):
"""
**DEPRECATED**: use pytest.mark.skipif instead.
Decorator to skip test if condition is false.
"""
return pytest.mark.skipif(not condition, reason=(msg or 'conditional skip'))
def with_tempdir(func):
"""
**DEPRECATED**: use tempdir fixture instead.
"""
return func
def raises(exc, func, *args, **kwds):
"""
**DEPRECATED**: use pytest.raises instead.
Raise AssertionError if ``func(*args, **kwds)`` does not raise *exc*.
"""
with pytest.raises(exc):
func(*args, **kwds)
def raises_msg(exc, msg, func, *args, **kwds):
"""
**DEPRECATED**: use pytest.raises instead.
Raise AssertionError if ``func(*args, **kwds)`` does not raise *exc*,
and check if the message contains *msg*.
"""
with pytest.raises(exc) as excinfo:
func(*args, **kwds)
assert msg in str(excinfo.value)
def assert_true(v1, msg=''):
"""
**DEPRECATED**: use assert instead.
"""
assert v1, msg
def assert_equal(v1, v2, msg=''):
"""
**DEPRECATED**: use assert instead.
"""
assert v1 == v2, msg
def assert_in(x, thing, msg=''):
"""
**DEPRECATED**: use assert instead.
"""
if x not in thing:
assert False, msg or '%r is not in %r' % (x, thing)
def assert_not_in(x, thing, msg=''):
"""
**DEPRECATED**: use assert instead.
"""
if x in thing:
assert False, msg or '%r is in %r' % (x, thing)
class ListOutput(object):
"""
File-like object that collects written text in a list.
"""
def __init__(self, name):
self.name = name
self.content = []
def reset(self):
del self.content[:]
def write(self, text):
self.content.append(text)
# **DEPRECATED**: use pytest.skip instead.
SkipTest = pytest.skip.Exception
class _DeprecationWrapper(object):
def __init__(self, mod, deprecated):
self._mod = mod
self._deprecated = deprecated
def __getattr__(self, attr):
if attr in self._deprecated:
obj, instead = self._deprecated[attr]
warnings.warn("tests/util.py::%s is deprecated and will be "
"removed in Sphinx 1.7, please use %s instead."
% (attr, instead),
RemovedInSphinx17Warning, stacklevel=2)
return obj
return getattr(self._mod, attr)
sys.modules[__name__] = _DeprecationWrapper(sys.modules[__name__], dict( # type: ignore
with_app=(pytest.mark.sphinx, 'pytest.mark.sphinx'),
TestApp=(SphinxTestApp, 'SphinxTestApp'),
gen_with_app=(gen_with_app, 'pytest.mark.parametrize'),
skip_if=(skip_if, 'pytest.skipif'),
skip_unless=(skip_unless, 'pytest.skipif'),
with_tempdir=(with_tempdir, 'tmpdir pytest fixture'),
raises=(raises, 'pytest.raises'),
raises_msg=(raises_msg, 'pytest.raises'),
assert_true=(assert_true, 'assert'),
assert_equal=(assert_equal, 'assert'),
assert_in=(assert_in, 'assert'),
assert_not_in=(assert_not_in, 'assert'),
ListOutput=(ListOutput, 'StringIO'),
SkipTest=(SkipTest, 'pytest.skip'),
))