diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2017-06-11 03:16:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-11 03:16:15 (GMT) |
commit | 6ea4186de32d65b1f1dc1533b6312b798d300466 (patch) | |
tree | bac8387f2da20d5b6d5f74bb09fb5708d1fbd61e /Lib/test/test_capi.py | |
parent | 0afbabe245e2eb6f7cef3b70531d69f2a7ad8295 (diff) | |
download | cpython-6ea4186de32d65b1f1dc1533b6312b798d300466.zip cpython-6ea4186de32d65b1f1dc1533b6312b798d300466.tar.gz cpython-6ea4186de32d65b1f1dc1533b6312b798d300466.tar.bz2 |
bpo-28180: Implementation for PEP 538 (#659)
- new PYTHONCOERCECLOCALE config setting
- coerces legacy C locale to C.UTF-8, C.utf8 or UTF-8 by default
- always uses C.UTF-8 on Android
- uses `surrogateescape` on stdin and stdout in the coercion
target locales
- configure option to disable locale coercion at build time
- configure option to disable C locale warning at build time
Diffstat (limited to 'Lib/test/test_capi.py')
-rw-r--r-- | Lib/test/test_capi.py | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py index 8ac8af9..c4a9766 100644 --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -371,14 +371,21 @@ class EmbeddingTests(unittest.TestCase): def tearDown(self): os.chdir(self.oldcwd) - def run_embedded_interpreter(self, *args): + def run_embedded_interpreter(self, *args, env=None): """Runs a test in the embedded interpreter""" cmd = [self.test_exe] cmd.extend(args) + if env is not None and sys.platform == 'win32': + # Windows requires at least the SYSTEMROOT environment variable to + # start Python. + env = env.copy() + env['SYSTEMROOT'] = os.environ['SYSTEMROOT'] + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - universal_newlines=True) + universal_newlines=True, + env=env) (out, err) = p.communicate() self.assertEqual(p.returncode, 0, "bad returncode %d, stderr is %r" % @@ -471,26 +478,16 @@ class EmbeddingTests(unittest.TestCase): self.assertNotEqual(sub.tstate, main.tstate) self.assertNotEqual(sub.modules, main.modules) - @staticmethod - def _get_default_pipe_encoding(): - rp, wp = os.pipe() - try: - with os.fdopen(wp, 'w') as w: - default_pipe_encoding = w.encoding - finally: - os.close(rp) - return default_pipe_encoding - def test_forced_io_encoding(self): # Checks forced configuration of embedded interpreter IO streams - out, err = self.run_embedded_interpreter("forced_io_encoding") - if support.verbose: + env = {"PYTHONIOENCODING": "utf-8:surrogateescape"} + out, err = self.run_embedded_interpreter("forced_io_encoding", env=env) + if support.verbose > 1: print() print(out) print(err) - expected_errors = sys.__stdout__.errors - expected_stdin_encoding = sys.__stdin__.encoding - expected_pipe_encoding = self._get_default_pipe_encoding() + expected_stream_encoding = "utf-8" + expected_errors = "surrogateescape" expected_output = '\n'.join([ "--- Use defaults ---", "Expected encoding: default", @@ -517,8 +514,8 @@ class EmbeddingTests(unittest.TestCase): "stdout: latin-1:replace", "stderr: latin-1:backslashreplace"]) expected_output = expected_output.format( - in_encoding=expected_stdin_encoding, - out_encoding=expected_pipe_encoding, + in_encoding=expected_stream_encoding, + out_encoding=expected_stream_encoding, errors=expected_errors) # This is useful if we ever trip over odd platform behaviour self.maxDiff = None |