From 4af00f66823b3a58d70d4ccf16801f4452eeff05 Mon Sep 17 00:00:00 2001 From: hpk Date: Mon, 5 Feb 2007 23:46:31 +0100 Subject: [PATCH] [svn r37985] make sure that host.initgateway() will always have the other side chdir()ed to home, thus generalizing 37971 with respect to platform support and making it independent from gateway implementation details. --HG-- branch : trunk --- py/test/rsession/hostmanage.py | 22 ++++++++++++--------- py/test/rsession/testing/test_hostmanage.py | 15 ++++++++++++++ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/py/test/rsession/hostmanage.py b/py/test/rsession/hostmanage.py index 0dee38166..9c3494776 100644 --- a/py/test/rsession/hostmanage.py +++ b/py/test/rsession/hostmanage.py @@ -6,7 +6,6 @@ from py.__.test.rsession.master import MasterNode from py.__.test.rsession.slave import setup_slave from py.__.test.rsession import repevent -from py.__.execnet.register import PopenCmdGateway class HostInfo(object): """ Class trying to store all necessary attributes @@ -33,24 +32,22 @@ class HostInfo(object): def initgateway(self, python="python"): assert not hasattr(self, 'gw') if self.hostname == "localhost": - cmd = 'cd ~; %s -u -c "exec input()"' % python - gw = PopenCmdGateway(cmd) + gw = py.execnet.PopenGateway(python=python) else: gw = py.execnet.SshGateway(self.hostname, remotepython=python) self.gw = gw - channel = gw.remote_exec(""" + channel = gw.remote_exec(py.code.Source(gethomedir, """ import os targetdir = %r + homedir = gethomedir() if not os.path.isabs(targetdir): - homedir = os.environ.get('HOME', '') - if not homedir: - homedir = os.environ.get('HOMEPATH', '.') targetdir = os.path.join(homedir, targetdir) if not os.path.exists(targetdir): os.makedirs(targetdir) - channel.send(os.path.abspath(targetdir)) - """ % self.relpath) + os.chdir(homedir) + channel.send(targetdir) + """ % self.relpath)) self.gw_remotepath = channel.receive() #print "initialized", gw, "with remotepath", self.gw_remotepath if self.hostname == "localhost": @@ -177,3 +174,10 @@ class HostManager(object): except: pass channel.gateway.exit() + +def gethomedir(): + import os + homedir = os.environ.get('HOME', '') + if not homedir: + homedir = os.environ.get('HOMEPATH', '.') + return homedir diff --git a/py/test/rsession/testing/test_hostmanage.py b/py/test/rsession/testing/test_hostmanage.py index c4340e8f8..094a261a6 100644 --- a/py/test/rsession/testing/test_hostmanage.py +++ b/py/test/rsession/testing/test_hostmanage.py @@ -37,6 +37,20 @@ class TestHostInfo: py.test.raises((py.process.cmdexec.Error, IOError, EOFError), host.initgateway) + def test_remote_has_homedir_as_currentdir(self): + host = HostInfo("localhost") + old = py.path.local.get_temproot().chdir() + try: + host.initgateway() + channel = host.gw.remote_exec(""" + import os + channel.send(os.getcwd()) + """) + dir = channel.receive() + assert dir == py.path.local._gethomedir() + finally: + old.chdir() + def test_initgateway_localhost_relpath(self): name = "pytestcache-localhost" x = HostInfo("localhost:%s" % name) @@ -160,3 +174,4 @@ class TestHostManager(DirSetup): assert not self.dest.join("dir1", "dir2").check() assert self.dest.join("dir5","file").check() assert not self.dest.join("dir6").check() +