mirror of
https://github.com/python/cpython.git
synced 2025-08-19 00:00:48 +00:00
Merged revisions 86185 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r86185 | brian.curtin | 2010-11-04 22:58:52 -0500 (Thu, 04 Nov 2010) | 2 lines Add cleanups to stdout/stderr pipes to remove ResourceWarnings. ........
This commit is contained in:
parent
ab016d21a6
commit
d117b562ed
1 changed files with 16 additions and 0 deletions
|
@ -117,6 +117,8 @@ class ProcessTestCase(BaseTestCase):
|
||||||
# .stdin is None when not redirected
|
# .stdin is None when not redirected
|
||||||
p = subprocess.Popen([sys.executable, "-c", 'print "banana"'],
|
p = subprocess.Popen([sys.executable, "-c", 'print "banana"'],
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
self.addCleanup(p.stdout.close)
|
||||||
|
self.addCleanup(p.stderr.close)
|
||||||
p.wait()
|
p.wait()
|
||||||
self.assertEqual(p.stdin, None)
|
self.assertEqual(p.stdin, None)
|
||||||
|
|
||||||
|
@ -127,6 +129,8 @@ class ProcessTestCase(BaseTestCase):
|
||||||
'test of stdout in a different '
|
'test of stdout in a different '
|
||||||
'process ..."'],
|
'process ..."'],
|
||||||
stdin=subprocess.PIPE, stderr=subprocess.PIPE)
|
stdin=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
self.addCleanup(p.stdin.close)
|
||||||
|
self.addCleanup(p.stderr.close)
|
||||||
p.wait()
|
p.wait()
|
||||||
self.assertEqual(p.stdout, None)
|
self.assertEqual(p.stdout, None)
|
||||||
|
|
||||||
|
@ -134,6 +138,8 @@ class ProcessTestCase(BaseTestCase):
|
||||||
# .stderr is None when not redirected
|
# .stderr is None when not redirected
|
||||||
p = subprocess.Popen([sys.executable, "-c", 'print "banana"'],
|
p = subprocess.Popen([sys.executable, "-c", 'print "banana"'],
|
||||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
|
self.addCleanup(p.stdout.close)
|
||||||
|
self.addCleanup(p.stdin.close)
|
||||||
p.wait()
|
p.wait()
|
||||||
self.assertEqual(p.stderr, None)
|
self.assertEqual(p.stderr, None)
|
||||||
|
|
||||||
|
@ -194,6 +200,7 @@ class ProcessTestCase(BaseTestCase):
|
||||||
p = subprocess.Popen([sys.executable, "-c",
|
p = subprocess.Popen([sys.executable, "-c",
|
||||||
'import sys; sys.stdout.write("orange")'],
|
'import sys; sys.stdout.write("orange")'],
|
||||||
stdout=subprocess.PIPE)
|
stdout=subprocess.PIPE)
|
||||||
|
self.addCleanup(p.stdout.close)
|
||||||
self.assertEqual(p.stdout.read(), "orange")
|
self.assertEqual(p.stdout.read(), "orange")
|
||||||
|
|
||||||
def test_stdout_filedes(self):
|
def test_stdout_filedes(self):
|
||||||
|
@ -222,6 +229,7 @@ class ProcessTestCase(BaseTestCase):
|
||||||
p = subprocess.Popen([sys.executable, "-c",
|
p = subprocess.Popen([sys.executable, "-c",
|
||||||
'import sys; sys.stderr.write("strawberry")'],
|
'import sys; sys.stderr.write("strawberry")'],
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE)
|
||||||
|
self.addCleanup(p.stderr.close)
|
||||||
self.assertStderrEqual(p.stderr.read(), "strawberry")
|
self.assertStderrEqual(p.stderr.read(), "strawberry")
|
||||||
|
|
||||||
def test_stderr_filedes(self):
|
def test_stderr_filedes(self):
|
||||||
|
@ -254,6 +262,7 @@ class ProcessTestCase(BaseTestCase):
|
||||||
'sys.stderr.write("orange")'],
|
'sys.stderr.write("orange")'],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.STDOUT)
|
stderr=subprocess.STDOUT)
|
||||||
|
self.addCleanup(p.stdout.close)
|
||||||
self.assertStderrEqual(p.stdout.read(), "appleorange")
|
self.assertStderrEqual(p.stdout.read(), "appleorange")
|
||||||
|
|
||||||
def test_stdout_stderr_file(self):
|
def test_stdout_stderr_file(self):
|
||||||
|
@ -289,6 +298,7 @@ class ProcessTestCase(BaseTestCase):
|
||||||
'sys.stdout.write(os.getcwd())'],
|
'sys.stdout.write(os.getcwd())'],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
cwd=tmpdir)
|
cwd=tmpdir)
|
||||||
|
self.addCleanup(p.stdout.close)
|
||||||
normcase = os.path.normcase
|
normcase = os.path.normcase
|
||||||
self.assertEqual(normcase(p.stdout.read()), normcase(tmpdir))
|
self.assertEqual(normcase(p.stdout.read()), normcase(tmpdir))
|
||||||
|
|
||||||
|
@ -300,6 +310,7 @@ class ProcessTestCase(BaseTestCase):
|
||||||
'sys.stdout.write(os.getenv("FRUIT"))'],
|
'sys.stdout.write(os.getenv("FRUIT"))'],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
env=newenv)
|
env=newenv)
|
||||||
|
self.addCleanup(p.stdout.close)
|
||||||
self.assertEqual(p.stdout.read(), "orange")
|
self.assertEqual(p.stdout.read(), "orange")
|
||||||
|
|
||||||
def test_communicate_stdin(self):
|
def test_communicate_stdin(self):
|
||||||
|
@ -415,6 +426,7 @@ class ProcessTestCase(BaseTestCase):
|
||||||
'sys.stdout.write("\\nline6");'],
|
'sys.stdout.write("\\nline6");'],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
universal_newlines=1)
|
universal_newlines=1)
|
||||||
|
self.addCleanup(p.stdout.close)
|
||||||
stdout = p.stdout.read()
|
stdout = p.stdout.read()
|
||||||
if hasattr(file, 'newlines'):
|
if hasattr(file, 'newlines'):
|
||||||
# Interpreter with universal newline support
|
# Interpreter with universal newline support
|
||||||
|
@ -639,6 +651,7 @@ class POSIXProcessTestCase(BaseTestCase):
|
||||||
"sys.stdout.write(os.getenv('FRUIT'))"],
|
"sys.stdout.write(os.getenv('FRUIT'))"],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
preexec_fn=lambda: os.putenv("FRUIT", "apple"))
|
preexec_fn=lambda: os.putenv("FRUIT", "apple"))
|
||||||
|
self.addCleanup(p.stdout.close)
|
||||||
self.assertEqual(p.stdout.read(), "apple")
|
self.assertEqual(p.stdout.read(), "apple")
|
||||||
|
|
||||||
def test_args_string(self):
|
def test_args_string(self):
|
||||||
|
@ -672,6 +685,7 @@ class POSIXProcessTestCase(BaseTestCase):
|
||||||
p = subprocess.Popen(["echo $FRUIT"], shell=1,
|
p = subprocess.Popen(["echo $FRUIT"], shell=1,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
env=newenv)
|
env=newenv)
|
||||||
|
self.addCleanup(p.stdout.close)
|
||||||
self.assertEqual(p.stdout.read().strip(), "apple")
|
self.assertEqual(p.stdout.read().strip(), "apple")
|
||||||
|
|
||||||
def test_shell_string(self):
|
def test_shell_string(self):
|
||||||
|
@ -681,6 +695,7 @@ class POSIXProcessTestCase(BaseTestCase):
|
||||||
p = subprocess.Popen("echo $FRUIT", shell=1,
|
p = subprocess.Popen("echo $FRUIT", shell=1,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
env=newenv)
|
env=newenv)
|
||||||
|
self.addCleanup(p.stdout.close)
|
||||||
self.assertEqual(p.stdout.read().strip(), "apple")
|
self.assertEqual(p.stdout.read().strip(), "apple")
|
||||||
|
|
||||||
def test_call_string(self):
|
def test_call_string(self):
|
||||||
|
@ -712,6 +727,7 @@ class POSIXProcessTestCase(BaseTestCase):
|
||||||
for sh in shells:
|
for sh in shells:
|
||||||
p = subprocess.Popen("echo $0", executable=sh, shell=True,
|
p = subprocess.Popen("echo $0", executable=sh, shell=True,
|
||||||
stdout=subprocess.PIPE)
|
stdout=subprocess.PIPE)
|
||||||
|
self.addCleanup(p.stdout.close)
|
||||||
self.assertEqual(p.stdout.read().strip(), sh)
|
self.assertEqual(p.stdout.read().strip(), sh)
|
||||||
|
|
||||||
def _kill_process(self, method, *args):
|
def _kill_process(self, method, *args):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue