diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-04-18 07:59:53 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-04-18 07:59:53 (GMT) |
commit | f3bc258b947de621b5487f8be8f07f936fc7fdf9 (patch) | |
tree | a4d93d4e95d0e14f256a6dbf7a86e486001fc74a /Lib/test/test_site.py | |
parent | 738446f0f7d2e1ca76dd70d59c02312992194644 (diff) | |
download | cpython-f3bc258b947de621b5487f8be8f07f936fc7fdf9.zip cpython-f3bc258b947de621b5487f8be8f07f936fc7fdf9.tar.gz cpython-f3bc258b947de621b5487f8be8f07f936fc7fdf9.tar.bz2 |
Issue #8340, test_abs_path() of test_site: encode paths to ASCII with
backslashreplace to avoid locale issues, don't write stderr to a pipe to ease
debug, separate directories by newlines instead of a space.
Diffstat (limited to 'Lib/test/test_site.py')
-rw-r--r-- | Lib/test/test_site.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py index 1a50f19..904bcef 100644 --- a/Lib/test/test_site.py +++ b/Lib/test/test_site.py @@ -268,26 +268,31 @@ class ImportSideEffectTests(unittest.TestCase): parent = os.path.relpath(os.path.dirname(os.__file__)) env = os.environ.copy() env['PYTHONPATH'] = parent - command = 'import os; print(os.__file__, os.__cached__)' + code = ('import os, sys', + # use ASCII to avoid locale issues with non-ASCII directories + 'os_file = os.__file__.encode("ascii", "backslashreplace")', + r'sys.stdout.buffer.write(os_file + b"\n")', + 'os_cached = os.__cached__.encode("ascii", "backslashreplace")', + r'sys.stdout.buffer.write(os_cached + b"\n")') + command = '\n'.join(code) # First, prove that with -S (no 'import site'), the paths are # relative. proc = subprocess.Popen([sys.executable, '-S', '-c', command], env=env, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + stdout=subprocess.PIPE) stdout, stderr = proc.communicate() + self.assertEqual(proc.returncode, 0) - os__file__, os__cached__ = stdout.split() + os__file__, os__cached__ = stdout.splitlines()[:2] self.assertFalse(os.path.isabs(os__file__)) self.assertFalse(os.path.isabs(os__cached__)) # Now, with 'import site', it works. proc = subprocess.Popen([sys.executable, '-c', command], env=env, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + stdout=subprocess.PIPE) stdout, stderr = proc.communicate() self.assertEqual(proc.returncode, 0) - os__file__, os__cached__ = stdout.split() + os__file__, os__cached__ = stdout.splitlines()[:2] self.assertTrue(os.path.isabs(os__file__)) self.assertTrue(os.path.isabs(os__cached__)) |