sphinx/tests/test_util_pycompat.py
Jon Dufresne bade33c7e4 Remove unnecessary encoding cookie from Python source files
In Python 3, the default encoding of source files is utf-8. The encoding
cookie is now unnecessary and redundant so remove it. For more details,
see the docs:

https://docs.python.org/3/howto/unicode.html#the-string-type

> The default encoding for Python source code is UTF-8, so you can
> simply include a Unicode character in a string literal ...

Includes a fix for the flake8 header checks to stop expecting an
encoding cookie.
2018-12-16 12:22:12 -08:00

43 lines
1.1 KiB
Python

"""
test_util_pycompat
~~~~~~~~~~~~~~~~~~
Tests sphinx.util.pycompat functions.
:copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import tempfile
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):
logging.setup(app, status, warning)
ns = {}
with tempfile.NamedTemporaryFile() as tmp:
tmp.write(b'print "hello"\n')
tmp.flush()
execfile_(tmp.name, ns)
msg = (
'Support for evaluating Python 2 syntax is deprecated '
'and will be removed in Sphinx 4.0. '
'Convert %s to Python 3 syntax.\n' % tmp.name)
assert msg in strip_escseq(warning.getvalue())
captured = capsys.readouterr()
assert captured.out == 'hello\n'
def test_execfile(capsys):
ns = {}
with tempfile.NamedTemporaryFile() as tmp:
tmp.write(b'print("hello")\n')
tmp.flush()
execfile_(tmp.name, ns)
captured = capsys.readouterr()
assert captured.out == 'hello\n'