[py-svn] r63154 - in py/trunk/py/test/dsession: . testing

hpk at codespeak.net hpk at codespeak.net
Fri Mar 20 20:33:06 CET 2009


Author: hpk
Date: Fri Mar 20 20:33:05 2009
New Revision: 63154

Added:
   py/trunk/py/test/dsession/nodemanage.py
      - copied, changed from r63153, py/trunk/py/test/dsession/hostmanage.py
   py/trunk/py/test/dsession/testing/test_nodemanage.py
      - copied, changed from r63153, py/trunk/py/test/dsession/testing/test_hostmanage.py
Removed:
   py/trunk/py/test/dsession/hostmanage.py
   py/trunk/py/test/dsession/testing/test_hostmanage.py
Modified:
   py/trunk/py/test/dsession/dsession.py
   py/trunk/py/test/dsession/testing/test_masterslave.py
Log:
use "node" instead of "host" everywhere 


Modified: py/trunk/py/test/dsession/dsession.py
==============================================================================
--- py/trunk/py/test/dsession/dsession.py	(original)
+++ py/trunk/py/test/dsession/dsession.py	Fri Mar 20 20:33:05 2009
@@ -9,6 +9,7 @@
 from py.__.test.runner import basic_run_report, basic_collect_report
 from py.__.test.session import Session
 from py.__.test import outcome 
+from py.__.test.dsession.nodemanage import NodeManager
 
 import Queue 
 
@@ -97,9 +98,9 @@
     def main(self, colitems=None):
         colitems = self.getinitialitems(colitems)
         self.sessionstarts()
-        self.setup_nodes()
+        self.setup()
         exitstatus = self.loop(colitems)
-        self.teardown_nodes()
+        self.teardown()
         self.sessionfinishes() 
         return exitstatus
 
@@ -235,15 +236,14 @@
         rep = event.ItemTestReport(item, when="???", excinfo=longrepr)
         self.bus.notify("itemtestreport", rep)
 
-    def setup_nodes(self):
+    def setup(self):
         """ setup any neccessary resources ahead of the test run. """
-        from py.__.test.dsession.hostmanage import HostManager
-        self.hm = HostManager(self.config)
-        self.hm.setup_hosts(putevent=self.queue.put)
+        self.nodemanager = NodeManager(self.config)
+        self.nodemanager.setup_nodes(putevent=self.queue.put)
 
-    def teardown_nodes(self):
+    def teardown(self):
         """ teardown any resources after a test run. """ 
-        self.hm.teardown_hosts()
+        self.nodemanager.teardown_nodes()
 
 # debugging function
 def dump_picklestate(item):

