[py-svn] r33651 - in py/dist/py/apigen: rest rest/testing tracer
fijal at codespeak.net
fijal at codespeak.net
Tue Oct 24 14:57:56 CEST 2006
Author: fijal
Date: Tue Oct 24 14:57:54 2006
New Revision: 33651
Modified:
py/dist/py/apigen/rest/genrest.py
py/dist/py/apigen/rest/testing/test_rest.py
py/dist/py/apigen/tracer/description.py
py/dist/py/apigen/tracer/docstorage.py
Log:
Added function source.
Modified: py/dist/py/apigen/rest/genrest.py
==============================================================================
--- py/dist/py/apigen/rest/genrest.py (original)
+++ py/dist/py/apigen/rest/genrest.py Tue Oct 24 14:57:54 2006
@@ -108,6 +108,7 @@
class RestGen(object):
def __init__(self, ds, linkgen, writer=PipeWriter()):
+ #assert isinstance(linkgen, DirectPaste), "Cannot use different linkgen by now"
self.dsa = DocStorageAccessor(ds)
self.linkgen = linkgen
self.writer = writer
@@ -191,7 +192,8 @@
# lst.append(Paragraph("Function source: ",
# Link(linkname, linktarget)))
#else:
- lst.append(Paragraph('Function source: <unknown>'))
+ lst.append(Paragraph('Function source:'))
+ lst.append(LiteralBlock(self.dsa.get_function_source(fun_name)))
args, retval = self.dsa.get_function_signature(fun_name)
# XXX: we just do "knowntype" here, but we should
Modified: py/dist/py/apigen/rest/testing/test_rest.py
==============================================================================
--- py/dist/py/apigen/rest/testing/test_rest.py (original)
+++ py/dist/py/apigen/rest/testing/test_rest.py Tue Oct 24 14:57:54 2006
@@ -218,3 +218,22 @@
r = RestGen(ds, lg, DirWriter(tempdir))
r.write()
self.check_rest(tempdir)
+
+ def test_function_source(self):
+ def blah():
+ a = 3
+ b = 4
+ return a + b
+
+ descs = {'blah':blah}
+ ds = DocStorage().from_dict(descs)
+ t = Tracer(ds)
+ t.start_tracing()
+ blah()
+ t.end_tracing()
+ lg = DirectPaste()
+ tempdir = temppath.ensure("function_source", dir=True)
+ r = RestGen(ds, lg, DirWriter(tempdir))
+ r.write()
+ assert tempdir.join("function_blah.txt").open().read().find("a = 3") != -1
+ self.check_rest(tempdir)
Modified: py/dist/py/apigen/tracer/description.py
==============================================================================
--- py/dist/py/apigen/tracer/description.py (original)
+++ py/dist/py/apigen/tracer/description.py Tue Oct 24 14:57:54 2006
@@ -1,9 +1,4 @@
-#try:
-# from pypy.annotation import model
-#except ImportError:
-# pass
-
from py.__.apigen.tracer import model
import types
Modified: py/dist/py/apigen/tracer/docstorage.py
==============================================================================
--- py/dist/py/apigen/tracer/docstorage.py (original)
+++ py/dist/py/apigen/tracer/docstorage.py Tue Oct 24 14:57:54 2006
@@ -15,11 +15,6 @@
class DocStorage(object):
""" Class storing info about API
"""
- #def __init__(self):
- #self.bookkeeper = Bookkeeper(DummyAnnotator())
- #self.call_stack = []
- #self.frames = []
-
def consider_call(self, frame, caller_frame):
assert isinstance(frame, py.code.Frame)
desc = self.find_desc(frame.code)
@@ -191,6 +186,13 @@
def get_function_signature(self, name):
desc = self.ds.descs[name]
return desc.inputcells, desc.retval
+
+ def get_function_source(self, name):
+ desc = self.ds.descs[name]
+ try:
+ return str(py.code.Source(desc.pyobj))
+ except IOError:
+ return "Cannot get source"
def get_function_callpoints(self, name):
# return list of tuple (filename, fileline, frame)
More information about the pytest-commit
mailing list