[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
This commit is contained in:
parent
102409a846
commit
4af00f6682
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue