- 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.Frame' : ('./code/frame.py', 'Frame'),
'code.ExceptionInfo' : ('./code/excinfo.py', 'ExceptionInfo'), 'code.ExceptionInfo' : ('./code/excinfo.py', 'ExceptionInfo'),
'code.Traceback' : ('./code/traceback2.py', 'Traceback'), 'code.Traceback' : ('./code/traceback2.py', 'Traceback'),
'code.getfslineno' : ('./code/source.py', 'getfslineno'),
# backports and additions of builtins # backports and additions of builtins
'builtin.__doc__' : ('./builtin/__init__.py', '__doc__'), '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 import py
from py.__.test.collect import configproperty, warnoldcollect from py.__.test.collect import configproperty, warnoldcollect
from py.__.code.source import findsource
pydir = py.path.local(py.__file__).dirpath() pydir = py.path.local(py.__file__).dirpath()
from py.__.test import funcargs from py.__.test import funcargs
@ -69,37 +68,21 @@ class PyobjMixin(object):
s = ".".join(parts) s = ".".join(parts)
return s.replace(".[", "[") return s.replace(".[", "[")
def getfslineno(self): def _getfslineno(self):
try: try:
return self._fslineno return self._fslineno
except AttributeError: except AttributeError:
pass pass
obj = self.obj obj = self.obj
# let decorators etc specify a sane ordering # xxx let decorators etc specify a sane ordering
if hasattr(obj, 'place_as'): if hasattr(obj, 'place_as'):
obj = obj.place_as obj = obj.place_as
try:
code = py.code.Code(obj) self._fslineno = py.code.getfslineno(obj)
except TypeError: return self._fslineno
# 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
def metainfo(self): def metainfo(self):
fspath, lineno = self.getfslineno() fspath, lineno = self._getfslineno()
modpath = self.getmodpath() modpath = self.getmodpath()
return fspath, lineno, modpath return fspath, lineno, modpath
@ -233,7 +216,7 @@ class Class(PyCollectorMixin, py.test.collect.Collector):
teardown_class(self.obj) teardown_class(self.obj)
def _getsortvalue(self): def _getsortvalue(self):
return self.getfslineno() return self._getfslineno()
class Instance(PyCollectorMixin, py.test.collect.Collector): class Instance(PyCollectorMixin, py.test.collect.Collector):
def _getobj(self): def _getobj(self):
@ -258,7 +241,7 @@ class FunctionMixin(PyobjMixin):
""" """
def _getsortvalue(self): def _getsortvalue(self):
return self.getfslineno() return self._getfslineno()
def setup(self): def setup(self):
""" perform setup for this test function. """ """ 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) return report_process_crash(item, result)
def report_process_crash(item, result): def report_process_crash(item, result):
path, lineno = item.getfslineno() path, lineno = item._getfslineno()
longrepr = [ longrepr = [
("X", "CRASHED"), ("X", "CRASHED"),
("%s:%s: CRASHED with signal %d" %(path, lineno, result.signal)), ("%s:%s: CRASHED with signal %d" %(path, lineno, result.signal)),