summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
authorXavier de Gaye <xdegaye@users.sourceforge.net>2016-07-22 12:15:29 +0200
committerXavier de Gaye <xdegaye@users.sourceforge.net>2016-07-22 12:15:29 +0200
commit1968105b8f73b8e9efeee7a8735df76f6ad06b29 (patch)
tree3d7860d37a5183b723815f5e1498207037521e35 /Lib
parent66d4b915d1a98c47d4fb366ccf712fce455ac626 (diff)
downloadcpython-1968105b8f73b8e9efeee7a8735df76f6ad06b29.tar.gz
Issue #27472: Add test.support.unix_shell as the path to the default shell.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/distutils/tests/test_spawn.py11
-rw-r--r--Lib/test/support/__init__.py7
-rw-r--r--Lib/test/test_os.py13
-rw-r--r--Lib/test/test_subprocess.py4
4 files changed, 22 insertions, 13 deletions
diff --git a/Lib/distutils/tests/test_spawn.py b/Lib/distutils/tests/test_spawn.py
index f507ef7750..5edc24a3a1 100644
--- a/Lib/distutils/tests/test_spawn.py
+++ b/Lib/distutils/tests/test_spawn.py
@@ -1,7 +1,8 @@
"""Tests for distutils.spawn."""
import unittest
+import sys
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 spawn
@@ -29,9 +30,9 @@ class SpawnTestCase(support.TempdirManager,
# creating something executable
# through the shell that returns 1
- if os.name == 'posix':
+ if sys.platform != 'win32':
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:
exe = os.path.join(tmpdir, 'foo.bat')
self.write_file(exe, 'exit 1')
@@ -40,9 +41,9 @@ class SpawnTestCase(support.TempdirManager,
self.assertRaises(DistutilsExecError, spawn, [exe])
# now something that works
- if os.name == 'posix':
+ if sys.platform != 'win32':
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:
exe = os.path.join(tmpdir, 'foo.bat')
self.write_file(exe, 'exit 0')
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 2b2966876f..aa6725feec 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -92,7 +92,7 @@ __all__ = [
"anticipate_failure", "load_package_tests", "detect_api_mismatch",
"check__all__",
# sys
- "is_jython", "is_android", "check_impl_detail",
+ "is_jython", "is_android", "check_impl_detail", "unix_shell",
# network
"HOST", "IPV6_ENABLED", "find_unused_port", "bind_port", "open_urlresource",
# processes
@@ -736,6 +736,11 @@ is_jython = sys.platform.startswith('java')
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
if os.name == 'java':
# Jython disallows @ in module names
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index 6493d76c9a..aa9b538748 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -64,6 +64,7 @@ except ImportError:
INT_MAX = PY_SSIZE_T_MAX = sys.maxsize
from test.support.script_helper import assert_python_ok
+from test.support import unix_shell
root_in_posix = False
@@ -670,18 +671,20 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol):
return os.environ
# 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):
os.environ.clear()
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()
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):
- with os.popen(
- "/bin/sh -c 'echo \"line1\nline2\nline3\"'") as popen:
+ with os.popen("%s -c 'echo \"line1\nline2\nline3\"'"
+ % unix_shell) as popen:
it = iter(popen)
self.assertEqual(next(it), "line1\n")
self.assertEqual(next(it), "line2\n")
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index ba91bbc081..092e2ce753 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -1579,7 +1579,7 @@ class POSIXProcessTestCase(BaseTestCase):
fd, fname = tempfile.mkstemp()
# reopen in text mode
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" %
sys.executable)
os.chmod(fname, 0o700)
@@ -1624,7 +1624,7 @@ class POSIXProcessTestCase(BaseTestCase):
fd, fname = tempfile.mkstemp()
# reopen in text mode
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" %
sys.executable)
os.chmod(fname, 0o700)