Issue #7461: objects returned by os.popen() should support the context manager protocol

This commit is contained in:
Antoine Pitrou 2009-12-09 00:01:27 +00:00
parent 9b14f6044c
commit ac62535164
2 changed files with 12 additions and 0 deletions

View file

@ -49,6 +49,14 @@ class PopenTest(unittest.TestCase):
else:
self.assertEqual(os.popen("exit 42").close(), 42 << 8)
def test_contextmanager(self):
with os.popen("echo hello") as f:
self.assertEqual(f.read(), "hello\n")
def test_iterating(self):
with os.popen("echo hello") as f:
self.assertEqual(list(f), ["hello\n"])
def test_main():
support.run_unittest(PopenTest)