1"""
2    test_util_pycompat
3    ~~~~~~~~~~~~~~~~~~
4
5    Tests sphinx.util.pycompat functions.
6
7    :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS.
8    :license: BSD, see LICENSE for details.
9"""
10
11from sphinx.testing.util import strip_escseq
12from sphinx.util import logging
13from sphinx.util.pycompat import execfile_
14
15
16def test_execfile_python2(capsys, app, status, warning, tempdir):
17    logging.setup(app, status, warning)
18
19    conf_py = tempdir / 'conf.py'
20    conf_py.write_bytes(b'print "hello"\n')
21    execfile_(conf_py, {})
22
23    msg = (
24        'Support for evaluating Python 2 syntax is deprecated '
25        'and will be removed in Sphinx 4.0. '
26        'Convert %s to Python 3 syntax.\n' % conf_py)
27    assert msg in strip_escseq(warning.getvalue())
28    captured = capsys.readouterr()
29    assert captured.out == 'hello\n'
30
31
32def test_execfile(capsys, tempdir):
33    conf_py = tempdir / 'conf.py'
34    conf_py.write_bytes(b'print("hello")\n')
35    execfile_(conf_py, {})
36
37    captured = capsys.readouterr()
38    assert captured.out == 'hello\n'
39