[Python-checkins] r85987 - python/branches/py3k/Lib/test/test_os.py
brian.curtin
python-checkins at python.org
Sat Oct 30 23:24:21 CEST 2010
Author: brian.curtin
Date: Sat Oct 30 23:24:21 2010
New Revision: 85987
Log:
Fix #10257. Clear resource warnings by using os.popen's context manager.
Modified:
python/branches/py3k/Lib/test/test_os.py
Modified: python/branches/py3k/Lib/test/test_os.py
==============================================================================
--- python/branches/py3k/Lib/test/test_os.py (original)
+++ python/branches/py3k/Lib/test/test_os.py Sat Oct 30 23:24:21 2010
@@ -406,17 +406,19 @@
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.
More information about the Python-checkins
mailing list