sphinx/tests/test_util_pycompat.py
Takeshi KOMIYA f996859420 A happy new year!
.. note::

   $ find sphinx tests LICENSE doc/conf.py -type f -exec sed -i '' -e 's/2007\-20../2007-2021/' {} \;
   $ git co sphinx/locale/**/*.js sphinx/templates/epub3/mimetype
2021-01-01 13:40:48 +09:00

39 lines
1.0 KiB
Python

"""
test_util_pycompat
~~~~~~~~~~~~~~~~~~
Tests sphinx.util.pycompat functions.
:copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
from sphinx.testing.util import strip_escseq
from sphinx.util import logging
from sphinx.util.pycompat import execfile_
def test_execfile_python2(capsys, app, status, warning, tempdir):
logging.setup(app, status, warning)
conf_py = tempdir / 'conf.py'
conf_py.write_bytes(b'print "hello"\n')
execfile_(conf_py, {})
msg = (
'Support for evaluating Python 2 syntax is deprecated '
'and will be removed in Sphinx 4.0. '
'Convert %s to Python 3 syntax.\n' % conf_py)
assert msg in strip_escseq(warning.getvalue())
captured = capsys.readouterr()
assert captured.out == 'hello\n'
def test_execfile(capsys, tempdir):
conf_py = tempdir / 'conf.py'
conf_py.write_bytes(b'print("hello")\n')
execfile_(conf_py, {})
captured = capsys.readouterr()
assert captured.out == 'hello\n'