]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-131234: Improve `test_popen` with more asserts (#131235)
authorsobolevn <mail@sobolevn.me>
Fri, 14 Mar 2025 11:38:31 +0000 (14:38 +0300)
committerGitHub <noreply@github.com>
Fri, 14 Mar 2025 11:38:31 +0000 (11:38 +0000)
Lib/test/test_popen.py

index e6bfc480cbd12c46938077657fed8525db8453ee..34cda35b17bdb0640166f78d4c2d8c6452cf7aed 100644 (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()