Kaydet (Commit) 810921b6 authored tarafından Brian Curtin's avatar Brian Curtin

Fix #10257. Clear resource warnings by using os.popen's context manager.

üst 1d7878a6
...@@ -406,12 +406,14 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol): ...@@ -406,12 +406,14 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol):
os.environ.clear() os.environ.clear()
if os.path.exists("/bin/sh"): if os.path.exists("/bin/sh"):
os.environ.update(HELLO="World") os.environ.update(HELLO="World")
value = os.popen("/bin/sh -c 'echo $HELLO'").read().strip() with os.popen("/bin/sh -c 'echo $HELLO'") as popen:
value = popen.read().strip()
self.assertEquals(value, "World") self.assertEquals(value, "World")
def test_os_popen_iter(self): def test_os_popen_iter(self):
if os.path.exists("/bin/sh"): if os.path.exists("/bin/sh"):
popen = os.popen("/bin/sh -c 'echo \"line1\nline2\nline3\"'") with os.popen(
"/bin/sh -c 'echo \"line1\nline2\nline3\"'") as popen:
it = iter(popen) it = iter(popen)
self.assertEquals(next(it), "line1\n") self.assertEquals(next(it), "line1\n")
self.assertEquals(next(it), "line2\n") self.assertEquals(next(it), "line2\n")
......
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