summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Curtin <brian.curtin@gmail.com>2010-10-30 21:24:21 (GMT)
committerBrian Curtin <brian.curtin@gmail.com>2010-10-30 21:24:21 (GMT)
commit810921b675654fc6560747390eb657fa765d46ba (patch)
tree4157a8f8eb5f0d26dd5a399bbb144e10eb8b76e3
parent1d7878a6963082222af16b131dc640bc7c17c0ee (diff)
downloadcpython-810921b675654fc6560747390eb657fa765d46ba.zip
cpython-810921b675654fc6560747390eb657fa765d46ba.tar.gz
cpython-810921b675654fc6560747390eb657fa765d46ba.tar.bz2
Fix #10257. Clear resource warnings by using os.popen's context manager.
-rw-r--r--Lib/test/test_os.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index 73261e0..b67eed5 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -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.