[py-svn] r33400 - in py/dist/py/test/rsession: . testing

fijal at codespeak.net fijal at codespeak.net
Wed Oct 18 14:16:20 CEST 2006


Author: fijal
Date: Wed Oct 18 14:16:02 2006
New Revision: 33400

Modified:
   py/dist/py/test/rsession/local.py
   py/dist/py/test/rsession/rsession.py
   py/dist/py/test/rsession/testing/test_lsession.py
Log:
Added some tests, fixed some bugs.


Modified: py/dist/py/test/rsession/local.py
==============================================================================
--- py/dist/py/test/rsession/local.py	(original)
+++ py/dist/py/test/rsession/local.py	Wed Oct 18 14:16:02 2006
@@ -18,7 +18,7 @@
     raise NotImplementedError()
 
 def apigen_runner(item, config, reporter):
-    pass
+    raise NotImplementedError()
 
 def exec_runner(item, config, reporter):
     raise NotImplementedError()

Modified: py/dist/py/test/rsession/rsession.py
==============================================================================
--- py/dist/py/test/rsession/rsession.py	(original)
+++ py/dist/py/test/rsession/rsession.py	Wed Oct 18 14:16:02 2006
@@ -329,6 +329,7 @@
                     reporter_instance.is_failing()
         else:
             startserverflag = False
+        
         return reporter, checkfun, startserverflag
     
     def reporterror(reporter, data):
@@ -399,7 +400,7 @@
 class LSession(AbstractSession):
     """ Local version of session
     """
-    def main(self, args, reporter=None, runner=None):
+    def main(self, args, reporter=None, runner=None, shouldstop=None):
         if not args: 
             args = [py.path.local()]
             
@@ -407,6 +408,8 @@
 
         reporter, checkfun, startserverflag = self.init_reporter(reporter, 
             sshhosts, LocalReporter)
+        if shouldstop:
+            checkfun = shouldstop
         
         reporter(report.TestStarted(sshhosts))
         pkgdir = self.getpkgdir(args[0])

Modified: py/dist/py/test/rsession/testing/test_lsession.py
==============================================================================
--- py/dist/py/test/rsession/testing/test_lsession.py	(original)
+++ py/dist/py/test/rsession/testing/test_lsession.py	Wed Oct 18 14:16:02 2006
@@ -8,11 +8,14 @@
 from py.__.test.rsession.local import box_runner, plain_runner
 
 class TestLSession(object):
+    # XXX: Some tests of that should be run as well on RSession, while
+    #      some not at all
     def example_distribution(self, runner):
         # XXX find a better way for the below 
         tmpdir = py.path.local(py.__file__).dirpath().dirpath()
-        tmpdir.ensure("sub", "__init__.py")
-        tmpdir.ensure("sub", "test_one.py").write(py.code.Source("""
+        dirname = "sub"+runner.func_name
+        tmpdir.ensure(dirname, "__init__.py")
+        tmpdir.ensure(dirname, "test_one.py").write(py.code.Source("""
             def test_1(): 
                 pass
             def test_2():
@@ -25,7 +28,7 @@
             #    import os
             #    os.kill(os.getpid(), 11)
         """))
-        args = [str(tmpdir.join("sub"))]
+        args = [str(tmpdir.join(dirname))]
         config, args = py.test.Config.parse(args)
         lsession = LSession(config)
         allevents = []
@@ -60,3 +63,94 @@
     
     def test_plain(self):
         self.example_distribution(plain_runner)
+
+    def test_pdb_run(self):
+        # we make sure that pdb is engaged
+        tmpdir = py.path.local(py.__file__).dirpath().dirpath()
+        tmpdir.ensure("sub", "__init__.py")
+        tmpdir.ensure("sub", "test_one.py").write(py.code.Source("""
+            def test_1(): 
+                assert 0
+        """))
+        import pdb
+        l = []
+        def some_fun(*args):
+            l.append(args)
+        
+        pdb.post_mortem = some_fun
+        args = [str(tmpdir.join("sub")), '--pdb']
+        config, args = py.test.Config.parse(args)
+        lsession = LSession(config)
+        allevents = []
+        try:
+            lsession.main(args, reporter=allevents.append, runner=plain_runner)
+        except SystemExit:
+            pass
+        else:
+            py.test.fail("Didn't raise system exit")
+        failure_events = [event for event in allevents if isinstance(event,
+            report.ImmediateFailure)]
+        assert len(failure_events) == 1
+        assert len(l) == 1
+
+    def test_minus_x(self):
+        tmpdir = py.path.local(py.__file__).dirpath().dirpath()
+        tmpdir.ensure("sub2", "__init__.py")
+        tmpdir.ensure("sub2", "test_one.py").write(py.code.Source("""
+            def test_1(): 
+                pass
+            def test_2():
+                assert 0
+            def test_3():
+                raise ValueError(23)
+            def test_4(someargs):
+                pass
+        """))
+        args = [str(tmpdir.join("sub2")), '-x']
+        config, args = py.test.Config.parse(args)
+        assert config.option.exitfirst
+        lsession = LSession(config)
+        allevents = []
+        
+        def check_stop():
+            testevents = [x for x in allevents 
+                if isinstance(x, report.ReceivedItemOutcome)]
+            failevents = [i for i in testevents if i.outcome.excinfo]
+            return len(failevents) > 0
+        
+        lsession.main(args, reporter=allevents.append, runner=box_runner,
+            shouldstop=check_stop)
+        testevents = [x for x in allevents 
+                        if isinstance(x, report.ReceivedItemOutcome)]
+        assert len(testevents)
+        passevents = [i for i in testevents if i.outcome.passed]
+        failevents = [i for i in testevents if i.outcome.excinfo]
+        assert len(passevents) == 1
+        assert len(failevents) == 1
+    
+    def test_minus_k(self):
+        tmpdir = py.path.local(py.__file__).dirpath().dirpath()
+        tmpdir.ensure("sub3", "__init__.py")
+        tmpdir.ensure("sub3", "test_some.py").write(py.code.Source("""
+            def test_one(): 
+                pass
+            def test_one_one():
+                assert 0
+            def test_other():
+                raise ValueError(23)
+            def test_two(someargs):
+                pass
+        """))
+        args = [str(tmpdir.join("sub3")), '-k', 'test_one']
+        config, args = py.test.Config.parse(args)
+        lsession = LSession(config)
+        allevents = []
+        
+        lsession.main(args, reporter=allevents.append, runner=box_runner)
+        testevents = [x for x in allevents 
+                        if isinstance(x, report.ReceivedItemOutcome)]
+        assert len(testevents)
+        passevents = [i for i in testevents if i.outcome.passed]
+        failevents = [i for i in testevents if i.outcome.excinfo]
+        assert len(passevents) == 1
+        assert len(failevents) == 1



More information about the pytest-commit mailing list