[pypy-svn] r72907 - in pypy/trunk/pypy/tool: . test

arigo at codespeak.net arigo at codespeak.net
Fri Mar 26 16:38:21 CET 2010


Author: arigo
Date: Fri Mar 26 16:38:20 2010
New Revision: 72907

Modified:
   pypy/trunk/pypy/tool/runsubprocess.py
   pypy/trunk/pypy/tool/test/test_runsubprocess.py
Log:
Correctly catch and re-raise exceptions, at least the
ones inheriting from EnvironmentError.


Modified: pypy/trunk/pypy/tool/runsubprocess.py
==============================================================================
--- pypy/trunk/pypy/tool/runsubprocess.py	(original)
+++ pypy/trunk/pypy/tool/runsubprocess.py	Fri Mar 26 16:38:20 2010
@@ -32,7 +32,10 @@
             sys.exit()
         assert operation.startswith('(')
         args = eval(operation)
-        results = _run(*args)
+        try:
+            results = _run(*args)
+        except EnvironmentError, e:
+            results = (None, str(e))
         sys.stdout.write('%r\n' % (results,))
         sys.stdout.flush()
 
@@ -47,4 +50,7 @@
         _child_stdin.flush()
         results = _child_stdout.readline()
         assert results.startswith('(')
-        return eval(results)
+        results = eval(results)
+        if results[0] is None:
+            raise OSError(results[1])
+        return results

Modified: pypy/trunk/pypy/tool/test/test_runsubprocess.py
==============================================================================
--- pypy/trunk/pypy/tool/test/test_runsubprocess.py	(original)
+++ pypy/trunk/pypy/tool/test/test_runsubprocess.py	Fri Mar 26 16:38:20 2010
@@ -1,6 +1,12 @@
 import py, os
 from pypy.tool.runsubprocess import run_subprocess
 
+def test_no_such_command():
+    py.test.raises(EnvironmentError, run_subprocess,
+                   'this_command_does_not_exist', [])
+    py.test.raises(EnvironmentError, run_subprocess,
+                   'this_command_does_not_exist', [])
+
 def test_echo():
     if not os.path.exists('/bin/echo'):
         py.test.skip("there is no /bin/echo")



More information about the Pypy-commit mailing list