[py-svn] r57977 - in py/trunk/py/code: . testing
pedronis at codespeak.net
pedronis at codespeak.net
Mon Sep 8 17:51:39 CEST 2008
Author: pedronis
Date: Mon Sep 8 17:51:38 2008
New Revision: 57977
Modified:
py/trunk/py/code/excinfo.py
py/trunk/py/code/testing/test_excinfo.py
py/trunk/py/code/traceback2.py
Log:
(iko, pedronis)
- fixing a bug with test about the case when a multi line source cannot be retrieved
( test_repr_many_line_source_not_existing in test_excinfo.py )
- trying to make py test behave more like in the past in the face of fullsource errors, needed by pypy app test
infrastructure
( test_repr_source_failing_fullsource in test_excinfo.py )
Modified: py/trunk/py/code/excinfo.py
==============================================================================
--- py/trunk/py/code/excinfo.py (original)
+++ py/trunk/py/code/excinfo.py Mon Sep 8 17:51:38 2008
@@ -96,10 +96,10 @@
def _getentrysource(self, entry):
source = entry.getsource()
- if source is None:
- source = py.code.Source("???")
- return source.deindent()
-
+ if source is not None:
+ source = source.deindent()
+ return source
+
def _saferepr(self, obj):
return safe_repr._repr(obj)
@@ -166,7 +166,11 @@
def repr_traceback_entry(self, entry, excinfo=None):
# excinfo is not None if this is the last tb entry
source = self._getentrysource(entry)
- line_index = entry.lineno - entry.getfirstlinesource()
+ if source is None:
+ source = py.code.Source("???")
+ line_index = 0
+ else:
+ line_index = entry.lineno - entry.getfirstlinesource()
lines = []
if self.style == "long":
Modified: py/trunk/py/code/testing/test_excinfo.py
==============================================================================
--- py/trunk/py/code/testing/test_excinfo.py (original)
+++ py/trunk/py/code/testing/test_excinfo.py Mon Sep 8 17:51:38 2008
@@ -305,6 +305,65 @@
repr = pr.repr_excinfo(excinfo)
assert repr.reprtraceback.reprentries[1].lines[0] == "> ???"
+ def test_repr_many_line_source_not_existing(self):
+ pr = FormattedExcinfo()
+ co = compile("""
+a = 1
+raise ValueError()
+""", "", "exec")
+ try:
+ exec co
+ except ValueError:
+ excinfo = py.code.ExceptionInfo()
+ repr = pr.repr_excinfo(excinfo)
+ assert repr.reprtraceback.reprentries[1].lines[0] == "> ???"
+
+ def test_repr_source_failing_fullsource(self):
+ pr = FormattedExcinfo()
+
+ class FakeCode(object):
+ path = '?'
+ firstlineno = 5
+
+ @property
+ def fullsource(self):
+ raise fail
+
+ class FakeFrame(object):
+ code = FakeCode()
+ f_locals = {}
+
+ class FakeTracebackEntry(py.code.Traceback.Entry):
+ def __init__(self, tb):
+ self.frame = FakeFrame()
+ self.lineno = 5+3
+
+ class Traceback(py.code.Traceback):
+ Entry = FakeTracebackEntry
+
+ class FakeExcinfo(py.code.ExceptionInfo):
+ typename = "Foo"
+ def __init__(self):
+ pass
+
+ def exconly(self, tryshort):
+ return "EXC"
+
+ excinfo = FakeExcinfo()
+ class FakeRawTB(object):
+ tb_next = None
+ tb = FakeRawTB()
+ excinfo.traceback = Traceback(tb)
+
+ fail = IOError()
+ repr = pr.repr_excinfo(excinfo)
+ assert repr.reprtraceback.reprentries[0].lines[0] == "> ???"
+
+ fail = py.error.ENOENT
+ repr = pr.repr_excinfo(excinfo)
+ assert repr.reprtraceback.reprentries[0].lines[0] == "> ???"
+
+
def test_repr_local(self):
p = FormattedExcinfo(showlocals=True)
loc = {'y': 5, 'z': 7, 'x': 3, '__builtins__': __builtins__}
@@ -581,4 +640,3 @@
'tbfilter': tbfilter
}
yield kw
-
Modified: py/trunk/py/code/traceback2.py
==============================================================================
--- py/trunk/py/code/traceback2.py (original)
+++ py/trunk/py/code/traceback2.py Mon Sep 8 17:51:38 2008
@@ -50,8 +50,11 @@
return self.frame.code.firstlineno
def getsource(self):
- """ return failing source code. """
- source = self.frame.code.fullsource
+ """ return failing source code. """
+ try:
+ source = self.frame.code.fullsource
+ except (IOError, py.error.ENOENT):
+ return None
if source is None:
try:
sourcelines, lineno = py.std.inspect.findsource(self.frame.code.raw)
More information about the pytest-commit
mailing list