Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-131234: Improve test_popen with more asserts #131235

Merged
merged 2 commits into from
Mar 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Lib/test/test_popen.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,21 @@ def test_return_code(self):
def test_contextmanager(self):
with os.popen("echo hello") as f:
self.assertEqual(f.read(), "hello\n")
self.assertFalse(f.closed)
self.assertTrue(f.closed)

def test_iterating(self):
with os.popen("echo hello") as f:
self.assertEqual(list(f), ["hello\n"])
self.assertFalse(f.closed)
self.assertTrue(f.closed)

def test_keywords(self):
with os.popen(cmd="exit 0", mode="w", buffering=-1):
pass
with os.popen(cmd="echo hello", mode="r", buffering=-1) as f:
self.assertEqual(f.read(), "hello\n")
self.assertFalse(f.closed)
self.assertTrue(f.closed)


if __name__ == "__main__":
unittest.main()
Loading