[3.12] gh-131234: Improve test_popen with more asserts (GH-131235) (#131241)

gh-131234: Improve `test_popen` with more asserts (GH-131235)
(cherry picked from commit fc07f863ee)

Co-authored-by: sobolevn <mail@sobolevn.me>
This commit is contained in:
Miss Islington (bot) 2025-03-14 12:54:56 +01:00 committed by GitHub
parent 6658ada1ea
commit 9a612a850c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -57,14 +57,21 @@ class PopenTest(unittest.TestCase):
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()