[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:
hpk 2007-02-11 16:11:49 +01:00
parent c52a54796d
commit 9b7fa6514b
2 changed files with 23 additions and 2 deletions

View File

@ -124,6 +124,9 @@ def win32_exec_cmd(cmd):
if '"' in cmd and not cmd.startswith('""'): if '"' in cmd and not cmd.startswith('""'):
cmd = '"%s"' % cmd cmd = '"%s"' % cmd
return popen3_exec_cmd(cmd)
def popen3_exec_cmd(cmd):
stdin, stdout, stderr = os.popen3(cmd) stdin, stdout, stderr = os.popen3(cmd)
out = stdout.read() out = stdout.read()
err = stderr.read() err = stderr.read()
@ -134,6 +137,8 @@ def win32_exec_cmd(cmd):
raise ExecutionFailed(status, status, cmd, out, err) raise ExecutionFailed(status, status, cmd, out, err)
return out return out
def pypy_exec_cmd(cmd):
return popen3_exec_cmd(cmd)
class ExecutionFailed(py.error.Error): class ExecutionFailed(py.error.Error):
def __init__(self, status, systemstatus, cmd, out, err): def __init__(self, status, systemstatus, cmd, out, err):
@ -149,8 +154,11 @@ class ExecutionFailed(py.error.Error):
# #
# choose correct platform-version # choose correct platform-version
# #
if sys.platform == 'win32': if sys.platform == 'win32':
cmdexec = win32_exec_cmd cmdexec = win32_exec_cmd
elif hasattr(sys, 'pypy') or hasattr(sys, 'pypy_objspaceclass'):
cmdexec = popen3_exec_cmd
else: else:
cmdexec = posix_exec_cmd cmdexec = posix_exec_cmd

View File

@ -1,4 +1,4 @@
from py import test import py
from py.process import cmdexec from py.process import cmdexec
class Test_exec_cmd: class Test_exec_cmd:
@ -7,7 +7,7 @@ class Test_exec_cmd:
assert out.strip() == 'hallo' assert out.strip() == 'hallo'
def test_simple_error(self): 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): def test_simple_error_exact_status(self):
try: try:
@ -23,3 +23,16 @@ class Test_exec_cmd:
assert hasattr(e, 'err') assert hasattr(e, 'err')
assert hasattr(e, 'out') assert hasattr(e, 'out')
assert e.err or 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