[Python-checkins] r73934 - in python/branches/py3k: Lib/os.py Lib/test/test_popen.py Misc/NEWS

amaury.forgeotdarc python-checkins at python.org
Sat Jul 11 11:35:13 CEST 2009


Author: amaury.forgeotdarc
Date: Sat Jul 11 11:35:13 2009
New Revision: 73934
Log:
#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
Modified:
 python/branches/py3k/ (props changed)
 python/branches/py3k/Lib/os.py
 python/branches/py3k/Lib/test/test_popen.py
 python/branches/py3k/Misc/NEWS
Modified: python/branches/py3k/Lib/os.py
==============================================================================
--- python/branches/py3k/Lib/os.py	(original)
+++ python/branches/py3k/Lib/os.py	Sat Jul 11 11:35:13 2009
@@ -643,7 +643,13 @@
 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):
Modified: python/branches/py3k/Lib/test/test_popen.py
==============================================================================
--- python/branches/py3k/Lib/test/test_popen.py	(original)
+++ python/branches/py3k/Lib/test/test_popen.py	Sat Jul 11 11:35:13 2009
@@ -42,6 +42,13 @@
 )
 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)
 
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Sat Jul 11 11:35:13 2009
@@ -38,6 +38,9 @@
 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.
 


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /