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

guido at codespeak.net guido at codespeak.net
Sat Jan 27 16:37:45 CET 2007


Author: guido
Date: Sat Jan 27 16:37:43 2007
New Revision: 37438

Modified:
   py/trunk/py/test/conftesthandle.py
   py/trunk/py/test/rsession/outcome.py
   py/trunk/py/test/rsession/rest.py
   py/trunk/py/test/rsession/testing/test_rest.py
Log:
Fiddle-fixed --rest, although it works now some cleanups would be nice...
Cleaned up the tests a bit and re-enabled some (sucky tests are better than
no tests at all, I guess... :| ), re-enabled a debug print after complaints
from cfbolz ;) but this time it prints to stderr (to avoid ReST pollution).


Modified: py/trunk/py/test/conftesthandle.py
==============================================================================
--- py/trunk/py/test/conftesthandle.py	(original)
+++ py/trunk/py/test/conftesthandle.py	Sat Jan 27 16:37:43 2007
@@ -26,7 +26,7 @@
         for arg in args + [current]:
             anchor = current.join(arg, abs=1)
             if anchor.check(): # we found some file object 
-                #print "initializing conftest from", anchor
+                print >>py.std.sys.stderr, "initializing conftest from", anchor
                 # conftest-lookups without a path actually mean 
                 # lookups with our initial path. 
                 self._path2confmods[None] = self.getconftestmodules(anchor)

Modified: py/trunk/py/test/rsession/outcome.py
==============================================================================
--- py/trunk/py/test/rsession/outcome.py	(original)
+++ py/trunk/py/test/rsession/outcome.py	Sat Jan 27 16:37:43 2007
@@ -27,7 +27,10 @@
         tb_info = [self.traceback_entry_repr(x, tbstyle)
                    for x in excinfo.traceback]
         rec_index = excinfo.traceback.recursionindex()
-        return (excinfo.type.__name__, str(excinfo.value), (tb_info, rec_index))
+        etype = excinfo.type
+        if hasattr(etype, '__name__'):
+            etype = etype.__name__
+        return (etype, str(excinfo.value), (tb_info, rec_index))
     
     def traceback_entry_repr(self, tb_entry, tb_style):
         lineno = tb_entry.lineno

Modified: py/trunk/py/test/rsession/rest.py
==============================================================================
--- py/trunk/py/test/rsession/rest.py	(original)
+++ py/trunk/py/test/rsession/rest.py	Sat Jan 27 16:37:43 2007
@@ -140,7 +140,10 @@
                     self.add_rest(ListItem('%s: %s' % (item, text)))
 
     def get_host(self, event):
-        return event.channel.gateway.host
+        try:
+            return event.channel.gateway.host
+        except AttributeError:
+            return None
 
     def failures(self):
         self.traceback_num = 0
@@ -160,7 +163,8 @@
                     t.add(Link(itempath, link))
                 else:
                     t.add(Text(itempath))
-                t.add(Text('on %s' % (host.hostname,)))
+                if host:
+                    t.add(Text('on %s' % (host.hostname,)))
                 self.add_rest(t)
                 if event.outcome.signal:
                     self.repr_signal(event.item, event.outcome)

Modified: py/trunk/py/test/rsession/testing/test_rest.py
==============================================================================
--- py/trunk/py/test/rsession/testing/test_rest.py	(original)
+++ py/trunk/py/test/rsession/testing/test_rest.py	Sat Jan 27 16:37:43 2007
@@ -11,6 +11,11 @@
 from py.__.test.rsession.hostmanage import HostInfo
 from py.__.test.rsession.outcome import Outcome
 
+class Container(object):
+    def __init__(self, **args):
+        for arg, val in args.items():
+            setattr(self, arg, val) 
+
 class RestTestReporter(RestReporter):
     def __init__(self, *args, **kwargs):
         if args:
@@ -78,11 +83,6 @@
             def listnames(self):
                 return ['package', 'foo', 'bar.py']
 
-        class Container(object):
-            def __init__(self, **args):
-                for arg, val in args.items():
-                    setattr(self, arg, val) 
-        
         parent = Container(parent=None, fspath=py.path.local('.'))
         event = report.ItemStart(item=FakeModule(parent))
         reporter.report(event)
@@ -105,11 +105,6 @@
 
     def test_ReceivedItemOutcome_PASSED(self):
         outcome = Outcome()
-        class Container(object):
-            def __init__(self, **args):
-                for arg, val in args.items():
-                    setattr(self, arg, val) 
-
         item = Container(listnames=lambda: ['', 'foo.py', 'bar', '()', 'baz'])
         event = report.ReceivedItemOutcome(channel=ch, outcome=outcome, item=item)
         reporter.report(event)
@@ -117,11 +112,6 @@
                                      'foo.py/bar()/baz\n\n')
 
     def test_ReceivedItemOutcome_SKIPPED(self):
-        class Container(object):
-            def __init__(self, **args):
-                for arg, val in args.items():
-                    setattr(self, arg, val) 
-
         outcome = Outcome(skipped="reason")
         item = Container(listnames=lambda: ['', 'foo.py', 'bar', '()', 'baz'])
         event = report.ReceivedItemOutcome(channel=ch, outcome=outcome, item=item)
@@ -130,11 +120,6 @@
                                      'foo.py/bar()/baz\n\n')
 
     def test_ReceivedItemOutcome_FAILED(self):
-        class Container(object):
-            def __init__(self, **args):
-                for arg, val in args.items():
-                    setattr(self, arg, val) 
-
         outcome = Outcome(excinfo="xxx")
         item = Container(listnames=lambda: ['', 'foo.py', 'bar', '()', 'baz'])
         event = report.ReceivedItemOutcome(channel=ch, outcome=outcome, item=item)
@@ -143,13 +128,45 @@
 * localhost\: **FAILED** `traceback0`_ foo.py/bar()/baz
 
 """
-    
-    def test_skips(self):
-        class Container(object):
-            def __init__(self, **args):
-                for arg, val in args.items():
-                    setattr(self, arg, val) 
 
+    def test_ReceivedItemOutcome_FAILED_stdout(self):
+        excinfo = Container(
+            typename='FooError',
+            value='A foo has occurred',
+            traceback=[
+                Container(
+                    path='foo/bar.py',
+                    lineno=1,
+                    relline=1,
+                    source='foo()',
+                ),
+                Container(
+                    path='foo/baz.py',
+                    lineno=4,
+                    relline=1,
+                    source='raise FooError("A foo has occurred")',
+                ),
+            ]
+        )
+        outcome = Outcome(excinfo=excinfo)
+        outcome.stdout = '<printed>'
+        outcome.stderr = ''
+        parent = Container(parent=None, fspath=py.path.local('.'))
+        item = Container(listnames=lambda: ['', 'foo.py', 'bar', '()', 'baz'],
+                         parent=parent, fspath=py.path.local('foo'))
+        event = report.ReceivedItemOutcome(channel=ch, outcome=outcome,
+                                           item=item)
+        reporter.report(event)
+        reporter.timestart = 10
+        reporter.timeend = 20
+        reporter.timersync = 15
+        reporter.print_summary(10, '', '')
+
+        reporter.print_summary(1, 'skipped', 'failed')
+        out = stdout.getvalue()
+        assert out.find('<printed>') > -1
+
+    def test_skips(self):
         class FakeOutcome(Container, report.ReceivedItemOutcome):
             pass
 
@@ -175,12 +192,6 @@
 """
 
     def test_failures(self):
-        py.test.skip("This one is totally artificial, needs to be rewritten")
-        class Container(object):
-            def __init__(self, **args):
-                for arg, val in args.items():
-                    setattr(self, arg, val) 
-
         class FakeOutcome(Container, report.ReceivedItemOutcome):
             pass
 



More information about the pytest-commit mailing list