Merged revisions 73934 via svnmerge from
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>
Sat, 11 Jul 2009 09:37:09 +0000 (09:37 +0000)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>
Sat, 11 Jul 2009 09:37:09 +0000 (09:37 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r73934 | amaury.forgeotdarc | 2009-07-11 11:35:13 +0200 (sam., 11 juil. 2009) | 3 lines

  #6358: Merge r73933: Add basic tests for the return value of os.popen().close().
  And fix the implementation to make these tests pass with py3k
........

Lib/os.py
Lib/test/test_popen.py
Misc/NEWS

index 5dce0c1f24d6fa6d6886d674e37810b1f26fbe29..a59c5df1f6c87db707e092fc43b6520e9a1aa33d 100644 (file)
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -643,7 +643,13 @@ class _wrap_close:
         self._proc = proc
     def close(self):
         self._stream.close()
-        return self._proc.wait() << 8  # Shift left to match old behavior
+        returncode = self._proc.wait()
+        if returncode == 0:
+            return None
+        if name == 'nt':
+            return returncode
+        else:
+            return returncode << 8  # Shift left to match old behavior
     def __getattr__(self, name):
         return getattr(self._stream, name)
     def __iter__(self):
index d72879280cf6971b824609a4397fdf10cf291345..99ad41df749ba76f185552ebf95ab479351041cd 100644 (file)
@@ -42,6 +42,13 @@ class PopenTest(unittest.TestCase):
         )
         support.reap_children()
 
+    def test_return_code(self):
+        self.assertEqual(os.popen("exit 0").close(), None)
+        if os.name == 'nt':
+            self.assertEqual(os.popen("exit 42").close(), 42)
+        else:
+            self.assertEqual(os.popen("exit 42").close(), 42 << 8)
+
 def test_main():
     support.run_unittest(PopenTest)
 
index e1dba94e96cdd81a8573753e3750f6c7a614ee92..8ef35669e4c07fa7690390a7a790444ea96220eb 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -34,6 +34,9 @@ C-API
 Library
 -------
 
+- Issue #6358: The exit status of a command started with os.popen() was
+  reported differently than it did with python 2.x.
+
 - Issue #6323: The pdb debugger did not exit when running a script with a
   syntax error.