[py-svn] r45868 - in py/branch/session-cleanups/py/test: . rsession testing

fijal at codespeak.net fijal at codespeak.net
Sun Aug 19 16:57:12 CEST 2007


Author: fijal
Date: Sun Aug 19 16:57:12 2007
New Revision: 45868

Modified:
   py/branch/session-cleanups/py/test/reporter.py
   py/branch/session-cleanups/py/test/rsession/rsession.py
   py/branch/session-cleanups/py/test/rsession/web.py
   py/branch/session-cleanups/py/test/testing/test_reporter.py
Log:
shuffle stuff around, so no the choice of reporter is done independently of
session (based solely on config)


Modified: py/branch/session-cleanups/py/test/reporter.py
==============================================================================
--- py/branch/session-cleanups/py/test/reporter.py	(original)
+++ py/branch/session-cleanups/py/test/reporter.py	Sun Aug 19 16:57:12 2007
@@ -15,6 +15,20 @@
 
 import sys
 
+def choose_reporter(config):
+    option = config.option
+    if option.startserver or option.runbrowser:
+        from py.__.test.rsession.web import WebReporter
+        return WebReporter
+    if option.restreport:
+        from py.__.test.rsession.rest import RestReporter
+        return RestReporter
+    else:
+        if option.dist:
+            return RemoteReporter
+        else:
+            return LocalReporter
+
 class AbstractReporter(object):
     def __init__(self, config, hosts):
         self.config = config

Modified: py/branch/session-cleanups/py/test/rsession/rsession.py
==============================================================================
--- py/branch/session-cleanups/py/test/rsession/rsession.py	(original)
+++ py/branch/session-cleanups/py/test/rsession/rsession.py	Sun Aug 19 16:57:12 2007
@@ -30,30 +30,11 @@
         if self.config.getvalue("dist_boxed"):
             option.boxed = True
         super(AbstractSession, self).fixoptions()
-
-    def init_reporter(self, reporter, hosts, reporter_class):
-        """ This initialises so called `reporter` class, which will
-        handle all event presenting to user. Does not get called
-        if main received custom reporter
-        """
-        startserverflag = self.config.option.startserver
-        restflag = self.config.option.restreport
-        
-        if startserverflag and reporter is None:
-            from py.__.test.rsession.web import start_server_from_config
-            reporter = start_server_from_config(self.config)
-        elif reporter is None: 
-            if restflag:
-                from py.__.test.rsession.rest import RestReporter
-                reporter_class = RestReporter
-            reporter_instance = reporter_class(self.config, hosts)
-            reporter = reporter_instance.report
-        
-        return reporter
     
     def wrap_reporter(self, reporter):
         """ We wrap reporter around, which makes it possible to us to track
         existance of failures
+        XXX kill this bastard
         """
         self.was_failure = False
         def new_reporter(event):
@@ -94,9 +75,10 @@
     
     def main(self, reporter=None):
         """ main loop for running tests. """
-        hm = HostManager(self.config)
-        reporter = self.init_reporter(reporter,
-            hm.hosts, RemoteReporter)
+        config = self.config
+        hm = HostManager(config)
+        if reporter is None:
+            reporter = choose_reporter(config)(config, hm.hosts).report
         reporter, checkfun = self.wrap_reporter(reporter)
 
         reporter(repevent.TestStarted(hm.hosts, self.config.topdir,
@@ -139,13 +121,13 @@
     """
     def main(self, reporter=None, runner=None):
         # check out if used options makes any sense
-        hm = HostManager(self.config, hosts=[HostInfo('localhost')])
+        config = self.config
+        hm = HostManager(config, hosts=[HostInfo('localhost')])
         hosts = hm.hosts
         if not self.config.option.nomagic:
             py.magic.invoke(assertion=1)
-
-        reporter = self.init_reporter(reporter, 
-            hosts, LocalReporter)
+        if reporter is None:
+            reporter = choose_reporter(config)(config, hosts).report
         reporter, checkfun = self.wrap_reporter(reporter)
         
         reporter(repevent.TestStarted(hosts, self.config.topdir, []))

Modified: py/branch/session-cleanups/py/test/rsession/web.py
==============================================================================
--- py/branch/session-cleanups/py/test/rsession/web.py	(original)
+++ py/branch/session-cleanups/py/test/rsession/web.py	Sun Aug 19 16:57:12 2007
@@ -417,6 +417,17 @@
         self.end_headers()
         self.wfile.write(data)
 
+class WebReporter(object):
+    """ A simple wrapper, this file needs ton of refactoring
+    anyway, so this is just to satisfy things below
+    (and start to create saner interface as well)
+    """
+    def __init__(self, config, hosts):
+        start_server_from_config(config)
+
+    # rebind
+    report = exported_methods.report
+
 def start_server_from_config(config):
     if config.option.runbrowser:
         port = socket.INADDR_ANY

Modified: py/branch/session-cleanups/py/test/testing/test_reporter.py
==============================================================================
--- py/branch/session-cleanups/py/test/testing/test_reporter.py	(original)
+++ py/branch/session-cleanups/py/test/testing/test_reporter.py	Sun Aug 19 16:57:12 2007
@@ -18,8 +18,8 @@
 
 
 import py, os
-from py.__.test.rsession.rsession import LocalReporter, AbstractSession,\
-    RemoteReporter
+from py.__.test.rsession.rsession import AbstractSession
+from py.__.test.reporter import RemoteReporter, LocalReporter, choose_reporter 
 from py.__.test import repevent
 from py.__.test.outcome import ReprOutcome, SerializableOutcome
 from py.__.test.rsession.hostmanage import HostInfo
@@ -217,3 +217,17 @@
         val = self._test_full_module()
         assert val.find("FAILED TO LOAD MODULE: repmod/test_three.py\n"\
         "\nSkipped ('reason') repmod/test_two.py") != -1
+
+def test_reporter_choice():
+    from py.__.test.rsession.web import WebReporter
+    from py.__.test.rsession.rest import RestReporter
+    choices = [
+        (['-d'], RemoteReporter),
+        (['-d', '--rest'], RestReporter),
+        ([], LocalReporter),
+        (['-w'], WebReporter),
+        (['-r'], WebReporter)]
+    for opts, reporter in choices:
+        config = py.test.config._reparse(['xxx'] + opts)
+        assert choose_reporter(config) is reporter
+



More information about the pytest-commit mailing list