Deleted: /py/trunk/py/test/dsession/hostmanage.py
==============================================================================
--- /py/trunk/py/test/dsession/hostmanage.py	Fri Mar 20 20:33:05 2009
+++ (empty file)
@@ -1,125 +0,0 @@
-import py
-import sys, os
-from py.__.test.dsession.masterslave import MasterNode
-from py.__.execnet.gwmanage import GatewayManager
-from py.__.test import event
-
-def getxspecs(config):
-    if config.option.numprocesses:
-        if config.option.executable:
-            s = 'popen//python=%s' % config.option.executable
-        else:
-            s = 'popen'
-        xspecs = [s] * config.option.numprocesses
-    else:
-        xspecs = config.option.xspecs
-        if not xspecs:
-            xspecs = config.getvalue("xspecs")
-    assert xspecs is not None
-    #print "option value for xspecs", xspecs
-    return [py.execnet.XSpec(x) for x in xspecs]
-
-def getconfigroots(config):
-    roots = config.option.rsyncdirs
-    if roots:
-        roots = [py.path.local(x) for x in roots.split(',')]
-    else:
-        roots = []
-    conftestroots = config.getconftest_pathlist("rsyncdirs")
-    if conftestroots:
-        roots.extend(conftestroots)
-    pydir = py.path.local(py.__file__).dirpath()
-    for root in roots:
-        if not root.check():
-            raise ValueError("rsyncdir doesn't exist: %r" %(root,))
-        if pydir is not None and root.basename == "py":
-            if root != pydir:
-                raise ValueError("root %r conflicts with current %r" %(root, pydir))
-            pydir = None
-    if pydir is not None:
-        roots.append(pydir)
-    return roots 
-    
-class HostManager(object):
-    def __init__(self, config, hosts=None):
-        self.config = config 
-        if hosts is None:
-            hosts = getxspecs(self.config)
-        self.roots = getconfigroots(config)
-        self.gwmanager = GatewayManager(hosts)
-        self.nodes = []
-
-    def makegateways(self):
-        # we change to the topdir sot that 
-        # PopenGateways will have their cwd 
-        # such that unpickling configs will 
-        # pick it up as the right topdir 
-        # (for other gateways this chdir is irrelevant)
-        old = self.config.topdir.chdir()  
-        try:
-            self.gwmanager.makegateways()
-        finally:
-            old.chdir()
-        self.trace_hoststatus()
-
-    def trace_hoststatus(self):
-        if self.config.option.debug:
-            for ch, result in self.gwmanager.multi_exec("""
-                import sys, os
-                channel.send((sys.executable, os.getcwd(), sys.path))
-            """).receive_each(withchannel=True):
-                self.trace("spec %r, execuable %r, cwd %r, syspath %r" %(
-                    ch.gateway.spec, result[0], result[1], result[2]))
-
-    def config_getignores(self):
-        return self.config.getconftest_pathlist("rsyncignore")
-
-    def rsync_roots(self):
-        """ make sure that all remote gateways
-            have the same set of roots in their
-            current directory. 
-        """
-        self.makegateways()
-        options = {
-            'ignores': self.config_getignores(), 
-            'verbose': self.config.option.verbose,
-        }
-        if self.roots:
-            # send each rsync root
-            for root in self.roots:
-                self.gwmanager.rsync(root, **options)
-        else: 
-            XXX # do we want to care for situations without explicit rsyncdirs? 
-            # we transfer our topdir as the root
-            self.gwmanager.rsync(self.config.topdir, **options)
-            # and cd into it 
-            self.gwmanager.multi_chdir(self.config.topdir.basename, inplacelocal=False)
-        self.config.bus.notify("rsyncfinished", event.RsyncFinished())
-
-    def trace(self, msg):
-        self.config.bus.notify("trace", "testhostmanage", msg)
-
-    def setup_hosts(self, putevent):
-        self.rsync_roots()
-        nice = self.config.getvalue("dist_nicelevel")
-        if nice != 0:
-            self.gwmanager.multi_exec("""
-                import os
-                if hasattr(os, 'nice'): 
-                    os.nice(%r)
-            """ % nice).waitclose()
-
-        self.trace_hoststatus()
-        multigw = self.gwmanager.getgateways(inplacelocal=False, remote=True)
-        multigw.remote_exec("""
-            import os, sys
-            sys.path.insert(0, os.getcwd())
-        """).waitclose()
-
-        for gateway in self.gwmanager.gateways:
-            node = MasterNode(gateway, self.config, putevent)
-            self.nodes.append(node) 
-
-    def teardown_hosts(self):
-        # XXX teardown nodes? 
-        self.gwmanager.exit()

Copied: py/trunk/py/test/dsession/nodemanage.py (from r63153, py/trunk/py/test/dsession/hostmanage.py)
==============================================================================
--- py/trunk/py/test/dsession/hostmanage.py	(original)
+++ py/trunk/py/test/dsession/nodemanage.py	Fri Mar 20 20:33:05 2009
@@ -40,13 +40,13 @@
         roots.append(pydir)
     return roots 
     
-class HostManager(object):
-    def __init__(self, config, hosts=None):
+class NodeManager(object):
+    def __init__(self, config, specs=None):
         self.config = config 
-        if hosts is None:
-            hosts = getxspecs(self.config)
+        if specs is None:
+            specs = getxspecs(self.config)
         self.roots = getconfigroots(config)
-        self.gwmanager = GatewayManager(hosts)
+        self.gwmanager = GatewayManager(specs)
         self.nodes = []
 
     def makegateways(self):
@@ -60,9 +60,9 @@
             self.gwmanager.makegateways()
         finally:
             old.chdir()
-        self.trace_hoststatus()
+        self.trace_nodestatus()
 
-    def trace_hoststatus(self):
+    def trace_nodestatus(self):
         if self.config.option.debug:
             for ch, result in self.gwmanager.multi_exec("""
                 import sys, os
@@ -97,9 +97,9 @@
         self.config.bus.notify("rsyncfinished", event.RsyncFinished())
 
     def trace(self, msg):
-        self.config.bus.notify("trace", "testhostmanage", msg)
+        self.config.bus.notify("trace", "nodemanage", msg)
 
-    def setup_hosts(self, putevent):
+    def setup_nodes(self, putevent):
         self.rsync_roots()
         nice = self.config.getvalue("dist_nicelevel")
         if nice != 0:
@@ -109,7 +109,7 @@
                     os.nice(%r)
             """ % nice).waitclose()
 
-        self.trace_hoststatus()
+        self.trace_nodestatus()
         multigw = self.gwmanager.getgateways(inplacelocal=False, remote=True)
         multigw.remote_exec("""
             import os, sys
@@ -120,6 +120,6 @@
             node = MasterNode(gateway, self.config, putevent)
             self.nodes.append(node) 
 
-    def teardown_hosts(self):
+    def teardown_nodes(self):
         # XXX teardown nodes? 
         self.gwmanager.exit()

Deleted: /py/trunk/py/test/dsession/testing/test_hostmanage.py
==============================================================================
--- /py/trunk/py/test/dsession/testing/test_hostmanage.py	Fri Mar 20 20:33:05 2009
+++ (empty file)
@@ -1,154 +0,0 @@
-
-""" RSync filter test
-"""
-
-import py
-from py.__.test.dsession.hostmanage import HostManager, getxspecs, getconfigroots
-
-from py.__.test import event
-
-def pytest_pyfuncarg_source(pyfuncitem):
-    return py.test.ensuretemp(pyfuncitem.getmodpath()).mkdir("source")
-def pytest_pyfuncarg_dest(pyfuncitem):
-    dest = py.test.ensuretemp(pyfuncitem.getmodpath()).mkdir("dest")
-    return dest 
-
-class TestHostManager:
-    @py.test.mark.xfail("consider / forbid implicit rsyncdirs?")
-    def test_hostmanager_rsync_roots_no_roots(self, source, dest):
-        source.ensure("dir1", "file1").write("hello")
-        config = py.test.config._reparse([source])
-        hm = HostManager(config, hosts=["popen::%s" % dest])
-        assert hm.config.topdir == source == config.topdir
-        hm.rsync_roots()
-        p, = hm.gwmanager.multi_exec("import os ; channel.send(os.getcwd())").receive_each()
-        p = py.path.local(p)
-        print "remote curdir", p
-        assert p == dest.join(config.topdir.basename)
-        assert p.join("dir1").check()
-        assert p.join("dir1", "file1").check()
-
-    def test_popen_rsync_subdir(self, testdir, source, dest):
-        dir1 = source.mkdir("dir1")
-        dir2 = dir1.mkdir("dir2")
-        dir2.ensure("hello")
-        for rsyncroot in (dir1, source):
-            dest.remove()
-            hm = HostManager(testdir.parseconfig(
-                "--tx", "popen//chdir=%s" % dest,
-                "--rsyncdirs", rsyncroot,
-                source, 
-            ))
-            assert hm.config.topdir == source
-            hm.rsync_roots() 
-            if rsyncroot == source:
-                dest = dest.join("source")
-            assert dest.join("dir1").check()
-            assert dest.join("dir1", "dir2").check()
-            assert dest.join("dir1", "dir2", 'hello').check()
-
-    def test_init_rsync_roots(self, source, dest):
-        dir2 = source.ensure("dir1", "dir2", dir=1)
-        source.ensure("dir1", "somefile", dir=1)
-        dir2.ensure("hello")
-        source.ensure("bogusdir", "file")
-        source.join("conftest.py").write(py.code.Source("""
-            rsyncdirs = ['dir1/dir2']
-        """))
-        session = py.test.config._reparse([source]).initsession()
-        hm = HostManager(session.config, 
-                         hosts=["popen//chdir=%s" % dest])
-        hm.rsync_roots()
-        assert dest.join("dir2").check()
-        assert not dest.join("dir1").check()
-        assert not dest.join("bogus").check()
-
-    def test_rsyncignore(self, source, dest):
-        dir2 = source.ensure("dir1", "dir2", dir=1)
-        dir5 = source.ensure("dir5", "dir6", "bogus")
-        dirf = source.ensure("dir5", "file")
-        dir2.ensure("hello")
-        source.join("conftest.py").write(py.code.Source("""
-            rsyncdirs = ['dir1', 'dir5']
-            rsyncignore = ['dir1/dir2', 'dir5/dir6']
-        """))
-        session = py.test.config._reparse([source]).initsession()
-        hm = HostManager(session.config,
-                         hosts=["popen//chdir=%s" % dest])
-        hm.rsync_roots()
-        assert dest.join("dir1").check()
-        assert not dest.join("dir1", "dir2").check()
-        assert dest.join("dir5","file").check()
-        assert not dest.join("dir6").check()
-
-    def test_optimise_popen(self, source, dest):
-        hosts = ["popen"] * 3
-        source.join("conftest.py").write("rsyncdirs = ['a']")
-        source.ensure('a', dir=1)
-        config = py.test.config._reparse([source])
-        hm = HostManager(config, hosts=hosts)
-        hm.rsync_roots()
-        for gwspec in hm.gwmanager.specs:
-            assert gwspec._samefilesystem()
-            assert not gwspec.chdir
-
-    def test_setup_hosts_DEBUG(self, source, EventRecorder):
-        hosts = ["popen"] * 2
-        source.join("conftest.py").write("rsyncdirs = ['a']")
-        source.ensure('a', dir=1)
-        config = py.test.config._reparse([source, '--debug'])
-        assert config.option.debug
-        hm = HostManager(config, hosts=hosts)
-        evrec = EventRecorder(config.bus, debug=True)
-        hm.setup_hosts(putevent=[].append)
-        for host in hm.gwmanager.specs:
-            l = evrec.getnamed("trace")
-            print evrec.events
-            assert l 
-        hm.teardown_hosts()
-
-    def test_ssh_setup_hosts(self, specssh, testdir):
-        testdir.makepyfile(__init__="", test_x="""
-            def test_one():
-                pass
-        """)
-        sorter = testdir.inline_run("-d", "--rsyncdirs=%s" % testdir.tmpdir, 
-                "--tx=%s" % specssh, testdir.tmpdir)
-        ev = sorter.getfirstnamed("itemtestreport")
-        assert ev.passed 
-
-class TestOptionsAndConfiguration:
-    def test_getxspecs_numprocesses(self, testdir):
-        config = testdir.parseconfig("-n3")
-        xspecs = getxspecs(config)
-        assert len(xspecs) == 3
-
-    def test_getxspecs(self, testdir):
-        config = testdir.parseconfig("--tx=popen", "--tx", "ssh=xyz")
-        xspecs = getxspecs(config)
-        assert len(xspecs) == 2
-        print xspecs
-        assert xspecs[0].popen 
-        assert xspecs[1].ssh == "xyz"
-
-    def test_getconfigroots(self, testdir):
-        config = testdir.parseconfig('--rsyncdirs=' + str(testdir.tmpdir))
-        roots = getconfigroots(config)
-        assert len(roots) == 1 + 1 
-        assert testdir.tmpdir in roots
-
-    def test_getconfigroots_with_conftest(self, testdir):
-        testdir.chdir()
-        p = py.path.local()
-        for bn in 'x y z'.split():
-            p.mkdir(bn)
-        testdir.makeconftest("""
-            rsyncdirs= 'x', 
-        """)
-        config = testdir.parseconfig(testdir.tmpdir, '--rsyncdirs=y,z')
-        roots = getconfigroots(config)
-        assert len(roots) == 3 + 1 
-        assert py.path.local('y') in roots 
-        assert py.path.local('z') in roots 
-        assert testdir.tmpdir.join('x') in roots 
-

Modified: py/trunk/py/test/dsession/testing/test_masterslave.py
==============================================================================
--- py/trunk/py/test/dsession/testing/test_masterslave.py	(original)
+++ py/trunk/py/test/dsession/testing/test_masterslave.py	Fri Mar 20 20:33:05 2009
@@ -49,9 +49,10 @@
         return self.node 
 
     def finalize(self):
-        if hasattr(self, 'host'):
-            print "exiting:", self.gateway
-            self.gateway.exit()
+        if hasattr(self, 'node'):
+            gw = self.node.gateway
+            print "exiting:", gw
+            gw.exit()
 
 def pytest_pyfuncarg_mysetup(pyfuncitem):
     mysetup = MySetup(pyfuncitem)

Copied: py/trunk/py/test/dsession/testing/test_nodemanage.py (from r63153, py/trunk/py/test/dsession/testing/test_hostmanage.py)
==============================================================================
--- py/trunk/py/test/dsession/testing/test_hostmanage.py	(original)
+++ py/trunk/py/test/dsession/testing/test_nodemanage.py	Fri Mar 20 20:33:05 2009
@@ -3,7 +3,7 @@
 """
 
 import py
-from py.__.test.dsession.hostmanage import HostManager, getxspecs, getconfigroots
+from py.__.test.dsession.nodemanage import NodeManager, getxspecs, getconfigroots
 
 from py.__.test import event
 
@@ -13,15 +13,15 @@
     dest = py.test.ensuretemp(pyfuncitem.getmodpath()).mkdir("dest")
     return dest 
 
-class TestHostManager:
+class TestNodeManager:
     @py.test.mark.xfail("consider / forbid implicit rsyncdirs?")
-    def test_hostmanager_rsync_roots_no_roots(self, source, dest):
+    def test_rsync_roots_no_roots(self, source, dest):
         source.ensure("dir1", "file1").write("hello")
         config = py.test.config._reparse([source])
-        hm = HostManager(config, hosts=["popen::%s" % dest])
-        assert hm.config.topdir == source == config.topdir
-        hm.rsync_roots()
-        p, = hm.gwmanager.multi_exec("import os ; channel.send(os.getcwd())").receive_each()
+        nodemanager = NodeManager(config, ["popen//chdir=%s" % dest])
+        assert nodemanager.config.topdir == source == config.topdir
+        nodemanager.rsync_roots()
+        p, = nodemanager.gwmanager.multi_exec("import os ; channel.send(os.getcwd())").receive_each()
         p = py.path.local(p)
         print "remote curdir", p
         assert p == dest.join(config.topdir.basename)
@@ -34,13 +34,13 @@
         dir2.ensure("hello")
         for rsyncroot in (dir1, source):
             dest.remove()
-            hm = HostManager(testdir.parseconfig(
+            nodemanager = NodeManager(testdir.parseconfig(
                 "--tx", "popen//chdir=%s" % dest,
                 "--rsyncdirs", rsyncroot,
                 source, 
             ))
-            assert hm.config.topdir == source
-            hm.rsync_roots() 
+            assert nodemanager.config.topdir == source
+            nodemanager.rsync_roots() 
             if rsyncroot == source:
                 dest = dest.join("source")
             assert dest.join("dir1").check()
@@ -56,9 +56,8 @@
             rsyncdirs = ['dir1/dir2']
         """))
         session = py.test.config._reparse([source]).initsession()
-        hm = HostManager(session.config, 
-                         hosts=["popen//chdir=%s" % dest])
-        hm.rsync_roots()
+        nodemanager = NodeManager(session.config, ["popen//chdir=%s" % dest])
+        nodemanager.rsync_roots()
         assert dest.join("dir2").check()
         assert not dest.join("dir1").check()
         assert not dest.join("bogus").check()
@@ -73,41 +72,41 @@
             rsyncignore = ['dir1/dir2', 'dir5/dir6']
         """))
         session = py.test.config._reparse([source]).initsession()
-        hm = HostManager(session.config,
-                         hosts=["popen//chdir=%s" % dest])
-        hm.rsync_roots()
+        nodemanager = NodeManager(session.config,
+                         ["popen//chdir=%s" % dest])
+        nodemanager.rsync_roots()
         assert dest.join("dir1").check()
         assert not dest.join("dir1", "dir2").check()
         assert dest.join("dir5","file").check()
         assert not dest.join("dir6").check()
 
     def test_optimise_popen(self, source, dest):
-        hosts = ["popen"] * 3
+        specs = ["popen"] * 3
         source.join("conftest.py").write("rsyncdirs = ['a']")
         source.ensure('a', dir=1)
         config = py.test.config._reparse([source])
-        hm = HostManager(config, hosts=hosts)
-        hm.rsync_roots()
-        for gwspec in hm.gwmanager.specs:
+        nodemanager = NodeManager(config, specs)
+        nodemanager.rsync_roots()
+        for gwspec in nodemanager.gwmanager.specs:
             assert gwspec._samefilesystem()
             assert not gwspec.chdir
 
-    def test_setup_hosts_DEBUG(self, source, EventRecorder):
-        hosts = ["popen"] * 2
+    def test_setup_DEBUG(self, source, EventRecorder):
+        specs = ["popen"] * 2
         source.join("conftest.py").write("rsyncdirs = ['a']")
         source.ensure('a', dir=1)
         config = py.test.config._reparse([source, '--debug'])
         assert config.option.debug
-        hm = HostManager(config, hosts=hosts)
+        nodemanager = NodeManager(config, specs)
         evrec = EventRecorder(config.bus, debug=True)
-        hm.setup_hosts(putevent=[].append)
-        for host in hm.gwmanager.specs:
+        nodemanager.setup_nodes(putevent=[].append)
+        for spec in nodemanager.gwmanager.specs:
             l = evrec.getnamed("trace")
             print evrec.events
             assert l 
-        hm.teardown_hosts()
+        nodemanager.teardown_nodes()
 
-    def test_ssh_setup_hosts(self, specssh, testdir):
+    def test_ssh_setup_nodes(self, specssh, testdir):
         testdir.makepyfile(__init__="", test_x="""
             def test_one():
                 pass



More information about the pytest-commit mailing list