From 9b7fa6514bb281bc6a5844e7583dbb78c3748583 Mon Sep 17 00:00:00 2001 From: hpk Date: Sun, 11 Feb 2007 16:11:49 +0100 Subject: [PATCH] [svn r38470] try to have py.process.cmdexec run on top of PyPy (with its currentl limitations) --HG-- branch : trunk --- py/process/cmdexec.py | 8 ++++++++ py/process/testing/test_cmdexec.py | 17 +++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/py/process/cmdexec.py b/py/process/cmdexec.py index da2c7f425..54094d9fc 100644 --- a/py/process/cmdexec.py +++ b/py/process/cmdexec.py @@ -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 diff --git a/py/process/testing/test_cmdexec.py b/py/process/testing/test_cmdexec.py index f0a488ea7..5678004c8 100644 --- a/py/process/testing/test_cmdexec.py +++ b/py/process/testing/test_cmdexec.py @@ -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 + + + +