[py-svn] r48130 - in py/branch/reporter-merge/py/test: . testing

fijal at codespeak.net fijal at codespeak.net
Sun Oct 28 14:58:43 CET 2007


Author: fijal
Date: Sun Oct 28 14:58:42 2007
New Revision: 48130

Added:
   py/branch/reporter-merge/py/test/collectonly.py   (contents, props changed)
   py/branch/reporter-merge/py/test/testing/test_collectonly.py   (contents, props changed)
Modified:
   py/branch/reporter-merge/py/test/config.py
   py/branch/reporter-merge/py/test/repevent.py
   py/branch/reporter-merge/py/test/session.py
   py/branch/reporter-merge/py/test/testing/test_config.py
   py/branch/reporter-merge/py/test/testing/test_session.py
Log:
Add --collectonly handling, new style, logic separated


Added: py/branch/reporter-merge/py/test/collectonly.py
==============================================================================
--- (empty file)
+++ py/branch/reporter-merge/py/test/collectonly.py	Sun Oct 28 14:58:42 2007
@@ -0,0 +1,37 @@
+
+""" --collectonly session, not to spread logic all over the place
+"""
+
+import py
+from py.__.test.session import Session
+from py.__.test.reporter import LocalReporter
+
+class CollectReporter(LocalReporter):
+    def __init__(self, *args, **kwds):
+        super(LocalReporter, self).__init__(*args, **kwds)
+        self.indent = 0
+    
+    def report_ReceivedItemOutcome(self, event):
+        pass
+
+    def report_ItemStart(self, event):
+        self.out.line(" " * self.indent + str(event.item))
+        self.indent += 2
+
+    def report_ItemFinish(self, event):
+        self.indent -= 2
+
+    def report_FailedTryiter(self, event):
+        self.out.line(" " * self.indent + "- FAILED TO LOAD MODULE -")
+
+    def report_SkippedTryiter(self, event):
+        self.out.line(" " * self.indent + "- skipped -")
+
+    def summary(self):
+        self.out.sep("=", "Total time: %.1f" % (self.timeend - self.timestart))
+
+class CollectSession(Session):
+    reporterclass = CollectReporter
+    
+    def run(self, item):
+        pass

Modified: py/branch/reporter-merge/py/test/config.py
==============================================================================
--- py/branch/reporter-merge/py/test/config.py	(original)
+++ py/branch/reporter-merge/py/test/config.py	Sun Oct 28 14:58:42 2007
@@ -162,6 +162,8 @@
         name = 'Session'
         if self.option.dist:
             name = 'RSession'
+        elif self.option.collectonly:
+            name = 'CollectSession'
         else:
             if self.option.looponfailing or self.option.executable:
                 name = 'RemoteTerminalSession'
@@ -267,6 +269,7 @@
 RemoteTerminalSession = 'py.__.test.terminal.remote'
 RSession = 'py.__.test.rsession.rsession'
 LSession = 'py.__.test.rsession.rsession'
+CollectSession = 'py.__.test.collectonly'
 
 #
 # helpers

Modified: py/branch/reporter-merge/py/test/repevent.py
==============================================================================
--- py/branch/reporter-merge/py/test/repevent.py	(original)
+++ py/branch/reporter-merge/py/test/repevent.py	Sun Oct 28 14:58:42 2007
@@ -131,6 +131,13 @@
     def __init__(self, item):
         self.item = item
 
+class ItemFinish(ReportEvent):
+    """ This class shows most of the start stuff, like directory, module, class
+    can be used for containers
+    """
+    def __init__(self, item):
+        self.item = item
+
 class RsyncFinished(ReportEvent):
     def __init__(self):
         self.time = time.time()

Modified: py/branch/reporter-merge/py/test/session.py
==============================================================================
--- py/branch/reporter-merge/py/test/session.py	(original)
+++ py/branch/reporter-merge/py/test/session.py	Sun Oct 28 14:58:42 2007
@@ -93,7 +93,7 @@
     def finish(self, item):
         """ A hook invoked per every item ending
         """
