[py-svn] r34624 - in py/dist/py/apigen/rest: . testing
guido at codespeak.net
guido at codespeak.net
Wed Nov 15 13:19:43 CET 2006
Author: guido
Date: Wed Nov 15 13:19:41 2006
New Revision: 34624
Modified:
py/dist/py/apigen/rest/genrest.py
py/dist/py/apigen/rest/htmlhandlers.py
py/dist/py/apigen/rest/testing/test_rest.py
Log:
Removing headers of empty sections, made casing more consistently applied,
improved title in index.html (a bit).
Modified: py/dist/py/apigen/rest/genrest.py
==============================================================================
--- py/dist/py/apigen/rest/genrest.py (original)
+++ py/dist/py/apigen/rest/genrest.py Wed Nov 15 13:19:41 2006
@@ -200,8 +200,8 @@
Rest(*tbrest))
def build_index(self, modules):
- rest = [Title('Index', abovechar='=', belowchar='=')]
- rest.append(Title('Exported modules:', belowchar='='))
+ rest = [Title('index', abovechar='=', belowchar='=')]
+ rest.append(Title('exported modules:', belowchar='='))
for module in modules:
mtitle = module
if module == '':
@@ -218,23 +218,25 @@
mname = module
if mname == '':
mname = self.dsa.get_module_name()
- rest = [Title('Module: %s' % (mname,), abovechar='=',
+ rest = [Title('module: %s' % (mname,), abovechar='=',
belowchar='='),
- Title('Index:', belowchar='=')]
- rest.append(Title('Classes:', belowchar='^'))
- for cls, cfunclist in classes:
- linktarget = self.writer.getlink('class', cls,
- 'class_%s' % (cls,))
- rest.append(ListItem(Link(cls, linktarget)))
+ Title('index:', belowchar='=')]
+ if classes:
+ rest.append(Title('classes:', belowchar='^'))
+ for cls, cfunclist in classes:
+ linktarget = self.writer.getlink('class', cls,
+ 'class_%s' % (cls,))
+ rest.append(ListItem(Link(cls, linktarget)))
classrest = self.build_classes(classes)
- rest.append(Title('Functions:', belowchar='^'))
- for func in functions:
- if module:
- func = '%s.%s' % (module, func)
- linktarget = self.writer.getlink('function',
- func,
- 'function_%s' % (func,))
- rest.append(ListItem(Link(func, linktarget)))
+ if functions:
+ rest.append(Title('functions:', belowchar='^'))
+ for func in functions:
+ if module:
+ func = '%s.%s' % (module, func)
+ linktarget = self.writer.getlink('function',
+ func,
+ 'function_%s' % (func,))
+ rest.append(ListItem(Link(func, linktarget)))
funcrest = self.build_functions(functions, module, False)
ret.append((module, rest, classrest, funcrest))
return ret
@@ -242,14 +244,17 @@
def build_classes(self, classes):
ret = []
for cls, functions in classes:
- rest = [Title('Class: %s' % (cls,), belowchar='='),
- LiteralBlock(self.dsa.get_doc(cls)),
- Title('Functions:', belowchar='^')]
- for func in functions:
- linktarget = self.writer.getlink('method',
- '%s.%s' % (cls, func),
- 'method_%s.%s' % (cls, func))
- rest.append(ListItem(Link('%s.%s' % (cls, func), linktarget)))
+ rest = [Title('class: %s' % (cls,), belowchar='='),
+ LiteralBlock(self.dsa.get_doc(cls))]
+ if functions:
+ rest.append(Title('functions:', belowchar='^'))
+ for func in functions:
+ linktarget = self.writer.getlink('method',
+ '%s.%s' % (cls, func),
+ 'method_%s.%s' % (cls,
+ func))
+ rest.append(ListItem(Link('%s.%s' % (cls, func),
+ linktarget)))
funcrest = self.build_functions(functions, cls, True)
ret.append((cls, rest, funcrest))
return ret
@@ -327,17 +332,16 @@
# from indentation, or treated as ReST too (although this is obviously
# dangerous for non-ReST docstrings)...
if ismethod:
- title = 'Method: %s' % (functionname,)
+ title = 'method: %s' % (functionname,)
else:
- title = 'Function: %s' % (functionname,)
+ title = 'function: %s' % (functionname,)
lst = [Title(title, belowchar=belowchar),
LiteralBlock(self.dsa.get_doc(functionname)),
LiteralBlock(self.dsa.get_function_definition(functionname))]
lst.append(Paragraph("where:"))
-
args, retval = self.dsa.get_function_signature(functionname)
- for name, _type in args + [('Return value', retval)]:
+ for name, _type in args + [('return value', retval)]:
l = self.process_type_link(_type)
items = []
next = "%s :: " % name
@@ -354,14 +358,18 @@
lst.append(ListItem(*items))
local_changes = self.dsa.get_function_local_changes(functionname)
- lst.append(Paragraph('Changes in __dict__:'))
- for k, changeset in local_changes.iteritems():
- lst.append(ListItem('%s: %s' % (k, ', '.join(changeset))))
-
- lst.append(Paragraph('Exceptions that might appear in function body:'))
- for exc in self.dsa.get_function_exceptions(functionname):
- lst.append(ListItem(exc.__name__))
- # XXX: right now we leave it alone
+ if local_changes:
+ lst.append(Paragraph('changes in __dict__ after execution:'))
+ for k, changeset in local_changes.iteritems():
+ lst.append(ListItem('%s: %s' % (k, ', '.join(changeset))))
+
+ exceptions = self.dsa.get_function_exceptions(functionname)
+ if exceptions:
+ lst.append(Paragraph('exceptions that might appear during '
+ 'execution:'))
+ for exc in exceptions:
+ lst.append(ListItem(exc.__name__))
+ # XXX: right now we leave it alone
# XXX missing implementation of dsa.get_function_location()
#filename, lineno = self.dsa.get_function_location(functionname)
@@ -370,22 +378,27 @@
# lst.append(Paragraph("Function source: ",
# Link(linkname, linktarget)))
#else:
- lst.append(Paragraph('Function source:'))
- lst.append(LiteralBlock(self.dsa.get_function_source(functionname)))
+ source = self.dsa.get_function_source(functionname)
+ if source:
+ lst.append(Paragraph('function source:'))
+ lst.append(LiteralBlock(source))
# call sites..
- call_site_title = Title("Call sites:", belowchar='+')
- lst.append(call_site_title)
-
- # we have to think differently here. I would go for:
- # 1. A quick'n'dirty statement where call has appeared first (topmost)
- # 2. Link to short traceback
- # 3. Link to long traceback
+ call_sites = self.dsa.get_function_callpoints(functionname)
tbrest = []
- for call_site, _ in self.dsa.get_function_callpoints(functionname):
- fdata, tbdata = self.call_site_link(functionname, call_site)
- lst += fdata
- tbrest.append(tbdata)
+ if call_sites:
+ call_site_title = Title("call sites:", belowchar='+')
+ lst.append(call_site_title)
+
+ # we have to think differently here. I would go for:
+ # 1. A quick'n'dirty statement where call has appeared first
+ # (topmost)
+ # 2. Link to short traceback
+ # 3. Link to long traceback
+ for call_site, _ in call_sites:
+ fdata, tbdata = self.call_site_link(functionname, call_site)
+ lst += fdata
+ tbrest.append(tbdata)
return lst, tbrest
@@ -395,15 +408,15 @@
linktarget = self.writer.getlink('traceback',
tbname,
'traceback_%s' % (tbname,))
- frest = [Paragraph("Called in %s" % call_site[0].code.filename),
- Paragraph(Link("Full traceback %s" % (tbname,),
+ frest = [Paragraph("called in %s" % call_site[0].code.filename),
+ Paragraph(Link("traceback %s" % (tbname,),
linktarget))]
return frest, (tbname, tbrest)
def gen_traceback(self, funcname, call_site):
tbid = len(self.tracebacks.setdefault(funcname, []))
self.tracebacks[funcname].append(call_site)
- tbrest = [Title('Full traceback for %s' % (funcname,))]
+ tbrest = [Title('traceback for %s' % (funcname,))]
for line in reversed(call_site):
lineno = line.lineno - line.code.firstlineno
linkname, linktarget = self.linkgen.getlink(line.code.filename,
@@ -415,7 +428,7 @@
try:
source = line.code.source()
except IOError:
- source = "*Cannot get source*"
+ source = "*cannot get source*"
mangled = []
for i, sline in enumerate(str(source).split('\n')):
if i == lineno:
@@ -425,3 +438,4 @@
mangled.append(line)
tbrest.append(LiteralBlock('\n'.join(mangled)))
return tbid, tbrest
+
Modified: py/dist/py/apigen/rest/htmlhandlers.py
==============================================================================
--- py/dist/py/apigen/rest/htmlhandlers.py (original)
+++ py/dist/py/apigen/rest/htmlhandlers.py Wed Nov 15 13:19:41 2006
@@ -3,7 +3,7 @@
class PageHandler(HTMLHandler):
def startDocument(self):
self._data += ['<html>\n', '<head>\n',
- '<title>%s</title>\n' % (self.title,),
+ '<title>api reference</title>\n',
'<script type="text/javascript" src="apigen.js">',
'</script>',
('<link type="text/css" rel="stylesheet" '
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 Wed Nov 15 13:19:41 2006
@@ -259,22 +259,22 @@
data = tempfile.read()
# index should be above the rest
print data
- assert data.find('Classes\\:') > -1
- assert data.find('Classes\\:') < data.find('Function\\: fun')
- assert data.find('Classes\\:') < data.find(
- 'Class\\: SomeClass')
+ assert data.find('classes\\:') > -1
+ assert data.find('classes\\:') < data.find('function\\: fun')
+ assert data.find('classes\\:') < data.find(
+ 'class\\: SomeClass')
# function definitions should be above class ones
- assert data.find('Function\\: fun') > data.find('Class\\: SomeClass')
+ assert data.find('function\\: fun') > data.find('class\\: SomeClass')
# class method definitions should be below the class defs
- assert data.find('Class\\: SomeClass') < data.find(
- 'Method\\: SomeClass.method')
+ assert data.find('class\\: SomeClass') < data.find(
+ 'method\\: SomeClass.method')
# __init__ should be above other methods
- assert data.find('Method\\: SomeClass.\\_\\_init\\_\\_') > -1
- assert data.find('Method\\: SomeClass.\\_\\_init\\_\\_') < data.find(
- 'Method\\: SomeClass.method')
+ assert data.find('method\\: SomeClass.\\_\\_init\\_\\_') > -1
+ assert data.find('method\\: SomeClass.\\_\\_init\\_\\_') < data.find(
+ 'method\\: SomeClass.method')
def test_som_fun(self):
- descs = {'fun_':fun_}
+ descs = {'fun_': fun_}
ds = DocStorage().from_dict(descs)
t = Tracer(ds)
t.start_tracing()
@@ -292,7 +292,7 @@
b = 4
return a + b
- descs = {'blah':blah}
+ descs = {'blah': blah}
ds = DocStorage().from_dict(descs)
t = Tracer(ds)
t.start_tracing()
@@ -323,7 +323,7 @@
r = RestGen(ds, lg, DirWriter(tempdir))
r.write()
source = tempdir.join("function_blah.txt").read()
- call_point = source.find("Call sites\:")
+ call_point = source.find("call sites\:")
assert call_point != -1
assert source.find("a \:\: <Int>") < call_point
assert source.find("b \:\: <String>") < call_point
@@ -354,9 +354,10 @@
r = RestGen(ds, lg, DirWriter(tempdir))
r.write()
source = tempdir.join("function_xxx.txt").open().read()
- call_point = source.find("Call sites\:")
+ call_point = source.find("call sites\:")
assert call_point != -1
- assert source.find("x \:\: <Instance of AnyOf( `Class B`_ , `Class A`_ )>") < call_point
+ assert source.find("x \:\: <Instance of AnyOf( `Class B`_ , "
+ "`Class A`_ )>") < call_point
self.check_rest(tempdir)
def test_exc_raising(self):
@@ -377,4 +378,5 @@
r = RestGen(ds, lg, DirWriter(tempdir))
r.write()
source = tempdir.join('function_x.txt').open().read()
- assert source.find('ZeroDivisionError') < source.find('Call sites\:')
+ assert source.find('ZeroDivisionError') < source.find('call sites\:')
+
More information about the pytest-commit
mailing list