Wrap long lines.
This commit is contained in:
parent
e718f615b8
commit
3b01a70f76
|
@ -14,7 +14,8 @@ mswindows = (sys.platform == "win32")
|
||||||
#
|
#
|
||||||
|
|
||||||
if mswindows:
|
if mswindows:
|
||||||
SETBINARY = 'import msvcrt; msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY);'
|
SETBINARY = ('import msvcrt; msvcrt.setmode(sys.stdout.fileno(), '
|
||||||
|
'os.O_BINARY);')
|
||||||
else:
|
else:
|
||||||
SETBINARY = ''
|
SETBINARY = ''
|
||||||
|
|
||||||
|
@ -32,7 +33,8 @@ class ProcessTestCase(unittest.TestCase):
|
||||||
#
|
#
|
||||||
def test_call_seq(self):
|
def test_call_seq(self):
|
||||||
"""call() function with sequence argument"""
|
"""call() function with sequence argument"""
|
||||||
rc = subprocess.call([sys.executable, "-c", "import sys; sys.exit(47)"])
|
rc = subprocess.call([sys.executable, "-c",
|
||||||
|
"import sys; sys.exit(47)"])
|
||||||
self.assertEqual(rc, 47)
|
self.assertEqual(rc, 47)
|
||||||
|
|
||||||
def test_call_kwargs(self):
|
def test_call_kwargs(self):
|
||||||
|
@ -68,8 +70,9 @@ class ProcessTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def test_executable(self):
|
def test_executable(self):
|
||||||
"""executable"""
|
"""executable"""
|
||||||
p = subprocess.Popen(["somethingyoudonthave", "-c", "import sys; sys.exit(47)"],
|
p = subprocess.Popen(["somethingyoudonthave",
|
||||||
executable=sys.executable)
|
"-c", "import sys; sys.exit(47)"],
|
||||||
|
executable=sys.executable)
|
||||||
p.wait()
|
p.wait()
|
||||||
self.assertEqual(p.returncode, 47)
|
self.assertEqual(p.returncode, 47)
|
||||||
|
|
||||||
|
@ -215,14 +218,17 @@ class ProcessTestCase(unittest.TestCase):
|
||||||
'import sys,os;' \
|
'import sys,os;' \
|
||||||
'sys.stderr.write("pineapple");' \
|
'sys.stderr.write("pineapple");' \
|
||||||
'sys.stdout.write(sys.stdin.read())'],
|
'sys.stdout.write(sys.stdin.read())'],
|
||||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
stdin=subprocess.PIPE,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE)
|
||||||
(stdout, stderr) = p.communicate("banana")
|
(stdout, stderr) = p.communicate("banana")
|
||||||
self.assertEqual(stdout, "banana")
|
self.assertEqual(stdout, "banana")
|
||||||
self.assertEqual(stderr, "pineapple")
|
self.assertEqual(stderr, "pineapple")
|
||||||
|
|
||||||
def test_communicate_returns(self):
|
def test_communicate_returns(self):
|
||||||
"""communicate() should return None if no redirection is active"""
|
"""communicate() should return None if no redirection is active"""
|
||||||
p = subprocess.Popen([sys.executable, "-c", "import sys; sys.exit(47)"])
|
p = subprocess.Popen([sys.executable, "-c",
|
||||||
|
"import sys; sys.exit(47)"])
|
||||||
(stdout, stderr) = p.communicate()
|
(stdout, stderr) = p.communicate()
|
||||||
self.assertEqual(stdout, None)
|
self.assertEqual(stdout, None)
|
||||||
self.assertEqual(stderr, None)
|
self.assertEqual(stderr, None)
|
||||||
|
@ -243,7 +249,9 @@ class ProcessTestCase(unittest.TestCase):
|
||||||
'sys.stdout.write(sys.stdin.read(47));' \
|
'sys.stdout.write(sys.stdin.read(47));' \
|
||||||
'sys.stderr.write("xyz"*%d);' \
|
'sys.stderr.write("xyz"*%d);' \
|
||||||
'sys.stdout.write(sys.stdin.read())' % pipe_buf],
|
'sys.stdout.write(sys.stdin.read())' % pipe_buf],
|
||||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
stdin=subprocess.PIPE,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE)
|
||||||
string_to_write = "abc"*pipe_buf
|
string_to_write = "abc"*pipe_buf
|
||||||
(stdout, stderr) = p.communicate(string_to_write)
|
(stdout, stderr) = p.communicate(string_to_write)
|
||||||
self.assertEqual(stdout, string_to_write)
|
self.assertEqual(stdout, string_to_write)
|
||||||
|
@ -253,7 +261,9 @@ class ProcessTestCase(unittest.TestCase):
|
||||||
p = subprocess.Popen([sys.executable, "-c",
|
p = subprocess.Popen([sys.executable, "-c",
|
||||||
'import sys,os;' \
|
'import sys,os;' \
|
||||||
'sys.stdout.write(sys.stdin.read())'],
|
'sys.stdout.write(sys.stdin.read())'],
|
||||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
stdin=subprocess.PIPE,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE)
|
||||||
p.stdin.write("banana")
|
p.stdin.write("banana")
|
||||||
(stdout, stderr) = p.communicate("split")
|
(stdout, stderr) = p.communicate("split")
|
||||||
self.assertEqual(stdout, "bananasplit")
|
self.assertEqual(stdout, "bananasplit")
|
||||||
|
@ -262,49 +272,52 @@ class ProcessTestCase(unittest.TestCase):
|
||||||
def test_universal_newlines(self):
|
def test_universal_newlines(self):
|
||||||
"""universal newlines"""
|
"""universal newlines"""
|
||||||
p = subprocess.Popen([sys.executable, "-c",
|
p = subprocess.Popen([sys.executable, "-c",
|
||||||
'import sys,os;' + SETBINARY + \
|
'import sys,os;' + SETBINARY +
|
||||||
'sys.stdout.write("line1\\n");' \
|
'sys.stdout.write("line1\\n");'
|
||||||
'sys.stdout.flush();' \
|
'sys.stdout.flush();'
|
||||||
'sys.stdout.write("line2\\r");' \
|
'sys.stdout.write("line2\\r");'
|
||||||
'sys.stdout.flush();' \
|
'sys.stdout.flush();'
|
||||||
'sys.stdout.write("line3\\r\\n");' \
|
'sys.stdout.write("line3\\r\\n");'
|
||||||
'sys.stdout.flush();' \
|
'sys.stdout.flush();'
|
||||||
'sys.stdout.write("line4\\r");' \
|
'sys.stdout.write("line4\\r");'
|
||||||
'sys.stdout.flush();' \
|
'sys.stdout.flush();'
|
||||||
'sys.stdout.write("\\nline5");'
|
'sys.stdout.write("\\nline5");'
|
||||||
'sys.stdout.flush();' \
|
'sys.stdout.flush();'
|
||||||
'sys.stdout.write("\\nline6");'],
|
'sys.stdout.write("\\nline6");'],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
universal_newlines=1)
|
universal_newlines=1)
|
||||||
stdout = p.stdout.read()
|
stdout = p.stdout.read()
|
||||||
if hasattr(open, 'newlines'):
|
if hasattr(open, 'newlines'):
|
||||||
# Interpreter with universal newline support
|
# Interpreter with universal newline support
|
||||||
self.assertEqual(stdout, "line1\nline2\nline3\nline4\nline5\nline6")
|
self.assertEqual(stdout,
|
||||||
|
"line1\nline2\nline3\nline4\nline5\nline6")
|
||||||
else:
|
else:
|
||||||
# Interpreter without universal newline support
|
# Interpreter without universal newline support
|
||||||
self.assertEqual(stdout, "line1\nline2\rline3\r\nline4\r\nline5\nline6")
|
self.assertEqual(stdout,
|
||||||
|
"line1\nline2\rline3\r\nline4\r\nline5\nline6")
|
||||||
|
|
||||||
def test_universal_newlines_communicate(self):
|
def test_universal_newlines_communicate(self):
|
||||||
"""universal newlines through communicate()"""
|
"""universal newlines through communicate()"""
|
||||||
p = subprocess.Popen([sys.executable, "-c",
|
p = subprocess.Popen([sys.executable, "-c",
|
||||||
'import sys,os;' + SETBINARY + \
|
'import sys,os;' + SETBINARY +
|
||||||
'sys.stdout.write("line1\\n");' \
|
'sys.stdout.write("line1\\n");'
|
||||||
'sys.stdout.flush();' \
|
'sys.stdout.flush();'
|
||||||
'sys.stdout.write("line2\\r");' \
|
'sys.stdout.write("line2\\r");'
|
||||||
'sys.stdout.flush();' \
|
'sys.stdout.flush();'
|
||||||
'sys.stdout.write("line3\\r\\n");' \
|
'sys.stdout.write("line3\\r\\n");'
|
||||||
'sys.stdout.flush();' \
|
'sys.stdout.flush();'
|
||||||
'sys.stdout.write("line4\\r");' \
|
'sys.stdout.write("line4\\r");'
|
||||||
'sys.stdout.flush();' \
|
'sys.stdout.flush();'
|
||||||
'sys.stdout.write("\\nline5");'
|
'sys.stdout.write("\\nline5");'
|
||||||
'sys.stdout.flush();' \
|
'sys.stdout.flush();'
|
||||||
'sys.stdout.write("\\nline6");'],
|
'sys.stdout.write("\\nline6");'],
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
||||||
universal_newlines=1)
|
universal_newlines=1)
|
||||||
(stdout, stderr) = p.communicate()
|
(stdout, stderr) = p.communicate()
|
||||||
if hasattr(open, 'newlines'):
|
if hasattr(open, 'newlines'):
|
||||||
# Interpreter with universal newline support
|
# Interpreter with universal newline support
|
||||||
self.assertEqual(stdout, "line1\nline2\nline3\nline4\nline5\nline6")
|
self.assertEqual(stdout,
|
||||||
|
"line1\nline2\nline3\nline4\nline5\nline6")
|
||||||
else:
|
else:
|
||||||
# Interpreter without universal newline support
|
# Interpreter without universal newline support
|
||||||
self.assertEqual(stdout, "line1\nline2\rline3\r\nline4\r\nline5\nline6")
|
self.assertEqual(stdout, "line1\nline2\rline3\r\nline4\r\nline5\nline6")
|
||||||
|
@ -312,8 +325,11 @@ class ProcessTestCase(unittest.TestCase):
|
||||||
def test_no_leaking(self):
|
def test_no_leaking(self):
|
||||||
"""Make sure we leak no resources"""
|
"""Make sure we leak no resources"""
|
||||||
for i in range(1026):
|
for i in range(1026):
|
||||||
p = subprocess.Popen([sys.executable, "-c", "import sys;sys.stdout.write(sys.stdin.read())"],
|
p = subprocess.Popen([sys.executable, "-c",
|
||||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
"import sys;sys.stdout.write(sys.stdin.read())"],
|
||||||
|
stdin=subprocess.PIPE,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE)
|
||||||
data = p.communicate("lime")[0]
|
data = p.communicate("lime")[0]
|
||||||
self.assertEqual(data, "lime")
|
self.assertEqual(data, "lime")
|
||||||
|
|
||||||
|
@ -373,7 +389,8 @@ class ProcessTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def test_run_abort(self):
|
def test_run_abort(self):
|
||||||
"""returncode handles signal termination"""
|
"""returncode handles signal termination"""
|
||||||
p = subprocess.Popen([sys.executable, "-c", "import os; os.abort()"])
|
p = subprocess.Popen([sys.executable,
|
||||||
|
"-c", "import os; os.abort()"])
|
||||||
p.wait()
|
p.wait()
|
||||||
self.assertEqual(-p.returncode, signal.SIGABRT)
|
self.assertEqual(-p.returncode, signal.SIGABRT)
|
||||||
|
|
||||||
|
@ -401,7 +418,8 @@ class ProcessTestCase(unittest.TestCase):
|
||||||
"""args is a string"""
|
"""args is a string"""
|
||||||
f, fname = self.mkstemp()
|
f, fname = self.mkstemp()
|
||||||
os.write(f, "#!/bin/sh\n")
|
os.write(f, "#!/bin/sh\n")
|
||||||
os.write(f, "exec %s -c 'import sys; sys.exit(47)'\n" % sys.executable)
|
os.write(f, "exec %s -c 'import sys; sys.exit(47)'\n" %
|
||||||
|
sys.executable)
|
||||||
os.close(f)
|
os.close(f)
|
||||||
os.chmod(fname, 0700)
|
os.chmod(fname, 0700)
|
||||||
p = subprocess.Popen(fname)
|
p = subprocess.Popen(fname)
|
||||||
|
@ -412,10 +430,12 @@ class ProcessTestCase(unittest.TestCase):
|
||||||
def test_invalid_args(self):
|
def test_invalid_args(self):
|
||||||
"""invalid arguments should raise ValueError"""
|
"""invalid arguments should raise ValueError"""
|
||||||
self.assertRaises(ValueError, subprocess.call,
|
self.assertRaises(ValueError, subprocess.call,
|
||||||
[sys.executable, "-c", "import sys; sys.exit(47)"],
|
[sys.executable,
|
||||||
|
"-c", "import sys; sys.exit(47)"],
|
||||||
startupinfo=47)
|
startupinfo=47)
|
||||||
self.assertRaises(ValueError, subprocess.call,
|
self.assertRaises(ValueError, subprocess.call,
|
||||||
[sys.executable, "-c", "import sys; sys.exit(47)"],
|
[sys.executable,
|
||||||
|
"-c", "import sys; sys.exit(47)"],
|
||||||
creationflags=47)
|
creationflags=47)
|
||||||
|
|
||||||
def test_shell_sequence(self):
|
def test_shell_sequence(self):
|
||||||
|
@ -440,7 +460,8 @@ class ProcessTestCase(unittest.TestCase):
|
||||||
"""call() function with string argument on UNIX"""
|
"""call() function with string argument on UNIX"""
|
||||||
f, fname = self.mkstemp()
|
f, fname = self.mkstemp()
|
||||||
os.write(f, "#!/bin/sh\n")
|
os.write(f, "#!/bin/sh\n")
|
||||||
os.write(f, "exec %s -c 'import sys; sys.exit(47)'\n" % sys.executable)
|
os.write(f, "exec %s -c 'import sys; sys.exit(47)'\n" %
|
||||||
|
sys.executable)
|
||||||
os.close(f)
|
os.close(f)
|
||||||
os.chmod(fname, 0700)
|
os.chmod(fname, 0700)
|
||||||
rc = subprocess.call(fname)
|
rc = subprocess.call(fname)
|
||||||
|
@ -469,16 +490,19 @@ class ProcessTestCase(unittest.TestCase):
|
||||||
def test_creationflags(self):
|
def test_creationflags(self):
|
||||||
"""creationflags argument"""
|
"""creationflags argument"""
|
||||||
CREATE_NEW_CONSOLE = 16
|
CREATE_NEW_CONSOLE = 16
|
||||||
subprocess.call(sys.executable + ' -c "import time; time.sleep(2)"',
|
subprocess.call(sys.executable +
|
||||||
|
' -c "import time; time.sleep(2)"',
|
||||||
creationflags=CREATE_NEW_CONSOLE)
|
creationflags=CREATE_NEW_CONSOLE)
|
||||||
|
|
||||||
def test_invalid_args(self):
|
def test_invalid_args(self):
|
||||||
"""invalid arguments should raise ValueError"""
|
"""invalid arguments should raise ValueError"""
|
||||||
self.assertRaises(ValueError, subprocess.call,
|
self.assertRaises(ValueError, subprocess.call,
|
||||||
[sys.executable, "-c", "import sys; sys.exit(47)"],
|
[sys.executable,
|
||||||
|
"-c", "import sys; sys.exit(47)"],
|
||||||
preexec_fn=lambda: 1)
|
preexec_fn=lambda: 1)
|
||||||
self.assertRaises(ValueError, subprocess.call,
|
self.assertRaises(ValueError, subprocess.call,
|
||||||
[sys.executable, "-c", "import sys; sys.exit(47)"],
|
[sys.executable,
|
||||||
|
"-c", "import sys; sys.exit(47)"],
|
||||||
close_fds=True)
|
close_fds=True)
|
||||||
|
|
||||||
def test_shell_sequence(self):
|
def test_shell_sequence(self):
|
||||||
|
@ -501,11 +525,11 @@ class ProcessTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def test_call_string(self):
|
def test_call_string(self):
|
||||||
"""call() function with string argument on Windows"""
|
"""call() function with string argument on Windows"""
|
||||||
rc = subprocess.call(sys.executable + ' -c "import sys; sys.exit(47)"')
|
rc = subprocess.call(sys.executable +
|
||||||
|
' -c "import sys; sys.exit(47)"')
|
||||||
self.assertEqual(rc, 47)
|
self.assertEqual(rc, 47)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
test_support.run_unittest(ProcessTestCase)
|
test_support.run_unittest(ProcessTestCase)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue