aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_cmd_line.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-12-23 19:16:56 +0100
committerGitHub <noreply@github.com>2020-12-23 19:16:56 +0100
commita12491681f08a33abcca843f5150330740c91111 (patch)
tree0548d800982a420ed2804834b827c443cdcf5d05 /Lib/test/test_cmd_line.py
parent41b223d29cdfeb1f222c12c3abaccc3bc128f5e7 (diff)
downloadcpython-a12491681f08a33abcca843f5150330740c91111.tar.gz
cpython-a12491681f08a33abcca843f5150330740c91111.zip
bpo-32381: pymain_run_command() uses PyCF_IGNORE_COOKIE (GH-23724)
The coding cookie (ex: "# coding: latin1") is now ignored in the command passed to the -c command line option. Since pymain_run_command() uses UTF-8, pass PyCF_IGNORE_COOKIE compiler flag to the parser. pymain_run_python() no longer propages compiler flags between function calls.
Diffstat (limited to 'Lib/test/test_cmd_line.py')
-rw-r--r--Lib/test/test_cmd_line.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py
index fa3329efa28..f12dff3202f 100644
--- a/Lib/test/test_cmd_line.py
+++ b/Lib/test/test_cmd_line.py
@@ -153,6 +153,14 @@ class CmdLineTest(unittest.TestCase):
% (os_helper.FS_NONASCII, ord(os_helper.FS_NONASCII)))
assert_python_ok('-c', command)
+ @unittest.skipUnless(os_helper.FS_NONASCII, 'need os_helper.FS_NONASCII')
+ def test_coding(self):
+ # bpo-32381: the -c command ignores the coding cookie
+ ch = os_helper.FS_NONASCII
+ cmd = f"# coding: latin1\nprint(ascii('{ch}'))"
+ res = assert_python_ok('-c', cmd)
+ self.assertEqual(res.out.rstrip(), ascii(ch).encode('ascii'))
+
# On Windows, pass bytes to subprocess doesn't test how Python decodes the
# command line, but how subprocess does decode bytes to unicode. Python
# doesn't decode the command line because Windows provides directly the