From 5f3fac94b6234b1d58d1b32562e7f71716817a85 Mon Sep 17 00:00:00 2001 From: hpk Date: Fri, 20 Mar 2009 15:20:40 +0100 Subject: [PATCH] [svn r63141] makegateway works for plain popen and popen+python-version --HG-- branch : trunk --- py/execnet/testing/test_xspec.py | 94 +++++++++++++++++++++++--------- py/execnet/xspec.py | 12 +++- 2 files changed, 76 insertions(+), 30 deletions(-) diff --git a/py/execnet/testing/test_xspec.py b/py/execnet/testing/test_xspec.py index 706ed8cf8..5d9231ed2 100644 --- a/py/execnet/testing/test_xspec.py +++ b/py/execnet/testing/test_xspec.py @@ -1,34 +1,74 @@ import py -def test_XSpec_attributes(): - XSpec = py.execnet.XSpec - spec = XSpec("socket=192.168.102.2:8888//python=c:/this/python2.5//path=d:\hello") - assert spec.socket == "192.168.102.2:8888" - assert spec.python == "c:/this/python2.5" - assert spec.path == "d:\hello" - assert spec.xyz is None +XSpec = py.execnet.XSpec - py.test.raises(AttributeError, "spec._hello") +class TestXSpec: + def test_attributes(self): + spec = XSpec("socket=192.168.102.2:8888//python=c:/this/python2.5//path=d:\hello") + assert spec.socket == "192.168.102.2:8888" + assert spec.python == "c:/this/python2.5" + assert spec.path == "d:\hello" + assert spec.xyz is None - spec = XSpec("socket=192.168.102.2:8888//python=python2.5") - assert spec.socket == "192.168.102.2:8888" - assert spec.python == "python2.5" - assert spec.path is None + py.test.raises(AttributeError, "spec._hello") - spec = XSpec("ssh=user@host//path=/hello/this//python=/usr/bin/python2.5") - assert spec.ssh == "user@host" - assert spec.python == "/usr/bin/python2.5" - assert spec.path == "/hello/this" + spec = XSpec("socket=192.168.102.2:8888//python=python2.5") + assert spec.socket == "192.168.102.2:8888" + assert spec.python == "python2.5" + assert spec.path is None - spec = XSpec("popen") - assert spec.popen == True + spec = XSpec("ssh=user@host//path=/hello/this//python=/usr/bin/python2.5") + assert spec.ssh == "user@host" + assert spec.python == "/usr/bin/python2.5" + assert spec.path == "/hello/this" -@py.test.mark.xfail -def test_makegateway_popen(): - spec = py.execnet.XSpec("popen") - gw = py.execnet.makegateway(spec) - assert gw.spec == spec - rinfo = gw.remote_info() - assert rinfo.executable == py.std.sys.executable - assert rinfo.curdir == py.std.os.getcwd() - assert rinfo.version_info == py.std.sys.version_info + spec = XSpec("popen") + assert spec.popen == True + + def test__samefilesystem(self): + assert XSpec("popen")._samefilesystem() + assert XSpec("popen//python=123")._samefilesystem() + assert not XSpec("popen//path=hello")._samefilesystem() + +class TestMakegateway: + def test_popen(self): + gw = py.execnet.makegateway("popen") + assert gw.spec.python == None + rinfo = gw._rinfo() + assert rinfo.executable == py.std.sys.executable + assert rinfo.cwd == py.std.os.getcwd() + assert rinfo.version_info == py.std.sys.version_info + + def test_popen_explicit(self): + gw = py.execnet.makegateway("popen//python=%s" % py.std.sys.executable) + assert gw.spec.python == py.std.sys.executable + rinfo = gw._rinfo() + assert rinfo.executable == py.std.sys.executable + assert rinfo.cwd == py.std.os.getcwd() + assert rinfo.version_info == py.std.sys.version_info + + def test_popen_cpython24(self): + for trypath in ('python2.4', r'C:\Python24\python.exe'): + cpython24 = py.path.local.sysfind(trypath) + if cpython24 is not None: + break + else: + py.test.skip("cpython2.4 not found") + gw = py.execnet.makegateway("popen//python=%s" % cpython24) + rinfo = gw._rinfo() + assert rinfo.executable == cpython24 + assert rinfo.cwd == py.std.os.getcwd() + assert rinfo.version_info[:2] == (2,4) + + def test_popen_cpython26(self): + for trypath in ('python2.6', r'C:\Python26\python.exe'): + cpython26 = py.path.local.sysfind(trypath) + if cpython26 is not None: + break + else: + py.test.skip("cpython2.6 not found") + gw = py.execnet.makegateway("popen//python=%s" % cpython26) + rinfo = gw._rinfo() + assert rinfo.executable == cpython26 + assert rinfo.cwd == py.std.os.getcwd() + assert rinfo.version_info[:2] == (2,6) diff --git a/py/execnet/xspec.py b/py/execnet/xspec.py index b9eaffc39..e322d0b47 100644 --- a/py/execnet/xspec.py +++ b/py/execnet/xspec.py @@ -23,7 +23,13 @@ class XSpec: raise AttributeError(name) return None -def makegateway(spec): - pass + def _samefilesystem(self): + return bool(self.popen and not self.path) - +def makegateway(spec): + if not isinstance(spec, XSpec): + spec = XSpec(spec) + if spec.popen: + gw = py.execnet.PopenGateway(python=spec.python) + gw.spec = spec + return gw