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

hpk at codespeak.net hpk at codespeak.net
Mon Feb 5 01:14:13 CET 2007


Author: hpk
Date: Mon Feb  5 01:14:11 2007
New Revision: 37945

Modified:
   py/trunk/py/test/rsession/hostmanage.py
   py/trunk/py/test/rsession/rsession.py
   py/trunk/py/test/rsession/testing/test_hostmanage.py
   py/trunk/py/test/rsession/testing/test_rsession.py
Log:
make the hostmanager get at the hosts itself
(or you can pass it in a custom list of hosts)


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 01:14:11 2007
@@ -97,13 +97,16 @@
         return True # added the target
 
 class HostManager(object):
-    def __init__(self, sshhosts, config):
-        self.sshhosts = sshhosts
+    def __init__(self, config, hosts=None):
         self.config = config
+        if hosts is None:
+            hosts = self.config.getvalue("dist_hosts")
+            hosts = [HostInfo(x) for x in hosts]
+        self.hosts = hosts
 
     def prepare_gateways(self):
         dist_remotepython = self.config.getvalue("dist_remotepython")
-        for host in self.sshhosts:
+        for host in self.hosts:
             host.initgateway(python=dist_remotepython)
             host.gw.host = host
 
@@ -116,7 +119,7 @@
         rsync = HostRSync()
         for root in roots: 
             destrelpath = root.relto(self.config.topdir)
-            for host in self.sshhosts:
+            for host in self.hosts:
                 reporter(repevent.HostRSyncing(host))
                 def donecallback():
                     reporter(repevent.HostReady(host))
@@ -131,7 +134,7 @@
 
     def setup_nodes(self, reporter):
         nodes = []
-        for host in self.sshhosts:
+        for host in self.hosts:
             if hasattr(host.gw, 'remote_exec'): # otherwise dummy for tests :/
                 ch = setup_slave(host, self.config)
                 nodes.append(MasterNode(ch, reporter))

Modified: py/trunk/py/test/rsession/rsession.py
==============================================================================
--- py/trunk/py/test/rsession/rsession.py	(original)
+++ py/trunk/py/test/rsession/rsession.py	Mon Feb  5 01:14:11 2007
@@ -29,7 +29,7 @@
             option.startserver = True
         super(AbstractSession, self).fixoptions()
 
-    def init_reporter(self, reporter, sshhosts, reporter_class, arg=""):
+    def init_reporter(self, reporter, hosts, reporter_class, arg=""):
         """ This initialises so called `reporter` class, which will
         handle all event presenting to user. Does not get called
         if main received custom reporter
@@ -58,9 +58,9 @@
                 from py.__.test.rsession.rest import RestReporter
                 reporter_class = RestReporter
             if arg:
-                reporter_instance = reporter_class(self.config, sshhosts)
+                reporter_instance = reporter_class(self.config, hosts)
             else:
-                reporter_instance = reporter_class(self.config, sshhosts)
+                reporter_instance = reporter_class(self.config, hosts)
             reporter = reporter_instance.report
         else:
             startserverflag = False
@@ -125,16 +125,15 @@
         """ main loop for running tests. """
         args = self.config.args
 
-        sshhosts = self._getconfighosts()
+        hm = HostManager(self.config)
         reporter, startserverflag = self.init_reporter(reporter,
-            sshhosts, RemoteReporter)
+            hm.hosts, RemoteReporter)
         reporter, checkfun = self.wrap_reporter(reporter)
 
-        reporter(repevent.TestStarted(sshhosts))
+        reporter(repevent.TestStarted(hm.hosts))
 
-        hostmanager = HostManager(sshhosts, self.config)
         try:
-            nodes = hostmanager.init_hosts(reporter)
+            nodes = hm.init_hosts(reporter)
             reporter(repevent.RsyncFinished())
             try:
                 self.dispatch_tests(nodes, reporter, checkfun)
@@ -162,10 +161,6 @@
             self.kill_server(startserverflag)
             raise
 
-    def _getconfighosts(self):
-        return [HostInfo(spec) for spec in
-                                    self.config.getvalue("dist_hosts")]
-
     def dispatch_tests(self, nodes, reporter, checkfun):
         colitems = self.config.getcolitems()
         keyword = self.config.option.keyword
@@ -179,17 +174,17 @@
     def main(self, reporter=None, runner=None):
         # check out if used options makes any sense
         args = self.config.args  
-        
-        sshhosts = [HostInfo('localhost')] # this is just an info to reporter
-        
+       
+        hm = HostManager(self.config, hosts=[HostInfo('localhost')])
+        hosts = hm.hosts
         if not self.config.option.nomagic:
             py.magic.invoke(assertion=1)
 
         reporter, startserverflag = self.init_reporter(reporter, 
-            sshhosts, LocalReporter, args[0])
+            hosts, LocalReporter, args[0])
         reporter, checkfun = self.wrap_reporter(reporter)
         
-        reporter(repevent.TestStarted(sshhosts))
+        reporter(repevent.TestStarted(hosts))
         colitems = self.config.getcolitems()
         reporter(repevent.RsyncFinished())
 

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 01:14:11 2007
@@ -109,11 +109,17 @@
         assert not res2
 
 class TestHostManager(DirSetup):
+    def test_hostmanager_custom_hosts(self):
+        config = py.test.config._reparse([self.source])
+        hm = HostManager(config, hosts=[1,2,3])
+        assert hm.hosts == [1,2,3]
+
     def test_hostmanager_init_rsync_topdir(self):
         dir2 = self.source.ensure("dir1", "dir2", dir=1)
         dir2.ensure("hello")
         config = py.test.config._reparse([self.source])
-        hm = HostManager([HostInfo("localhost:" + str(self.dest))], config)
+        hm = HostManager(config, 
+                hosts=[HostInfo("localhost:" + str(self.dest))])
         events = []
         hm.init_rsync(reporter=events.append)
         assert self.dest.join("dir1").check()
@@ -128,7 +134,8 @@
             dist_rsync_roots = ['dir1/dir2']
         """))
         config = py.test.config._reparse([self.source])
-        hm = HostManager([HostInfo("localhost:" + str(self.dest))], config)
+        hm = HostManager(config, 
+                         hosts=[HostInfo("localhost:" + str(self.dest))])
         events = []
         hm.init_rsync(reporter=events.append)
         assert self.dest.join("dir1").check()

Modified: py/trunk/py/test/rsession/testing/test_rsession.py
==============================================================================
--- py/trunk/py/test/rsession/testing/test_rsession.py	(original)
+++ py/trunk/py/test/rsession/testing/test_rsession.py	Mon Feb  5 01:14:11 2007
@@ -121,7 +121,7 @@
         teardown_events = []
         tmpdir = py.test.ensuretemp("emptyconftest") 
         config = py.test.config._reparse([tmpdir])
-        hm = HostManager(hosts, config)
+        hm = HostManager(config, hosts)
         nodes = hm.init_hosts(setup_events.append)
         hm.teardown_hosts(teardown_events.append, 
                        [node.channel for node in nodes], nodes)
@@ -146,7 +146,7 @@
         allevents = []
         
         config = py.test.config._reparse([])
-        hm = HostManager(hosts, config)
+        hm = HostManager(config, hosts=hosts)
         nodes = hm.init_hosts(allevents.append)
         
         from py.__.test.rsession.testing.test_executor \



More information about the pytest-commit mailing list