diff options
author | Brian Curtin <brian.curtin@gmail.com> | 2010-10-30 21:27:07 (GMT) |
---|---|---|
committer | Brian Curtin <brian.curtin@gmail.com> | 2010-10-30 21:27:07 (GMT) |
commit | 32105f401d25d195a0668b56140d9fdfae439ca1 (patch) | |
tree | 960515f2a008a03a15a1a6cafc8a5da59af45405 | |
parent | cf9ca7f259e563a35886c0705860851fb0dd2bf1 (diff) | |
download | cpython-32105f401d25d195a0668b56140d9fdfae439ca1.zip cpython-32105f401d25d195a0668b56140d9fdfae439ca1.tar.gz cpython-32105f401d25d195a0668b56140d9fdfae439ca1.tar.bz2 |
Merged revisions 85987 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r85987 | brian.curtin | 2010-10-30 16:24:21 -0500 (Sat, 30 Oct 2010) | 2 lines
Fix #10257. Clear resource warnings by using os.popen's context manager.
........
-rw-r--r-- | Lib/test/test_os.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 6134c93..9be1aad 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -388,17 +388,19 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol): os.environ.clear() if os.path.exists("/bin/sh"): os.environ.update(HELLO="World") - value = os.popen("/bin/sh -c 'echo $HELLO'").read().strip() - self.assertEquals(value, "World") + with os.popen("/bin/sh -c 'echo $HELLO'") as popen: + value = popen.read().strip() + self.assertEquals(value, "World") def test_os_popen_iter(self): if os.path.exists("/bin/sh"): - popen = os.popen("/bin/sh -c 'echo \"line1\nline2\nline3\"'") - it = iter(popen) - self.assertEquals(next(it), "line1\n") - self.assertEquals(next(it), "line2\n") - self.assertEquals(next(it), "line3\n") - self.assertRaises(StopIteration, next, it) + with os.popen( + "/bin/sh -c 'echo \"line1\nline2\nline3\"'") as popen: + it = iter(popen) + self.assertEquals(next(it), "line1\n") + self.assertEquals(next(it), "line2\n") + self.assertEquals(next(it), "line3\n") + self.assertRaises(StopIteration, next, it) # Verify environ keys and values from the OS are of the # correct str type. |