[py-svn] r36299 - in py/dist/py/apigen/source: . testing
fijal at codespeak.net
fijal at codespeak.net
Mon Jan 8 18:02:46 CET 2007
Author: fijal
Date: Mon Jan 8 18:02:33 2007
New Revision: 36299
Modified:
py/dist/py/apigen/source/browser.py
py/dist/py/apigen/source/html.py
py/dist/py/apigen/source/testing/test_html.py
Log:
Added method links as well.
Modified: py/dist/py/apigen/source/browser.py
==============================================================================
--- py/dist/py/apigen/source/browser.py (original)
+++ py/dist/py/apigen/source/browser.py Mon Jan 8 18:02:33 2007
@@ -15,7 +15,10 @@
blockers = [ast.Function, ast.Class]
class BaseElem(object):
- pass # purely for testing isinstance
+ def listnames(self):
+ if getattr(self, 'parent', None):
+ return self.parent.listnames() + '.' + self.name
+ return self.name
class Module(BaseElem):
def __init__(self, path, _dict):
@@ -29,7 +32,11 @@
raise AttributeError(attr)
def get_children(self):
- return self.dict.values()
+ values = self.dict.values()
+ all = values[:]
+ for v in values:
+ all += v.get_children()
+ return all
def get_endline(start, lst):
l = reversed(lst)
@@ -42,22 +49,27 @@
return start
class Function(BaseElem):
- def __init__(self, name, firstlineno, endlineno):
+ def __init__(self, name, parent, firstlineno, endlineno):
self.firstlineno = firstlineno
self.endlineno = endlineno
self.name = name
+ self.parent = parent
+
+ def get_children(self):
+ return []
class Method(BaseElem):
- def __init__(self, name, firstlineno, endlineno):
+ def __init__(self, name, parent, firstlineno, endlineno):
self.name = name
self.firstlineno = firstlineno
self.endlineno = endlineno
+ self.parent = parent
-def function_from_ast(ast, cls=Function):
+def function_from_ast(ast, cls_ast, cls=Function):
startline = ast.lineno
endline = get_endline(startline, ast.getChildNodes())
assert endline
- return cls(ast.name, startline, endline)
+ return cls(ast.name, cls_ast, startline, endline)
def class_from_ast(cls_ast):
bases = [i.name for i in cls_ast.bases if isinstance(i, ast.Name)]
@@ -66,9 +78,10 @@
startline = cls_ast.lineno
name = cls_ast.name
endline = get_endline(startline, cls_ast.getChildNodes())
- methods = dict([(i.name, function_from_ast(i, Method)) for i in \
+ cls = Class(name, startline, endline, bases, [])
+ cls.methods = dict([(i.name, function_from_ast(i, cls, Method)) for i in \
cls_ast.code.nodes if isinstance(i, ast.Function)])
- return Class(name, startline, endline, bases, methods)
+ return cls
class Class(BaseElem):
def __init__(self, name, firstlineno, endlineno, bases, methods):
@@ -113,7 +126,7 @@
nodes = dir_nodes(st)
function_ast = [i for i in nodes if isinstance(i, ast.Function)]
classes_ast = [i for i in nodes if isinstance(i, ast.Class)]
- mod_dict = dict([(i.name, function_from_ast(i)) for i in function_ast]
+ mod_dict = dict([(i.name, function_from_ast(i, None)) for i in function_ast]
+ [(i.name, class_from_ast(i)) for i in classes_ast])
# we check all the elements, if they're really there
try:
Modified: py/dist/py/apigen/source/html.py
==============================================================================
--- py/dist/py/apigen/source/html.py (original)
+++ py/dist/py/apigen/source/html.py Mon Jan 8 18:02:33 2007
@@ -31,8 +31,8 @@
pos = row.find(item.name)
assert pos != -1
end = len(item.name) + pos
- chunk = html.a(row[pos:end], href="#" + item.name,
- name=item.name)
+ chunk = html.a(row[pos:end], href="#" + item.listnames(),
+ name=item.listnames())
return [row[:pos], chunk, row[end:]]
except KeyError:
return [row] # no more info
Modified: py/dist/py/apigen/source/testing/test_html.py
==============================================================================
--- py/dist/py/apigen/source/testing/test_html.py (original)
+++ py/dist/py/apigen/source/testing/test_html.py Mon Jan 8 18:02:33 2007
@@ -45,6 +45,7 @@
assert data.find('<a href="#func_two"') != -1
assert data.find('<a href="#B"') != -1
assert data.find('<a href="#A"') != -1
+ assert data.find('<a href="#A.meth1"') != -1
class _HTMLDocument(HTMLDocument):
def __init__(self):
More information about the pytest-commit
mailing list