]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix #10257. Clear resource warnings by using os.popen's context manager.
authorBrian Curtin <brian.curtin@gmail.com>
Sat, 30 Oct 2010 21:24:21 +0000 (21:24 +0000)
committerBrian Curtin <brian.curtin@gmail.com>
Sat, 30 Oct 2010 21:24:21 +0000 (21:24 +0000)
Lib/test/test_os.py

index 73261e00b3d8d021ad096eca2c2d0e8a6e56d151..b67eed5077fd09b11b0ce79cb3cafec04d1af28b 100644 (file)
@@ -406,17 +406,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.