[py-svn] r33416 - in py/dist/py: bin magic/testing test/rsession test/rsession/testing

fijal at codespeak.net fijal at codespeak.net
Wed Oct 18 19:56:53 CEST 2006


Author: fijal
Date: Wed Oct 18 19:55:40 2006
New Revision: 33416

Modified:
   py/dist/py/bin/py.lookup
   py/dist/py/magic/testing/test_assertion.py
   py/dist/py/test/rsession/box.py
   py/dist/py/test/rsession/outcome.py
   py/dist/py/test/rsession/rsession.py
   py/dist/py/test/rsession/slave.py
   py/dist/py/test/rsession/testing/test_lsession.py
   py/dist/py/test/rsession/testing/test_reporter.py
   py/dist/py/test/rsession/testing/test_rsession.py
   py/dist/py/test/rsession/testing/test_slave.py
Log:
Maintenance. Tests, fixes.


Modified: py/dist/py/bin/py.lookup
==============================================================================
--- py/dist/py/bin/py.lookup	(original)
+++ py/dist/py/bin/py.lookup	Wed Oct 18 19:55:40 2006
@@ -1,7 +1,9 @@
 #!/usr/bin/env python 
 
-from _findpy import py 
-import re 
+import sys, os
+sys.path.insert(0, os.path.dirname(__file__))
+from _findpy import py
+import re
 
 curdir = py.path.local()
 def rec(p):
@@ -12,6 +14,8 @@
 parser = optparse.OptionParser()
 parser.add_option("-i", "--ignore-case", action="store_true", dest="ignorecase",
                   help="ignore case distinctions")
+parser.add_option("-C", "--context", action="store", type="int", dest="context",
+            default=0, help="How many lines of output to show")
 
 if __name__ == '__main__':
     (options, args) = parser.parse_args()
@@ -31,4 +35,10 @@
                 searchlines = lines
             for i, (line, searchline) in enumerate(zip(lines, searchlines)): 
                 if searchline.find(string) != -1:
-                    print "%s:%d:  %s" %(x.relto(curdir), i+1, line.rstrip())
+                    if not options.context:
+                        print "%s:%d:  %s" %(x.relto(curdir), i+1, line.rstrip())
+                    else:
+                        context = (options.context)/2
+                        for count in range(i-context, i+context+1):
+                            print "%s:%d:  %s" %(x.relto(curdir), count+1, lines[count].rstrip())
+                        print "-"*50

Modified: py/dist/py/magic/testing/test_assertion.py
==============================================================================
--- py/dist/py/magic/testing/test_assertion.py	(original)
+++ py/dist/py/magic/testing/test_assertion.py	Wed Oct 18 19:55:40 2006
@@ -87,3 +87,12 @@
         assert 0, ['list']
     except AssertionError, e: 
         assert e.msg.find("list") != -1 
+
+def test_assert_implicit_multiline():
+    try:
+        x = [1,2,3]
+        assert x != [1,
+           2, 3]
+    except AssertionError, e:
+        assert e.msg.find('assert [1, 2, 3] !=') != -1
+

Modified: py/dist/py/test/rsession/box.py
==============================================================================
--- py/dist/py/test/rsession/box.py	(original)
+++ py/dist/py/test/rsession/box.py	Wed Oct 18 19:55:40 2006
@@ -189,6 +189,7 @@
             stdout.close()
             stderr.close()
             retvalf.close()
+        os._exit(0)
     
     def parent(self):
         pid, exitstat = os.wait()

Modified: py/dist/py/test/rsession/outcome.py
==============================================================================
--- py/dist/py/test/rsession/outcome.py	(original)
+++ py/dist/py/test/rsession/outcome.py	Wed Oct 18 19:55:40 2006
@@ -48,7 +48,7 @@
         self.lineno = int(lineno)
     
     def __repr__(self):
-        return "line %s in %s\n  %s" %(self.lineno, self.path, self.source)
+        return "line %s in %s\n  %s" %(self.lineno, self.path, self.source[100:])
 
 class ExcInfoRepr(object):
     def __init__(self, excinfo):

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 19:55:40 2006
@@ -23,7 +23,12 @@
         self.d = d
     
     def __getattr__(self, attr):
+        if attr == 'd':
+            return self.__dict__['d']
         return self.d[attr]
+    
+    def __setitem__(self, item, val):
+        self.d[item] = val
 
 remote_options = RemoteOptions({'we_are_remote':False})
 
@@ -37,6 +42,8 @@
         self.failed = dict([(host, 0) for host in hosts])
         self.skipped = dict([(host, 0) for host in hosts])
         self.passed = dict([(host, 0) for host in hosts])
+        self.count = 0
+        self.lgt = 1000
 
     def report(self, what):
         repfun = getattr(self, "report_" + what.__class__.__name__, 
@@ -61,7 +68,7 @@
         if self.config.option.verbose: 
             print "Sending %s to %s" % (item.item,
                                         address)
-
+    
     def report_HostRSyncing(self, item):
         print "%10s: RSYNC ==> %s" % (item.hostname[:10],
                                       item.remoterootpath)
@@ -238,6 +245,12 @@
         return event.channel.gateway.sshaddress + ":" + \
             "/".join(colitem.listnames())
                 
+    def report_FailedTryiter(self, event):
+        self.out.line("FAILED TO LOAD MODULE: %s" % "/".join(event.item.listnames()))
+    
+    def report_SkippedTryiter(self, event):
+        self.out.line("Skipped (%s) %s" % (str(event.excinfo.value), "/".
+            join(event.item.listnames())))
 
 class LocalReporter(AbstractReporter):
     def get_host(self, item):
@@ -246,6 +259,12 @@
     def get_item_name(self, event, colitem):
         return "/".join(colitem.listnames())
     
+    def report_SkippedTryiter(self, event):
+        self.out.write("- skipped (%s)\n" % event.excinfo.value)
+    
+    def report_FailedTryiter(self, event):
+        self.out.write("- FAILED TO LOAD MODULE\n")
+    
     def report_ReceivedItemOutcome(self, event):
         if event.outcome.passed:
             self.passed['localhost'] += 1
@@ -375,8 +394,9 @@
         except:
             remotepython = None
 
+        remote_options['nomagic'] = self.config.option.nomagic
         nodes = init_hosts(reporter, sshhosts, directories, pkgdir,
-            rsync_roots, remotepython)
+            rsync_roots, remotepython, remote_options=remote_options.d)
         reporter(report.RsyncFinished())
         
         keyword = self.config.option.keyword
@@ -405,6 +425,9 @@
             args = [py.path.local()]
             
         sshhosts = ['localhost'] # this is just an info to reporter
+        
+        if not self.config.option.nomagic:
+            py.magic.invoke(assertion=1)
 
         reporter, checkfun, startserverflag = self.init_reporter(reporter, 
             sshhosts, LocalReporter)
@@ -435,3 +458,7 @@
         if startserverflag:
             from py.__.test.rsession.web import kill_server
             kill_server()
+
+        #py.test.Function.state.teardown_all()
+        if not self.config.option.nomagic:
+            py.magic.revoke(assertion=1)

Modified: py/dist/py/test/rsession/slave.py
==============================================================================
--- py/dist/py/test/rsession/slave.py	(original)
+++ py/dist/py/test/rsession/slave.py	Wed Oct 18 19:55:40 2006
@@ -43,6 +43,7 @@
     while 1:
         nextitem = receive()
         if nextitem is None:
+            #py.test.Function.state.teardown_all()
             break
         try:
             node = getnode(nextitem)
@@ -65,19 +66,30 @@
     
 
 def setup():
+    default_options = {'nomagic':False} # XXX should come from somewhere else
+        # but I don't want to mess with conftest at this point
+    
     import os, sys
     pkgdir = channel.receive()   # path is ready 
     options = channel.receive()  # options stuff, should be dictionary
-    basedir = os.path.dirname(pkgdir) 
-    pkgname = os.path.basename(pkgdir) 
+    basedir = os.path.dirname(pkgdir)
+    pkgname = os.path.basename(pkgdir)
+    # setup defaults...
     sys.path.insert(0, basedir)
     import py
-    from py.__.test.rsession.rsession import RemoteOptions
     options['we_are_remote'] = True
+    for opt, val in default_options.items():
+        if opt not in options:
+            options[opt] = val
+    from py.__.test.rsession.rsession import RemoteOptions
     py.test.remote = RemoteOptions(options)
     # XXX the following assumes that py lib is there, a bit
     # much of an assumtion 
+    if not py.test.remote.nomagic:
+        py.magic.invoke(assertion=1)
     mod = __import__(pkgname)
     assert py.path.local(mod.__file__).dirpath() == py.path.local(pkgdir)
     from py.__.test.rsession.slave import slave_main
     slave_main(channel.receive, channel.send, basedir)
+    if not py.test.remote.nomagic:
+        py.magic.revoke(assertion=1)

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 19:55:40 2006
@@ -7,12 +7,21 @@
 from py.__.test.rsession import report
 from py.__.test.rsession.local import box_runner, plain_runner
 
+basepath = py.path.local(py.__file__).dirpath().dirpath()
+
+try:
+    tmp = basepath.mkdir("pytemp")
+except py.error.EEXIST:
+    tmp = basepath.join("pytemp")
+    tmp.remove(rec=1)
+    tmp = basepath.mkdir("pytemp")
+
 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 = tmp
         dirname = "sub"+runner.func_name
         tmpdir.ensure(dirname, "__init__.py")
         tmpdir.ensure(dirname, "test_one.py").write(py.code.Source("""
@@ -66,7 +75,7 @@
 
     def test_pdb_run(self):
         # we make sure that pdb is engaged
-        tmpdir = py.path.local(py.__file__).dirpath().dirpath()
+        tmpdir = tmp
         tmpdir.ensure("sub", "__init__.py")
         tmpdir.ensure("sub", "test_one.py").write(py.code.Source("""
             def test_1(): 
@@ -94,7 +103,7 @@
         assert len(l) == 1
 
     def test_minus_x(self):
-        tmpdir = py.path.local(py.__file__).dirpath().dirpath()
+        tmpdir = tmp
         tmpdir.ensure("sub2", "__init__.py")
         tmpdir.ensure("sub2", "test_one.py").write(py.code.Source("""
             def test_1(): 
@@ -129,7 +138,7 @@
         assert len(failevents) == 1
     
     def test_minus_k(self):
-        tmpdir = py.path.local(py.__file__).dirpath().dirpath()
+        tmpdir = tmp
         tmpdir.ensure("sub3", "__init__.py")
         tmpdir.ensure("sub3", "test_some.py").write(py.code.Source("""
             def test_one(): 
@@ -154,3 +163,83 @@
         failevents = [i for i in testevents if i.outcome.excinfo]
         assert len(passevents) == 1
         assert len(failevents) == 1
+
+    def test_lsession(self):
+        tmpdir = tmp
+        tmpdir.ensure("sub4", "__init__.py")
+        tmpdir.ensure("sub4", "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("sub4"))]
+        config, args = py.test.Config.parse(args)
+        lsession = LSession(config)
+        allevents = []
+        allruns = []
+        def dummy_runner(item, config, reporter):
+            allruns.append(item)
+            return item
+        lsession.main(args, reporter=allevents.append, runner=dummy_runner)
+        
+        assert len(allruns) == 4
+        testevents = [x for x in allevents 
+                        if isinstance(x, report.ReceivedItemOutcome)]
+        assert len(testevents) == 4
+        lst = ['test_one', 'test_one_one', 'test_other', 'test_two']
+        for num, i in enumerate(testevents):
+            assert i.item == i.outcome
+            assert i.item.name == lst[num]
+        
+    def test_module_raising(self):
+        tmpdir = tmp
+        tmpdir.ensure("sub5", "__init__.py")
+        tmpdir.ensure("sub5", "test_some.py").write(py.code.Source("""
+            1/0
+        """))
+        tmpdir.ensure("sub5", "test_other.py").write(py.code.Source("""
+            import py
+            py.test.skip("reason")
+        """))
+        
+        args = [str(tmpdir.join("sub5"))]
+        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) == 0
+        failedtryiter = [x for x in allevents 
+                        if isinstance(x, report.FailedTryiter)]
+        assert len(failedtryiter) == 1
+        skippedtryiter = [x for x in allevents 
+                        if isinstance(x, report.SkippedTryiter)]
+        assert len(skippedtryiter) == 1
+        
+
+    def test_assert_reinterpret(self):
+        tmpdir = tmp
+        tmpdir.ensure("sub6", "__init__.py")
+        tmpdir.ensure("sub6", "test_some.py").write(py.code.Source("""
+        def test_one():
+            x = [1, 2]
+            assert [0] == x
+        """))
+        args = [str(tmpdir.join("sub6"))]
+        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)]
+        failevents = [i for i in testevents if i.outcome.excinfo]
+        assert len(failevents) == 1
+        assert len(testevents) == 1
+        assert failevents[0].outcome.excinfo.value == 'assert [0] == [1, 2]'

Modified: py/dist/py/test/rsession/testing/test_reporter.py
==============================================================================
--- py/dist/py/test/rsession/testing/test_reporter.py	(original)
+++ py/dist/py/test/rsession/testing/test_reporter.py	Wed Oct 18 19:55:40 2006
@@ -4,7 +4,7 @@
 """
 
 import py
-from py.__.test.rsession.rsession import RemoteReporter
+from py.__.test.rsession.rsession import LocalReporter
 from py.__.test.rsession.report import ReceivedItemOutcome
 from py.__.test.rsession.outcome import ReprOutcome, Outcome
 from py.__.test.rsession.testing.test_slave import funcpass_spec
@@ -15,7 +15,7 @@
 class TestReporter(object):
     def test_report_received_item_outcome(self):
         config, args = py.test.Config.parse(["some_sub"])
-        r = RemoteReporter(config, ["host"])
+        r = LocalReporter(config, ["localhost"])
         # possible outcomes
         try:
             1/0
@@ -30,7 +30,7 @@
         outcomes = [ReprOutcome(outcome.make_repr()) for outcome in outcomes]
         outcomes[3].signal = 11
         outcomes[0].passed = False
-            
+        
         # we just go...
         rootcol = py.test.collect.Directory(pkgdir.dirpath())
         item = rootcol.getitembynames(funcpass_spec)

Modified: py/dist/py/test/rsession/testing/test_rsession.py
==============================================================================
--- py/dist/py/test/rsession/testing/test_rsession.py	(original)
+++ py/dist/py/test/rsession/testing/test_rsession.py	Wed Oct 18 19:55:40 2006
@@ -165,10 +165,10 @@
         
         count_rsyn_calls = [i for i in setup_events 
                 if isinstance(i, report.HostRSyncing)]
-        assert len(count_rsyn_calls) == len(hosts)
+        assert len(count_rsyn_calls) == len([i for i in hosts if i != 'localhost'])
         count_ready_calls = [i for i in setup_events 
                 if isinstance(i, report.HostReady)]
-        assert len(count_ready_calls) == len(hosts)
+        assert len(count_ready_calls) == len([i for i in hosts if i != 'localhost'])
         
         # same for teardown events
         teardown_wait_starts = [i for i in teardown_events 

Modified: py/dist/py/test/rsession/testing/test_slave.py
==============================================================================
--- py/dist/py/test/rsession/testing/test_slave.py	(original)
+++ py/dist/py/test/rsession/testing/test_slave.py	Wed Oct 18 19:55:40 2006
@@ -4,12 +4,14 @@
 from py.__.test.rsession.outcome import ReprOutcome
 import py, sys
 
+modlevel = []
+import os
+
 if sys.platform == 'win32':
     py.test.skip("rsession is unsupported on Windows.")
 
-
-def setup_module(mod):
-    mod.rootdir = py.path.local(py.__file__).dirpath().dirpath()
+def setup_module(module):
+    module.rootdir = py.path.local(py.__file__).dirpath().dirpath()
 
 # ----------------------------------------------------------------------
 # inlined testing functions used below
@@ -106,8 +108,8 @@
     slave_main(q.pop, res.append, str(rootdir))
     assert len(res) == 2
     res_repr = [ReprOutcome(r) for r in res]
-    assert not res_repr[0].passed
-    assert res_repr[1].passed
+    assert (not res_repr[0].passed and res_repr[1].passed) or \
+        (not res_repr[1].passed and res_repr[0].passed)
 
 def test_slave_run_different_stuff():
     node = gettestnode()



More information about the pytest-commit mailing list