mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue #7461: objects returned by os.popen() should support the context manager protocol
This commit is contained in:
parent
9b14f6044c
commit
ac62535164
2 changed files with 12 additions and 0 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue