summaryrefslogtreecommitdiff
path: root/tests/test_util_pycompat.py
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2018-11-21 19:15:27 -0800
committerJon Dufresne <jon.dufresne@gmail.com>2018-11-22 19:05:14 -0800
commitd99e2cae1981940437f073dc07f1420efa2c0bea (patch)
treee4c572d660e30b2351817ea2c52a4a8a7d134520 /tests/test_util_pycompat.py
parent318cfadfe0a3aa242ad250f6e3a2af8f8791cb5b (diff)
downloadsphinx-git-d99e2cae1981940437f073dc07f1420efa2c0bea.tar.gz
Deprecate evaluating Python 2 syntax in configuration files
Diffstat (limited to 'tests/test_util_pycompat.py')
-rw-r--r--tests/test_util_pycompat.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/test_util_pycompat.py b/tests/test_util_pycompat.py
new file mode 100644
index 000000000..333664975
--- /dev/null
+++ b/tests/test_util_pycompat.py
@@ -0,0 +1,43 @@
+# -*- coding: utf-8 -*-
+"""
+ 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'