[py-svn] r37985 - in py/trunk/py/test/rsession: . testing

hpk at codespeak.net hpk at codespeak.net
Mon Feb 5 23:46:33 CET 2007


Author: hpk
Date: Mon Feb  5 23:46:31 2007
New Revision: 37985

Modified:
   py/trunk/py/test/rsession/hostmanage.py
   py/trunk/py/test/rsession/testing/test_hostmanage.py
Log:
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. 


Modified: py/trunk/py/test/rsession/hostmanage.py
==============================================================================
--- py/trunk/py/test/rsession/hostmanage.py	(original)
+++ py/trunk/py/test/rsession/hostmanage.py	Mon Feb  5 23:46:31 2007
@@ -6,7 +6,6 @@
 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 @@
     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 @@
             except:
                 pass
             channel.gateway.exit()
+
+def gethomedir():
+    import os
+    homedir = os.environ.get('HOME', '')
+    if not homedir:
+        homedir = os.environ.get('HOMEPATH', '.')
+    return homedir

Modified: py/trunk/py/test/rsession/testing/test_hostmanage.py
==============================================================================
--- py/trunk/py/test/rsession/testing/test_hostmanage.py	(original)
+++ py/trunk/py/test/rsession/testing/test_hostmanage.py	Mon Feb  5 23:46:31 2007
@@ -37,6 +37,20 @@
         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 @@
         assert not self.dest.join("dir1", "dir2").check()
         assert self.dest.join("dir5","file").check()
         assert not self.dest.join("dir6").check()
+


More information about the py-svn mailing list