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

hpk at codespeak.net hpk at codespeak.net
Sat Feb 10 09:52:24 CET 2007


Author: hpk
Date: Sat Feb 10 09:52:22 2007
New Revision: 38352

Modified:
   py/trunk/py/test/rsession/hostmanage.py
   py/trunk/py/test/rsession/slave.py
   py/trunk/py/test/rsession/testing/test_hostmanage.py
Log:
made localhost inplace handling safer (and more
redundant, there is an additional flag now,
and host.gw_remotepath is None for localhost-inplace
hosts)


Modified: py/trunk/py/test/rsession/hostmanage.py
==============================================================================
--- py/trunk/py/test/rsession/hostmanage.py	(original)
+++ py/trunk/py/test/rsession/hostmanage.py	Sat Feb 10 09:52:22 2007
@@ -12,14 +12,17 @@
     for host
     """
     _hostname2list = {}
-    localdest = None
     
     def __init__(self, spec):
         parts = spec.split(':', 1)
         self.hostname = parts.pop(0)
         self.relpath = parts and parts.pop(0) or ""
-        if not self.relpath and self.hostname != "localhost":
-            self.relpath = "pytestcache-%s" % self.hostname
+        if self.hostname == "localhost" and not self.relpath:
+            self.inplacelocal = True
+        else:
+            self.inplacelocal = False 
+            if not self.relpath:
+                self.relpath = "pytestcache-%s" % self.hostname
         assert not parts
         self.hostid = self._getuniqueid(self.hostname) 
 
@@ -35,20 +38,22 @@
         else:
             self.gw = py.execnet.SshGateway(self.hostname, 
                                             remotepython=python)
-        relpath = self.relpath or topdir 
-        assert relpath 
-        channel = self.gw.remote_exec(py.code.Source(
-            gethomedir, 
-            getpath_relto_home, """
-            import os
-            os.chdir(gethomedir())
-            path = %r
-            if path:
-                path = getpath_relto_home(path)
-            channel.send(path)
-            """ % str(relpath)
-        ))
-        self.gw_remotepath = channel.receive()
+        if self.inplacelocal:
+            self.gw.remote_exec(py.code.Source(
+                sethomedir, "sethomedir()"
+            )).waitclose()
+            self.gw_remotepath = None
+        else:
+            relpath = self.relpath or topdir or ""
+            assert relpath
+            channel = self.gw.remote_exec(py.code.Source(
+                gethomedir,
+                sethomedir, "sethomedir()", 
+                getpath_relto_home, """
+                channel.send(getpath_relto_home(%r))
+            """ % relpath,
+            ))
+            self.gw_remotepath = channel.receive()
 
     def __str__(self):
         return "<HostInfo %s:%s>" % (self.hostname, self.relpath)
@@ -88,10 +93,11 @@
     def add_target_host(self, host, destrelpath="", reporter=lambda x: None):
         remotepath = host.gw_remotepath 
         key = host.hostname, host.relpath
-        if destrelpath:
-            remotepath = os.path.join(remotepath, destrelpath)
-        if host.hostname == "localhost" and remotepath == self._sourcedir:
+        if host.inplacelocal: 
+            remotepath = self._sourcedir
             self._synced[key] = True
+        elif destrelpath:
+            remotepath = os.path.join(remotepath, destrelpath)
         synced = key in self._synced 
         reporter(repevent.HostRSyncing(host, py.path.local(self._sourcedir), 
                                        remotepath, synced))
@@ -187,4 +193,11 @@
     if not os.path.isabs(targetpath):
         homedir = gethomedir()
         targetpath = os.path.join(homedir, targetpath)
-    return targetpath
+    return os.path.normpath(targetpath)
+
+def sethomedir():
+    import os
+    homedir = os.environ.get('HOME', '')
+    if not homedir:
+        homedir = os.environ.get('HOMEPATH', '.')
+    os.chdir(homedir)

Modified: py/trunk/py/test/rsession/slave.py
==============================================================================
--- py/trunk/py/test/rsession/slave.py	(original)
+++ py/trunk/py/test/rsession/slave.py	Sat Feb 10 09:52:22 2007
@@ -111,7 +111,11 @@
     channel = host.gw.remote_exec(str(py.code.Source(setup, "setup()")))
     configrepr = config.make_repr(defaultconftestnames)
     #print "sending configrepr", configrepr
-    channel.send(host.gw_remotepath)
+    topdir = host.gw_remotepath 
+    if topdir is None:
+        assert host.inplacelocal
+        topdir = config.topdir
+    channel.send(str(topdir))
     channel.send(configrepr) 
     return channel
 

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	Sat Feb 10 09:52:22 2007
@@ -4,7 +4,7 @@
 
 import py
 from py.__.test.rsession.hostmanage import HostRSync, HostInfo, HostManager
-from py.__.test.rsession.hostmanage import gethomedir, getpath_relto_home
+from py.__.test.rsession.hostmanage import sethomedir, gethomedir, getpath_relto_home
 from py.__.test.rsession import repevent
 
 class DirSetup:
@@ -27,11 +27,13 @@
         x = HostInfo("localhost:")
         assert x.hostname == "localhost"
         assert not x.relpath
+        assert x.inplacelocal 
 
     def test_path(self):
         x = HostInfo("localhost:/tmp")
         assert x.relpath == "/tmp"
         assert x.hostname == "localhost"
+        assert not x.inplacelocal 
 
     def test_hostid(self):
         x = HostInfo("localhost:")
@@ -115,6 +117,26 @@
         assert 'file.txt' in basenames
         assert 'somedir' in basenames
 
+    def test_hrsync_localhost_inplace(self):
+        h1 = HostInfo("localhost")
+        events = []
+        rsync = HostRSync(self.source)
+        h1.initgateway()
+        rsync.add_target_host(h1, reporter=events.append)
+        assert events
+        l = [x for x in events 
+                if isinstance(x, repevent.HostRSyncing)]
+        assert len(l) == 1
+        ev = l[0]
+        assert ev.host == h1
+        assert ev.root == ev.remotepath 
+        l = [x for x in events 
+                if isinstance(x, repevent.HostRSyncRootReady)]
+        assert len(l) == 1
+        ev = l[0]
+        assert ev.root == self.source
+        assert ev.host == h1
+
     def test_hrsync_one_host(self):
         h1 = self._gethostinfo()
         finished = []
@@ -200,11 +222,24 @@
         events = []
         hm.init_rsync(events.append)
         for host in hosts:
-            assert host.gw_remotepath == str(self.source)
+            assert host.inplacelocal
+            assert host.gw_remotepath is None
             assert not host.relpath 
         assert events
 
 def test_getpath_relto_home():
     x = getpath_relto_home("hello")
     assert x == py.path.local._gethomedir().join("hello")
+    x = getpath_relto_home(".")
+    assert x == py.path.local._gethomedir()
+
+def test_sethomedir():
+    old = py.path.local.get_temproot().chdir()
+    try:
+        sethomedir()
+        curdir = py.path.local()
+    finally:
+        old.chdir()
+
+    assert py.path.local._gethomedir() == curdir
 



More information about the pytest-commit mailing list