- implement a general getfslineno helper in code/source.py with tests

- not exposed yey

--HG--
branch : trunk
This commit is contained in:
Samuele Pedroni
2009-05-12 12:36:43 +02:00
parent 9950fdc3eb
commit 1e5ece07e8
2 changed files with 40 additions and 0 deletions

View File

@@ -355,3 +355,23 @@ def test_findsource___source__():
assert 'if 1:' in str(src)
assert src[lineno] == " def x():"
def test_getfslineno():
from py.__.code.source import getfslineno
def f(x):
pass
fspath, lineno = getfslineno(f)
assert fspath == py.path.local(__file__)
assert lineno == f.func_code.co_firstlineno-1 # see findsource
class A(object):
pass
fspath, lineno = getfslineno(A)
_, A_lineno = py.std.inspect.findsource(A)
assert fspath == py.path.local(__file__)
assert lineno == A_lineno