[py-svn] r37155 - in py/dist/py/apigen: . testing
guido at codespeak.net
guido at codespeak.net
Mon Jan 22 19:23:08 CET 2007
Author: guido
Date: Mon Jan 22 19:23:07 2007
New Revision: 37155
Modified:
py/dist/py/apigen/htmlgen.py
py/dist/py/apigen/testing/test_apigen_example.py
py/dist/py/apigen/testing/test_apigen_functional.py
Log:
Some improvements in function HTML, small cleanup in tests (there's now a
single create_namespace_tree call done for all the apigen tests).
Modified: py/dist/py/apigen/htmlgen.py
==============================================================================
--- py/dist/py/apigen/htmlgen.py (original)
+++ py/dist/py/apigen/htmlgen.py Mon Jan 22 19:23:07 2007
@@ -288,32 +288,28 @@
""" build the html for a class method """
# XXX we may want to have seperate
func = self.dsa.get_obj(dotted_name)
- sourcefile = inspect.getsourcefile(func)
docstring = func.__doc__
- local_methodname = func.__name__
+ localname = func.__name__
argdesc = get_param_htmldesc(self.linker, func)
valuedesc = self.build_callable_value_description(dotted_name)
-
+
+ sourcefile = inspect.getsourcefile(func)
callable_source = self.dsa.get_function_source(dotted_name)
- if callable_source:
+ # i assume they're both either available or unavailable(XXX ?)
+ if sourcefile and callable_source:
csource = H.div(H.br(),
- H.div('source:'),
+ H.a('source:',
+ href=self.linker.get_lazyhref(sourcefile)),
+ H.br(),
H.SourceDef(H.pre(callable_source)))
else:
- csource = H.SourceDef('could not get source')
-
- if sourcefile is not None:
- sourcelink = H.a('view source file',
- href=self.linker.get_lazyhref(sourcefile))
- else:
- sourcelink = H.span('no source file available')
+ csource = H.SourceDef('could not get source file')
snippet = H.FunctionDescription(
- H.FunctionDef(local_methodname, argdesc),
+ H.FunctionDef(localname, argdesc),
valuedesc,
- H.Docstring(docstring),
+ H.Docstring(docstring or H.em('no docstring available')),
csource,
- sourcelink,
)
return snippet
@@ -321,14 +317,20 @@
def build_class_view(self, dotted_name):
""" build the html for a class """
cls = self.dsa.get_obj(dotted_name)
+ # XXX is this a safe check?
try:
sourcefile = inspect.getsourcefile(cls)
except TypeError:
- return H.div('builtin file')
- if sourcefile is None:
- return H.div('no source available')
- if sourcefile[-1] in ['o', 'c']:
- sourcefile = sourcefile[:-1]
+ sourcelink = 'builtin file, no source available'
+ else:
+ if sourcefile is None:
+ sourcelink = H.div('no source available')
+ else:
+ if sourcefile[-1] in ['o', 'c']:
+ sourcefile = sourcefile[:-1]
+ sourcelink = H.div(H.a('source',
+ href=self.linker.get_lazyhref(sourcefile)))
+
docstring = cls.__doc__
methods = self.dsa.get_class_methods(dotted_name)
basehtml = []
@@ -345,11 +347,15 @@
if basehtml:
basehtml.pop()
basehtml.append('):')
+ if not hasattr(cls, '__name__'):
+ clsname = 'instance of %s' % (cls.__class__.__name__,)
+ else:
+ clsname = cls.__name__
snippet = H.ClassDescription(
# XXX bases HTML
- H.ClassDef('%s(' % (cls.__name__,), *basehtml),
- H.a('source', href=self.linker.get_lazyhref(sourcefile)),
- H.Docstring(docstring),
+ H.ClassDef('%s(' % (clsname,), *basehtml),
+ sourcelink,
+ H.Docstring(docstring or H.em('no docstring available')),
)
snippet.append(H.h2('Functions:'))
for method in methods:
@@ -359,6 +365,7 @@
def build_namespace_view(self, namespace_dotted_name, item_dotted_names):
""" build the html for a namespace (module) """
+ print 'building namespace for', namespace_dotted_name
snippet = H.NamespaceDescription(
H.NamespaceDef(namespace_dotted_name),
)
Modified: py/dist/py/apigen/testing/test_apigen_example.py
==============================================================================
--- py/dist/py/apigen/testing/test_apigen_example.py (original)
+++ py/dist/py/apigen/testing/test_apigen_example.py Mon Jan 22 19:23:07 2007
@@ -35,6 +35,7 @@
def get_somevar(self):
" get_somevar docstring "
return self.somevar
+ SomeInstance = SomeClass(10)
"""))
temp.ensure('pkg/somesubclass.py').write(py.code.Source("""\
from someclass import SomeClass
@@ -43,12 +44,21 @@
def get_somevar(self):
return self.somevar + 1
"""))
+ temp.ensure('pkg/somenamespace.py').write(py.code.Source("""\
+ def foo():
+ return 'bar'
+ def baz(qux):
+ return qux
+ """))
temp.ensure("pkg/__init__.py").write(py.code.Source("""\
from py.initpkg import initpkg
initpkg(__name__, exportdefs = {
'main.sub.func': ("./func.py", "func"),
'main.SomeClass': ('./someclass.py', 'SomeClass'),
+ 'main.SomeInstance': ('./someclass.py', 'SomeInstance'),
+ 'main.SomeSubClass': ('./somesubclass.py', 'SomeSubClass'),
'main.SomeSubClass': ('./somesubclass.py', 'SomeSubClass'),
+ 'other': ('./somenamespace.py', '*'),
})
"""))
return temp, 'pkg'
@@ -96,6 +106,13 @@
self.linker = linker = LinkerForTests()
self.apb = ApiPageBuilder(base, linker, self.dsa)
self.spb = SourcePageBuilder(base, linker, self.fs_root)
+ self.namespace_tree = create_namespace_tree(['main.sub',
+ 'main.sub.func',
+ 'main.SomeClass',
+ 'main.SomeSubClass',
+ 'main.SomeInstance',
+ 'other.foo',
+ 'other.bar'])
class TestApiPageBuilder(AbstractBuilderTest):
def test_build_callable_view(self):
@@ -122,10 +139,7 @@
_checkhtmlsnippet(html)
def test_build_function_pages(self):
- namespace_tree = create_namespace_tree(['main.sub', 'main.sub.func',
- 'main.SomeClass',
- 'main.SomeSubClass'])
- data = self.apb.prepare_function_pages(namespace_tree,
+ data = self.apb.prepare_function_pages(self.namespace_tree,
['main.sub.func'])
self.apb.build_function_pages(data, self.project)
funcfile = self.base.join('api/main.sub.func.html')
@@ -139,10 +153,7 @@
_checkhtmlsnippet(html)
def test_build_class_pages(self):
- namespace_tree = create_namespace_tree(['main.SomeClass',
- 'main.SomeSubClass',
- 'main.sub.func'])
- data, methodsdata = self.apb.prepare_class_pages(namespace_tree,
+ data, methodsdata = self.apb.prepare_class_pages(self.namespace_tree,
['main.SomeClass',
'main.SomeSubClass'])
self.apb.build_class_pages(data, self.project)
@@ -151,11 +162,22 @@
html = clsfile.read()
_checkhtml(html)
+ def test_build_class_pages_instance(self):
+ data, methodsdata = self.apb.prepare_class_pages(self.namespace_tree,
+ ['main.SomeClass',
+ 'main.SomeSubClass',
+ 'main.SomeInstance'])
+ self.apb.build_class_pages(data, self.project)
+ clsfile = self.base.join('api/main.SomeInstance.html')
+ assert clsfile.check()
+ html = clsfile.read()
+ print html
+ run_string_sequence_test(html, [
+ 'instance of SomeClass()',
+ ])
+
def test_build_class_pages_nav_links(self):
- namespace_tree = create_namespace_tree(['main.SomeClass',
- 'main.SomeSubClass',
- 'main.sub.func'])
- data, methodsdata = self.apb.prepare_class_pages(namespace_tree,
+ data, methodsdata = self.apb.prepare_class_pages(self.namespace_tree,
['main.SomeSubClass',
'main.SomeClass'])
# fake some stuff that would be built from other methods
@@ -179,10 +201,7 @@
_checkhtml(html)
def test_build_class_pages_base_link(self):
- namespace_tree = create_namespace_tree(['main.SomeClass',
- 'main.SomeSubClass',
- 'main.sub.func'])
- data, methodsdata = self.apb.prepare_class_pages(namespace_tree,
+ data, methodsdata = self.apb.prepare_class_pages(self.namespace_tree,
['main.SomeSubClass',
'main.SomeClass'])
self.apb.build_class_pages(data, self.project)
@@ -197,10 +216,7 @@
_checkhtml(html)
def test_source_links(self):
- namespace_tree = create_namespace_tree(['main.SomeClass',
- 'main.SomeSubClass',
- 'main.sub.func'])
- data, methodsdata = self.apb.prepare_class_pages(namespace_tree,
+ data, methodsdata = self.apb.prepare_class_pages(self.namespace_tree,
['main.SomeSubClass',
'main.SomeClass'])
sourcedata = self.spb.prepare_pages(self.fs_root)
@@ -210,15 +226,28 @@
assert funchtml.find('href="../source/pkg/someclass.py.html"') > -1
_checkhtml(funchtml)
+ def test_build_namespace_pages(self):
+ data = self.apb.prepare_namespace_pages(self.namespace_tree)
+ self.apb.build_namespace_pages(data, self.project)
+ mainfile = self.base.join('api/main.html')
+ assert mainfile.check()
+ html = mainfile.read()
+ print html
+ run_string_sequence_test(html, [
+ 'index of main namespace',
+ ])
+ otherfile = self.base.join('api/other.html')
+ assert otherfile.check()
+ otherhtml = otherfile.read()
+ print otherhtml
+ run_string_sequence_test(otherhtml, [
+ 'index of other namespace',
+ ])
+ _checkhtml(html)
+ _checkhtml(otherhtml)
+
def test_build_namespace_pages_index(self):
- namespace_tree = create_namespace_tree(['main.sub', 'main.sub.func',
- 'main.SomeClass',
- 'main.SomeSubClass'])
- data = self.apb.prepare_namespace_pages(namespace_tree)
- self.apb.prepare_class_pages(namespace_tree,
- ['main.SomeClass',
- 'main.SomeSubClass'])
- self.apb.prepare_function_pages(namespace_tree, ['main.sub.func'])
+ data = self.apb.prepare_namespace_pages(self.namespace_tree)
self.apb.build_namespace_pages(data, self.project)
pkgfile = self.base.join('api/index.html')
assert pkgfile.check()
@@ -227,10 +256,7 @@
_checkhtml(html)
def test_build_namespace_pages_subnamespace(self):
- namespace_tree = create_namespace_tree(['main.sub', 'main.sub.func',
- 'main.SomeClass',
- 'main.SomeSubClass'])
- data = self.apb.prepare_namespace_pages(namespace_tree)
+ data = self.apb.prepare_namespace_pages(self.namespace_tree)
self.apb.build_namespace_pages(data, self.project)
subfile = self.base.join('api/main.sub.html')
assert subfile.check()
@@ -238,10 +264,7 @@
_checkhtml(html)
def test_build_function_api_pages_nav(self):
- namespace_tree = create_namespace_tree(['main.sub', 'main.sub.func',
- 'main.SomeClass',
- 'main.SomeSubClass'])
- data = self.apb.prepare_function_pages(namespace_tree,
+ data = self.apb.prepare_function_pages(self.namespace_tree,
['main.sub.func'])
self.linker.set_link('', 'api/index.html')
self.linker.set_link('main', 'api/main.html')
@@ -259,11 +282,8 @@
_checkhtml(html)
def test_build_function_navigation(self):
- namespace_tree = create_namespace_tree(['main.sub', 'main.sub.func',
- 'main.SomeClass',
- 'main.SomeSubClass'])
- self.apb.prepare_namespace_pages(namespace_tree)
- self.apb.prepare_function_pages(namespace_tree, ['main.sub.func'])
+ self.apb.prepare_namespace_pages(self.namespace_tree)
+ self.apb.prepare_function_pages(self.namespace_tree, ['main.sub.func'])
nav = self.apb.build_navigation('main.sub', ['main.sub.func'],
'main.sub.func')
html = nav.unicode(indent=0)
@@ -277,10 +297,7 @@
) in html
def test_build_root_namespace_view(self):
- namespace_tree = create_namespace_tree(['main.sub', 'main.sub.func',
- 'main.SomeClass',
- 'main.SomeSubClass'])
- data = self.apb.prepare_namespace_pages(namespace_tree)
+ data = self.apb.prepare_namespace_pages(self.namespace_tree)
self.apb.build_namespace_pages(data, self.project)
rootfile = self.base.join('api/index.html')
assert rootfile.check()
Modified: py/dist/py/apigen/testing/test_apigen_functional.py
==============================================================================
--- py/dist/py/apigen/testing/test_apigen_functional.py (original)
+++ py/dist/py/apigen/testing/test_apigen_functional.py Mon Jan 22 19:23:07 2007
@@ -31,13 +31,20 @@
def get_somevar(self):
return self.somevar + 1
"""))
+ temp.ensure('pkg/somenamespace.py').write(py.code.Source("""\
+ def foo():
+ return 'bar'
+ def baz(qux):
+ return qux
+ """))
temp.ensure("pkg/__init__.py").write(py.code.Source("""\
from py.initpkg import initpkg
initpkg(__name__, exportdefs = {
'main.sub.func': ("./func.py", "func"),
'main.func': ("./func.py", "func_2"),
'main.SomeTestClass': ('./sometestclass.py', 'SomeTestClass'),
- 'main.SomeTestSubClass': ('./sometestsubclass.py', 'SomeTestSubClass'),
+ 'main.SomeTestSubClass': ('./sometestsubclass.py',
+ 'SomeTestSubClass'),
})
"""))
temp.ensure('pkg/test/test_pkg.py').write(py.code.Source("""\
More information about the pytest-commit
mailing list