[py-svn] r63139 - in py/trunk/py/execnet: . testing

hpk at codespeak.net hpk at codespeak.net
Fri Mar 20 15:04:16 CET 2009


Author: hpk
Date: Fri Mar 20 15:04:15 2009
New Revision: 63139

Modified:
   py/trunk/py/execnet/gateway.py
   py/trunk/py/execnet/testing/test_gateway.py
Log:
make _rinfo() cache results by default


Modified: py/trunk/py/execnet/gateway.py
==============================================================================
--- py/trunk/py/execnet/gateway.py	(original)
+++ py/trunk/py/execnet/gateway.py	Fri Mar 20 15:04:15 2009
@@ -241,16 +241,18 @@
         chan.setcallback(callback)
         return chan.id 
 
-    def _rinfo(self):
+    def _rinfo(self, update=False):
         """ return some sys/env information from remote. """
-        return RInfo(**self.remote_exec("""
-            import sys, os
-            channel.send(dict(
-                executable = sys.executable, 
-                version_info = sys.version_info, 
-                curdir = os.getcwd(),
-            ))
-        """).receive())
+        if update or not hasattr(self, '_cache_rinfo'):
+            self._cache_rinfo = RInfo(**self.remote_exec("""
+                import sys, os
+                channel.send(dict(
+                    executable = sys.executable, 
+                    version_info = sys.version_info, 
+                    cwd = os.getcwd(),
+                ))
+            """).receive())
+        return self._cache_rinfo
 
     # _____________________________________________________________________
     #

Modified: py/trunk/py/execnet/testing/test_gateway.py
==============================================================================
--- py/trunk/py/execnet/testing/test_gateway.py	(original)
+++ py/trunk/py/execnet/testing/test_gateway.py	Fri Mar 20 15:04:15 2009
@@ -444,9 +444,22 @@
     def test__rinfo(self):
         rinfo = self.gw._rinfo()
         assert rinfo.executable 
-        assert rinfo.curdir 
+        assert rinfo.cwd 
         assert rinfo.version_info 
-        
+        old = self.gw.remote_exec("""
+            import os.path
+            cwd = os.getcwd()
+            channel.send(os.path.basename(cwd))
+            os.chdir('..')
+        """).receive()
+        try:
+            rinfo2 = self.gw._rinfo()
+            assert rinfo2.cwd == rinfo.cwd
+            rinfo3 = self.gw._rinfo(update=True)
+            assert rinfo3.cwd != rinfo2.cwd
+        finally:
+            self.gw._cache_rinfo = rinfo
+            self.gw.remote_exec("import os ; os.chdir(%r)" % old).waitclose()
 
 class BasicCmdbasedRemoteExecution(BasicRemoteExecution):
     def test_cmdattr(self):
@@ -487,10 +500,11 @@
 #        assert x == 17 
 
 class TestPopenGateway(PopenGatewayTestSetup, BasicRemoteExecution):
-    def test_remote_info_popen(self):
+    def test_rinfo_popen(self):
+        #rinfo = py.execnet.PopenGateway()._rinfo()
         rinfo = self.gw._rinfo()
         assert rinfo.executable == py.std.sys.executable 
-        assert rinfo.curdir == py.std.os.getcwd()
+        assert rinfo.cwd == py.std.os.getcwd()
         assert rinfo.version_info == py.std.sys.version_info
 
     def test_chdir_separation(self):



More information about the pytest-commit mailing list