Kaydet (Commit) d141531e authored tarafından Xavier de Gaye's avatar Xavier de Gaye

Issue #27472: Add test.support.unix_shell as the path to the default shell.

üst de85ed69
"""Tests for distutils.spawn.""" """Tests for distutils.spawn."""
import unittest import unittest
import sys
import os import os
from test.support import run_unittest from test.support import run_unittest, unix_shell
from distutils.spawn import _nt_quote_args from distutils.spawn import _nt_quote_args
from distutils.spawn import spawn from distutils.spawn import spawn
...@@ -29,9 +30,9 @@ class SpawnTestCase(support.TempdirManager, ...@@ -29,9 +30,9 @@ class SpawnTestCase(support.TempdirManager,
# creating something executable # creating something executable
# through the shell that returns 1 # through the shell that returns 1
if os.name == 'posix': if sys.platform != 'win32':
exe = os.path.join(tmpdir, 'foo.sh') exe = os.path.join(tmpdir, 'foo.sh')
self.write_file(exe, '#!/bin/sh\nexit 1') self.write_file(exe, '#!%s\nexit 1' % unix_shell)
else: else:
exe = os.path.join(tmpdir, 'foo.bat') exe = os.path.join(tmpdir, 'foo.bat')
self.write_file(exe, 'exit 1') self.write_file(exe, 'exit 1')
...@@ -40,9 +41,9 @@ class SpawnTestCase(support.TempdirManager, ...@@ -40,9 +41,9 @@ class SpawnTestCase(support.TempdirManager,
self.assertRaises(DistutilsExecError, spawn, [exe]) self.assertRaises(DistutilsExecError, spawn, [exe])
# now something that works # now something that works
if os.name == 'posix': if sys.platform != 'win32':
exe = os.path.join(tmpdir, 'foo.sh') exe = os.path.join(tmpdir, 'foo.sh')
self.write_file(exe, '#!/bin/sh\nexit 0') self.write_file(exe, '#!%s\nexit 0' % unix_shell)
else: else:
exe = os.path.join(tmpdir, 'foo.bat') exe = os.path.join(tmpdir, 'foo.bat')
self.write_file(exe, 'exit 0') self.write_file(exe, 'exit 0')
......
...@@ -92,7 +92,7 @@ __all__ = [ ...@@ -92,7 +92,7 @@ __all__ = [
"anticipate_failure", "load_package_tests", "detect_api_mismatch", "anticipate_failure", "load_package_tests", "detect_api_mismatch",
"check__all__", "check__all__",
# sys # sys
"is_jython", "is_android", "check_impl_detail", "is_jython", "is_android", "check_impl_detail", "unix_shell",
# network # network
"HOST", "IPV6_ENABLED", "find_unused_port", "bind_port", "open_urlresource", "HOST", "IPV6_ENABLED", "find_unused_port", "bind_port", "open_urlresource",
# processes # processes
...@@ -736,6 +736,11 @@ is_jython = sys.platform.startswith('java') ...@@ -736,6 +736,11 @@ is_jython = sys.platform.startswith('java')
is_android = bool(sysconfig.get_config_var('ANDROID_API_LEVEL')) is_android = bool(sysconfig.get_config_var('ANDROID_API_LEVEL'))
if sys.platform != 'win32':
unix_shell = '/system/bin/sh' if is_android else '/bin/sh'
else:
unix_shell = None
# Filename used for testing # Filename used for testing
if os.name == 'java': if os.name == 'java':
# Jython disallows @ in module names # Jython disallows @ in module names
......
...@@ -64,6 +64,7 @@ except ImportError: ...@@ -64,6 +64,7 @@ except ImportError:
INT_MAX = PY_SSIZE_T_MAX = sys.maxsize INT_MAX = PY_SSIZE_T_MAX = sys.maxsize
from test.support.script_helper import assert_python_ok from test.support.script_helper import assert_python_ok
from test.support import unix_shell
root_in_posix = False root_in_posix = False
...@@ -670,18 +671,20 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol): ...@@ -670,18 +671,20 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol):
return os.environ return os.environ
# Bug 1110478 # Bug 1110478
@unittest.skipUnless(os.path.exists('/bin/sh'), 'requires /bin/sh') @unittest.skipUnless(unix_shell and os.path.exists(unix_shell),
'requires a shell')
def test_update2(self): def test_update2(self):
os.environ.clear() os.environ.clear()
os.environ.update(HELLO="World") os.environ.update(HELLO="World")
with os.popen("/bin/sh -c 'echo $HELLO'") as popen: with os.popen("%s -c 'echo $HELLO'" % unix_shell) as popen:
value = popen.read().strip() value = popen.read().strip()
self.assertEqual(value, "World") self.assertEqual(value, "World")
@unittest.skipUnless(os.path.exists('/bin/sh'), 'requires /bin/sh') @unittest.skipUnless(unix_shell and os.path.exists(unix_shell),
'requires a shell')
def test_os_popen_iter(self): def test_os_popen_iter(self):
with os.popen( with os.popen("%s -c 'echo \"line1\nline2\nline3\"'"
"/bin/sh -c 'echo \"line1\nline2\nline3\"'") as popen: % unix_shell) as popen:
it = iter(popen) it = iter(popen)
self.assertEqual(next(it), "line1\n") self.assertEqual(next(it), "line1\n")
self.assertEqual(next(it), "line2\n") self.assertEqual(next(it), "line2\n")
......
...@@ -1579,7 +1579,7 @@ class POSIXProcessTestCase(BaseTestCase): ...@@ -1579,7 +1579,7 @@ class POSIXProcessTestCase(BaseTestCase):
fd, fname = tempfile.mkstemp() fd, fname = tempfile.mkstemp()
# reopen in text mode # reopen in text mode
with open(fd, "w", errors="surrogateescape") as fobj: with open(fd, "w", errors="surrogateescape") as fobj:
fobj.write("#!/bin/sh\n") fobj.write("#!%s\n" % support.unix_shell)
fobj.write("exec '%s' -c 'import sys; sys.exit(47)'\n" % fobj.write("exec '%s' -c 'import sys; sys.exit(47)'\n" %
sys.executable) sys.executable)
os.chmod(fname, 0o700) os.chmod(fname, 0o700)
...@@ -1624,7 +1624,7 @@ class POSIXProcessTestCase(BaseTestCase): ...@@ -1624,7 +1624,7 @@ class POSIXProcessTestCase(BaseTestCase):
fd, fname = tempfile.mkstemp() fd, fname = tempfile.mkstemp()
# reopen in text mode # reopen in text mode
with open(fd, "w", errors="surrogateescape") as fobj: with open(fd, "w", errors="surrogateescape") as fobj:
fobj.write("#!/bin/sh\n") fobj.write("#!%s\n" % support.unix_shell)
fobj.write("exec '%s' -c 'import sys; sys.exit(47)'\n" % fobj.write("exec '%s' -c 'import sys; sys.exit(47)'\n" %
sys.executable) sys.executable)
os.chmod(fname, 0o700) os.chmod(fname, 0o700)
......
...@@ -46,6 +46,8 @@ Library ...@@ -46,6 +46,8 @@ Library
Tests Tests
----- -----
- Issue #27472: Add test.support.unix_shell as the path to the default shell.
- Issue #27369: In test_pyexpat, avoid testing an error message detail that - Issue #27369: In test_pyexpat, avoid testing an error message detail that
changed in Expat 2.2.0. changed in Expat 2.2.0.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment