[py-svn] r11506 - in py/dist/py/test: . terminal testing tkinter
hpk at codespeak.net
hpk at codespeak.net
Wed Apr 27 12:02:20 CEST 2005
Author: hpk
Date: Wed Apr 27 12:02:20 2005
New Revision: 11506
Modified:
py/dist/py/test/collect.py
py/dist/py/test/compat.py
py/dist/py/test/item.py
py/dist/py/test/raises.py
py/dist/py/test/session.py
py/dist/py/test/terminal/terminal.py
py/dist/py/test/testing/test_raises.py
py/dist/py/test/testing/test_session.py
py/dist/py/test/tkinter/util.py
Log:
- pass more precise arguments to Outcomes (no general
keyword-args anymore)
- get rid of obsolete 'tbindex' argument.
Since some time we just use '__tracebackhide__=True'
in functions which we don't wan't by default
to show up in tracebacks. (--fulltrace disables
this, btw)
- added raises-output test
- refactored a bit the way to get at test outcomes
- use the name 'outcome' instead of 'res'
(not renamed in the tkinter-session, though,
i leave that to Jan :-)
Modified: py/dist/py/test/collect.py
==============================================================================
--- py/dist/py/test/collect.py (original)
+++ py/dist/py/test/collect.py Wed Apr 27 12:02:20 2005
@@ -76,19 +76,27 @@
_stickyfailure = None
class Outcome:
- def __init__(self, **kwargs):
- assert 'msg' not in kwargs or isinstance(kwargs['msg'], str), (
- "given 'msg' argument is not a string" )
- self.__dict__.update(kwargs)
+ msg = None
+ excinfo = None
+ def __init__(self, msg=None, excinfo=None):
+ if msg is not None:
+ self.msg = msg
+ if excinfo is not None:
+ self.excinfo = excinfo
def __repr__(self):
return getattr(self, 'msg', "%s instance" % (self.__class__,))
def __str__(self):
return getattr(self, 'msg', object.__repr__(self))
class Passed(Outcome): pass
class Failed(Outcome): pass
- class ExceptionFailure(Failed): msg = 'DID NOT RAISE'
- class Skipped(Outcome): pass
+ class ExceptionFailure(Failed):
+ msg = 'DID NOT RAISE'
+ def __init__(self, expr, expected, msg=None, excinfo=None):
+ Collector.Failed.__init__(self, msg=msg, excinfo=excinfo)
+ self.expr = expr
+ self.expected = expected
+ class Skipped(Outcome): pass
def __repr__(self):
return "<%s %r>" %(self.__class__.__name__, self.name)
Modified: py/dist/py/test/compat.py
==============================================================================
--- py/dist/py/test/compat.py (original)
+++ py/dist/py/test/compat.py Wed Apr 27 12:02:20 2005
@@ -47,8 +47,9 @@
for name in names:
items.append("""
def %(name)s(self, %(sig)s):
+ __tracebackhide__ = True
if %(expr)s:
- raise py.test.Item.Failed(tbindex=-2, msg=%(sigsubst)r %% (%(sig)s))
+ raise py.test.Item.Failed(msg=%(sigsubst)r %% (%(sig)s))
""" % locals() )
source = "".join(items)
Modified: py/dist/py/test/item.py
==============================================================================
--- py/dist/py/test/item.py (original)
+++ py/dist/py/test/item.py Wed Apr 27 12:02:20 2005
@@ -87,22 +87,23 @@
#
# triggering specific outcomes while executing Items
#
-def skip(msg="unknown reason", tbindex=-2):
+def skip(msg="unknown reason"):
""" skip with the given Message. """
__tracebackhide__ = True
- raise py.test.Item.Skipped(msg=msg, tbindex=tbindex)
+ raise py.test.Item.Skipped(msg=msg)
def skip_on_error(func, *args, **kwargs):
""" skip test if the given call fails. """
+ __tracebackhide__ = True
try:
return func(*args, **kwargs)
except Exception, e:
s = py.code.ExceptionInfo().exconly()
name = getattr(func, '__name__', func)
- py.test.skip("%s(...) -> %s" %(name, s.rstrip(), ), tbindex=-3)
+ py.test.skip("%s(...) -> %s" %(name, s.rstrip(), ))
def fail(msg="unknown failure"):
""" fail with the given Message. """
__tracebackhide__ = True
- raise py.test.Item.Failed(msg=msg, tbindex=-2)
+ raise py.test.Item.Failed(msg=msg)
Modified: py/dist/py/test/raises.py
==============================================================================
--- py/dist/py/test/raises.py (original)
+++ py/dist/py/test/raises.py Wed Apr 27 12:02:20 2005
@@ -23,8 +23,7 @@
# this is destroyed here ...
except ExpectedException:
return py.code.ExceptionInfo()
- raise ExceptionFailure(expr=expr, expected=ExpectedException,
- tbindex = -2)
+ raise ExceptionFailure(expr=expr, expected=ExpectedException)
else:
func = args[0]
assert callable
Modified: py/dist/py/test/session.py
==============================================================================
--- py/dist/py/test/session.py (original)
+++ py/dist/py/test/session.py Wed Apr 27 12:02:20 2005
@@ -76,7 +76,7 @@
except (KeyboardInterrupt, Exit):
raise
except colitem.Outcome, outcome:
- if not hasattr(outcome, 'excinfo'):
+ if outcome.excinfo is None:
outcome.excinfo = py.code.ExceptionInfo()
except:
excinfo = py.code.ExceptionInfo()
Modified: py/dist/py/test/terminal/terminal.py
==============================================================================
--- py/dist/py/test/terminal/terminal.py (original)
+++ py/dist/py/test/terminal/terminal.py Wed Apr 27 12:02:20 2005
@@ -189,11 +189,23 @@
self.out.sep('=', 'tests finished: %s in %4.2f seconds' %
(status, elapsed))
+ def getlastvisible(self, sourcetraceback):
+ traceback = sourcetraceback[:]
+ while traceback:
+ entry = traceback.pop()
+ try:
+ x = entry.frame.eval("__tracebackhide__")
+ except:
+ x = False
+ if not x:
+ return entry
+ else:
+ return sourcetraceback[-1]
+
def skippedreasons(self):
texts = {}
for colitem, outcome in self.getitemoutcomepairs(Item.Skipped):
- tbindex = getattr(outcome, 'tbindex', -1)
- raisingtb = outcome.excinfo.traceback[tbindex]
+ raisingtb = self.getlastvisible(outcome.excinfo.traceback)
fn = raisingtb.frame.code.path
lineno = raisingtb.lineno
d = texts.setdefault(outcome.excinfo.exconly(), {})
@@ -204,7 +216,7 @@
self.out.sep('_', 'reasons for skipped tests')
for text, dict in texts.items():
for (fn, lineno), outcome in dict.items():
- self.out.line('Skipped in %s:%d' %(fn,lineno))
+ self.out.line('Skipped in %s:%d' %(fn, lineno+1))
self.out.line("reason: %s" % text)
self.out.line()
Modified: py/dist/py/test/testing/test_raises.py
==============================================================================
--- py/dist/py/test/testing/test_raises.py (original)
+++ py/dist/py/test/testing/test_raises.py Wed Apr 27 12:02:20 2005
@@ -15,3 +15,4 @@
def test_raises_function(self):
test.raises(ValueError, int, 'hello')
+
Modified: py/dist/py/test/testing/test_session.py
==============================================================================
--- py/dist/py/test/testing/test_session.py (original)
+++ py/dist/py/test/testing/test_session.py Wed Apr 27 12:02:20 2005
@@ -137,6 +137,21 @@
i = out.find('TypeError')
assert i != -1
+ def test_raises_output(self):
+ o = tmpdir.ensure('raisestest', dir=1)
+ tfile = o.join('test_raisesoutput.py')
+ tfile.write(py.code.Source("""
+ import py
+ def test_raises_doesnt():
+ py.test.raises(ValueError, int, "3")
+ """))
+ session = self.session
+ session.main([o])
+ out = self.file.getvalue()
+ if not out.find("DID NOT RAISE") != -1:
+ print out
+ py.test.fail("incorrect raises() output")
+
def test_order_of_execution(self):
o = tmpdir.ensure('ordertest', dir=1)
tfile = o.join('test_orderofexecution.py')
Modified: py/dist/py/test/tkinter/util.py
==============================================================================
--- py/dist/py/test/tkinter/util.py (original)
+++ py/dist/py/test/tkinter/util.py Wed Apr 27 12:02:20 2005
@@ -202,8 +202,7 @@
def report_skipped(self, config, item, res):
texts = {}
- tbindex = getattr(res, 'tbindex', -1)
- raisingtb = res.excinfo.traceback[tbindex]
+ raisingtb = self.getlastvisible(res.excinfo.traceback)
fn = raisingtb.frame.code.path
lineno = raisingtb.lineno
d = texts.setdefault(res.excinfo.exconly(), {})
More information about the pytest-commit
mailing list