-        pass
+        self.reporter(repevent.ItemFinish(item))
 
 class Session(AbstractSession):
     """

Added: py/branch/reporter-merge/py/test/testing/test_collectonly.py
==============================================================================
--- (empty file)
+++ py/branch/reporter-merge/py/test/testing/test_collectonly.py	Sun Oct 28 14:58:42 2007
@@ -0,0 +1,49 @@
+
+import py
+
+class TestCollectonly:
+    def setup_class(cls):
+        tmp = py.test.ensuretemp('itemgentest')
+        tmp.ensure("__init__.py")
+        tmp.ensure("test_one.py").write(py.code.Source("""
+        def test_one():
+            pass
+
+        class TestX:
+            def test_method_one(self):
+                pass
+
+        class TestY(TestX):
+            pass
+        """))
+        tmp.ensure("test_two.py").write(py.code.Source("""
+        import py
+        py.test.skip('xxx')
+        """))
+        tmp.ensure("test_three.py").write("xxxdsadsadsadsa")
+        cls.tmp = tmp
+
+    def test_collectonly(self):
+        config = py.test.config._reparse([self.tmp, '--collectonly'])
+        session = config.initsession()
+        # test it all in once
+        cap = py.io.StdCaptureFD()
+        session.main()
+        out, err = cap.reset()
+        # XXX exact output matching
+        lines = """<Directory 'itemgentest'>
+  <Module 'test_one.py'>
+    <Function 'test_one'>
+    <Class 'TestX'>
+      <Instance '()'>
+        <Function 'test_method_one'>
+    <Class 'TestY'>
+      <Instance '()'>
+        <Function 'test_method_one'>
+  <Module 'test_three.py'>
+    - FAILED TO LOAD MODULE -
+  <Module 'test_two.py'>
+    - skipped -
+"""
+        for line in lines:
+            assert line in out

Modified: py/branch/reporter-merge/py/test/testing/test_config.py
==============================================================================
--- py/branch/reporter-merge/py/test/testing/test_config.py	(original)
+++ py/branch/reporter-merge/py/test/testing/test_config.py	Sun Oct 28 14:58:42 2007
@@ -224,6 +224,8 @@
         assert config._getsessionname() == 'RemoteTerminalSession'
         config = py.test.config._reparse([self.tmpdir, '--dist', '--exec=x'])
         assert config._getsessionname() == 'RSession'
+        config = py.test.config._reparse([self.tmpdir, '--collectonly'])
+        assert config._getsessionname() == 'CollectSession'
 
     def test_sessionname_lookup_custom(self):
         self.tmpdir.join("conftest.py").write(py.code.Source("""

Modified: py/branch/reporter-merge/py/test/testing/test_session.py
==============================================================================
--- py/branch/reporter-merge/py/test/testing/test_session.py	(original)
+++ py/branch/reporter-merge/py/test/testing/test_session.py	Sun Oct 28 14:58:42 2007
@@ -158,22 +158,6 @@
         assert len(getfailed(all)) == 1 
         assert not getpassed(all)
 
-    def test_collectonly(self):
-        py.test.skip("XXX Reimplement this feature")
-        session, out = self.mainsession("--collectonly", 
-                                        datadir / 'filetest.py')
-        assert session.config.option.collectonly
-        #print out 
-        l = session.getitemoutcomepairs(Failed)
-        #if l: 
-        #    x = l[0][1].excinfo
-        #    print x.exconly() 
-        #    print x.traceback
-        assert len(l) == 0 
-        for line in ('filetest.py', 'test_one', 
-                     'TestClass', 'test_method_one'): 
-            assert out.find(line) 
-
     def test_recursion_detection(self):
         py.test.skip("XXX the test is bogus here")
         o = tmpdir.ensure('recursiontest', dir=1)


More information about the py-svn mailing list