- expose py.code.getfslineno and use it in pycollect

- rename PyobjMixin.getfslineno to PyobjMixin._getdslineno

- place_as still in place

--HG--
branch : trunk
This commit is contained in:
Samuele Pedroni 2009-05-12 13:39:09 +02:00
parent 89c025335f
commit 69214d053d
3 changed files with 10 additions and 26 deletions

View File

@ -133,6 +133,7 @@ initpkg(__name__,
'code.Frame' : ('./code/frame.py', 'Frame'),
'code.ExceptionInfo' : ('./code/excinfo.py', 'ExceptionInfo'),
'code.Traceback' : ('./code/traceback2.py', 'Traceback'),
'code.getfslineno' : ('./code/source.py', 'getfslineno'),
# backports and additions of builtins
'builtin.__doc__' : ('./builtin/__init__.py', '__doc__'),

View File

@ -18,7 +18,6 @@ a tree of collectors and test items that this modules provides::
"""
import py
from py.__.test.collect import configproperty, warnoldcollect
from py.__.code.source import findsource
pydir = py.path.local(py.__file__).dirpath()
from py.__.test import funcargs
@ -69,37 +68,21 @@ class PyobjMixin(object):
s = ".".join(parts)
return s.replace(".[", "[")
def getfslineno(self):
def _getfslineno(self):
try:
return self._fslineno
except AttributeError:
pass
obj = self.obj
# let decorators etc specify a sane ordering
# xxx let decorators etc specify a sane ordering
if hasattr(obj, 'place_as'):
obj = obj.place_as
try:
code = py.code.Code(obj)
except TypeError:
# fallback to
fn = (py.std.inspect.getsourcefile(obj) or
py.std.inspect.getfile(obj))
fspath = fn and py.path.local(fn) or None
if fspath:
try:
_, lineno = findsource(obj)
except IOError:
lineno = None
else:
lineno = None
else:
fspath = code.path
lineno = code.firstlineno
self._fslineno = fspath, lineno
return fspath, lineno
self._fslineno = py.code.getfslineno(obj)
return self._fslineno
def metainfo(self):
fspath, lineno = self.getfslineno()
fspath, lineno = self._getfslineno()
modpath = self.getmodpath()
return fspath, lineno, modpath
@ -233,7 +216,7 @@ class Class(PyCollectorMixin, py.test.collect.Collector):
teardown_class(self.obj)
def _getsortvalue(self):
return self.getfslineno()
return self._getfslineno()
class Instance(PyCollectorMixin, py.test.collect.Collector):
def _getobj(self):
@ -258,7 +241,7 @@ class FunctionMixin(PyobjMixin):
"""
def _getsortvalue(self):
return self.getfslineno()
return self._getfslineno()
def setup(self):
""" perform setup for this test function. """

View File

@ -76,7 +76,7 @@ def forked_run_report(item, pdb=None):
return report_process_crash(item, result)
def report_process_crash(item, result):
path, lineno = item.getfslineno()
path, lineno = item._getfslineno()
longrepr = [
("X", "CRASHED"),
("%s:%s: CRASHED with signal %d" %(path, lineno, result.signal)),