From e383082b5bd54c90084fbce3b848edbeae950f1d Mon Sep 17 00:00:00 2001 From: hpk Date: Fri, 20 Mar 2009 16:36:45 +0100 Subject: [PATCH] [svn r63144] have socket and ssh gateways --HG-- branch : trunk --- py/__init__.py | 6 +++-- py/conftest.py | 37 +++++++++++++++++++++++++----- py/execnet/testing/test_gateway.py | 14 +++-------- py/execnet/testing/test_gwspec.py | 5 ++-- py/execnet/testing/test_xspec.py | 24 +++++++++++++++++++ py/execnet/xspec.py | 6 +++++ 6 files changed, 70 insertions(+), 22 deletions(-) diff --git a/py/__init__.py b/py/__init__.py index 4b5f1d528..0a92588ca 100644 --- a/py/__init__.py +++ b/py/__init__.py @@ -27,8 +27,8 @@ version = "1.0.0a1" initpkg(__name__, description = "pylib and py.test: agile development and test support library", - revision = int('$LastChangedRevision: 63089 $'.split(':')[1][:-1]), - lastchangedate = '$LastChangedDate: 2009-03-19 18:05:41 +0100 (Thu, 19 Mar 2009) $', + revision = int('$LastChangedRevision: 63144 $'.split(':')[1][:-1]), + lastchangedate = '$LastChangedDate: 2009-03-20 16:36:45 +0100 (Fri, 20 Mar 2009) $', version = version, url = "http://pylib.org", download_url = "http://codespeak.net/py/0.9.2/download.html", @@ -152,6 +152,8 @@ initpkg(__name__, 'execnet.PopenGateway' : ('./execnet/register.py', 'PopenGateway'), 'execnet.SshGateway' : ('./execnet/register.py', 'SshGateway'), 'execnet.GatewaySpec' : ('./execnet/gwmanage.py', 'GatewaySpec'), + 'execnet.XSpec' : ('./execnet/xspec.py', 'XSpec'), + 'execnet.makegateway' : ('./execnet/xspec.py', 'makegateway'), 'execnet.MultiGateway' : ('./execnet/multi.py', 'MultiGateway'), 'execnet.MultiChannel' : ('./execnet/multi.py', 'MultiChannel'), diff --git a/py/conftest.py b/py/conftest.py index 8fd2fadec..96564533f 100644 --- a/py/conftest.py +++ b/py/conftest.py @@ -1,20 +1,45 @@ -dist_rsync_roots = ['.'] # XXX - pytest_plugins = 'pytest_doctest', 'pytest_pytester', 'pytest_restdoc' - rsyncignore = ['c-extension/greenlet/build'] import py -class PylibTestPlugin: +class PylibTestconfigPlugin: + def pytest_pyfuncarg_specssh(self, pyfuncitem): + return getspecssh(pyfuncitem.config) + def pytest_pyfuncarg_specsocket(self, pyfuncitem): + return getsocketspec(pyfuncitem.config) + def pytest_addoption(self, parser): group = parser.addgroup("pylib", "py lib testing options") group.addoption('--sshhost', action="store", dest="sshhost", default=None, help=("target to run tests requiring ssh, e.g. " "user@codespeak.net")) + group.addoption('--gx', + action="append", dest="gspecs", default=None, + help=("add a global test environment, XSpec-syntax. ")), group.addoption('--runslowtests', action="store_true", dest="runslowtests", default=False, - help="run slow tests") + help=("run slow tests")) -ConftestPlugin = PylibTestPlugin +ConftestPlugin = PylibTestconfigPlugin +# configuration information for tests +def getgspecs(config=None): + if config is None: + config = py.test.config + return [py.execnet.XSpec(spec) + for spec in config.getvalueorskip("gspecs")] + +def getspecssh(config=None): + xspecs = getgspecs(config) + for spec in xspecs: + if spec.ssh: + if not py.path.local.sysfind("ssh"): + py.test.skip("command not found: ssh") + return spec + +def getsocketspec(config=None): + xspecs = getgspecs(config) + for spec in xspecs: + if spec.socket: + return spec diff --git a/py/execnet/testing/test_gateway.py b/py/execnet/testing/test_gateway.py index 20bcc24b6..5147f7002 100644 --- a/py/execnet/testing/test_gateway.py +++ b/py/execnet/testing/test_gateway.py @@ -542,8 +542,8 @@ class TestPopenGateway(PopenGatewayTestSetup, BasicRemoteExecution): ret = channel.receive() assert ret == 42 + @py.test.mark.xfail("fix needed: dying remote process does not cause waitclose() to fail") def test_waitclose_on_remote_killed(self): - py.test.skip("fix needed: dying remote process does not cause waitclose() to fail") gw = py.execnet.PopenGateway() channel = gw.remote_exec(""" import os @@ -591,21 +591,13 @@ class SocketGatewaySetup: ## cls.gw.exit() ## cls.proxygw.exit() -def getsshhost(withpython=False): - sshhost = py.test.config.getvalueorskip("sshhost") - if not withpython and sshhost.find(":") != -1: - sshhost = sshhost.split(":")[0] - ssh = py.path.local.sysfind("ssh") - if not ssh: - py.test.skip("command not found: ssh") - return sshhost - class TestSocketGateway(SocketGatewaySetup, BasicRemoteExecution): pass class TestSshGateway(BasicRemoteExecution): def setup_class(cls): - cls.sshhost = getsshhost() + from py.__.conftest import getspecssh + cls.sshhost = getspecssh().ssh cls.gw = py.execnet.SshGateway(cls.sshhost) def test_sshconfig_functional(self): diff --git a/py/execnet/testing/test_gwspec.py b/py/execnet/testing/test_gwspec.py index de1b7f2bf..96e02a646 100644 --- a/py/execnet/testing/test_gwspec.py +++ b/py/execnet/testing/test_gwspec.py @@ -3,7 +3,6 @@ """ import py -from test_gateway import getsshhost class TestGatewaySpec: """ @@ -88,8 +87,8 @@ class TestGatewaySpecAPI: assert py.std.sys.executable == py.std.sys.executable gw.exit() - def test_ssh(self): - sshhost = getsshhost() + def test_ssh(self, specssh): + sshhost = specssh.ssh spec = py.execnet.GatewaySpec("ssh:" + sshhost) gw = spec.makegateway() p = gw.remote_exec("import os ; channel.send(os.getcwd())").receive() diff --git a/py/execnet/testing/test_xspec.py b/py/execnet/testing/test_xspec.py index 5d9231ed2..aa5672847 100644 --- a/py/execnet/testing/test_xspec.py +++ b/py/execnet/testing/test_xspec.py @@ -72,3 +72,27 @@ class TestMakegateway: assert rinfo.executable == cpython26 assert rinfo.cwd == py.std.os.getcwd() assert rinfo.version_info[:2] == (2,6) + + def test_ssh(self, specssh): + sshhost = specssh.ssh + gw = py.execnet.makegateway("ssh=%s" % sshhost) + rinfo = gw._rinfo() + gw2 = py.execnet.SshGateway(sshhost) + rinfo2 = gw2._rinfo() + assert rinfo.executable == rinfo2.executable + assert rinfo.cwd == rinfo2.cwd + assert rinfo.version_info == rinfo2.version_info + + def test_socket(self, specsocket): + gw = py.execnet.makegateway("socket=%s" % specsocket.socket) + rinfo = gw._rinfo() + assert rinfo.executable + assert rinfo.cwd + assert rinfo.version_info + # we cannot instantiate a second gateway + + #gw2 = py.execnet.SocketGateway(*specsocket.socket.split(":")) + #rinfo2 = gw2._rinfo() + #assert rinfo.executable == rinfo2.executable + #assert rinfo.cwd == rinfo2.cwd + #assert rinfo.version_info == rinfo2.version_info diff --git a/py/execnet/xspec.py b/py/execnet/xspec.py index e322d0b47..edd095c92 100644 --- a/py/execnet/xspec.py +++ b/py/execnet/xspec.py @@ -31,5 +31,11 @@ def makegateway(spec): spec = XSpec(spec) if spec.popen: gw = py.execnet.PopenGateway(python=spec.python) + elif spec.ssh: + gw = py.execnet.SshGateway(spec.ssh, remotepython=spec.python) + elif spec.socket: + assert not spec.python, "socket: specifying python executables not supported" + hostport = spec.socket.split(":") + gw = py.execnet.SocketGateway(*hostport) gw.spec = spec return gw