[svn r38470] try to have py.process.cmdexec run on top of PyPy
(with its currentl limitations) --HG-- branch : trunk
This commit is contained in:
parent
c52a54796d
commit
9b7fa6514b
|
@ -124,6 +124,9 @@ def win32_exec_cmd(cmd):
|
|||
if '"' in cmd and not cmd.startswith('""'):
|
||||
cmd = '"%s"' % cmd
|
||||
|
||||
return popen3_exec_cmd(cmd)
|
||||
|
||||
def popen3_exec_cmd(cmd):
|
||||
stdin, stdout, stderr = os.popen3(cmd)
|
||||
out = stdout.read()
|
||||
err = stderr.read()
|
||||
|
@ -134,6 +137,8 @@ def win32_exec_cmd(cmd):
|
|||
raise ExecutionFailed(status, status, cmd, out, err)
|
||||
return out
|
||||
|
||||
def pypy_exec_cmd(cmd):
|
||||
return popen3_exec_cmd(cmd)
|
||||
|
||||
class ExecutionFailed(py.error.Error):
|
||||
def __init__(self, status, systemstatus, cmd, out, err):
|
||||
|
@ -149,8 +154,11 @@ class ExecutionFailed(py.error.Error):
|
|||
#
|
||||
# choose correct platform-version
|
||||
#
|
||||
|
||||
if sys.platform == 'win32':
|
||||
cmdexec = win32_exec_cmd
|
||||
elif hasattr(sys, 'pypy') or hasattr(sys, 'pypy_objspaceclass'):
|
||||
cmdexec = popen3_exec_cmd
|
||||
else:
|
||||
cmdexec = posix_exec_cmd
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from py import test
|
||||
import py
|
||||
from py.process import cmdexec
|
||||
|
||||
class Test_exec_cmd:
|
||||
|
@ -7,7 +7,7 @@ class Test_exec_cmd:
|
|||
assert out.strip() == 'hallo'
|
||||
|
||||
def test_simple_error(self):
|
||||
test.raises (cmdexec.Error, cmdexec, 'exit 1')
|
||||
py.test.raises (cmdexec.Error, cmdexec, 'exit 1')
|
||||
|
||||
def test_simple_error_exact_status(self):
|
||||
try:
|
||||
|
@ -23,3 +23,16 @@ class Test_exec_cmd:
|
|||
assert hasattr(e, 'err')
|
||||
assert hasattr(e, 'out')
|
||||
assert e.err or e.out
|
||||
|
||||
def test_cmdexec_selection():
|
||||
from py.__.process import cmdexec
|
||||
if py.std.sys.platform == "win32":
|
||||
assert py.process.cmdexec == cmdexec.win32_exec_cmd
|
||||
elif hasattr(py.std.sys, 'pypy') or hasattr(py.std.sys, 'pypy_objspaceclass'):
|
||||
assert py.process.cmdexec == cmdexec.popen3_exec_cmd
|
||||
else:
|
||||
assert py.process.cmdexec == cmdexec.posix_exec_cmd
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue