1
from twisted.trial import unittest
2
import inspect, glob, os
5
from twisted.python import reflect
9
def errorInFile(f, line=17, name=''):
10
"""Return a filename formatted so emacs will recognize it as an error point
12
@param line: Line number in file. Defaults to 17 because that's about how
13
long the copyright headers are.
15
return '%s:%d:%s' % (f, line, name)
16
# return 'File "%s", line %d, in %s' % (f, line, name)
18
class DocCoverage(unittest.TestCase):
20
remove = len(os.path.dirname(os.path.dirname(twisted.__file__)))+1
21
def visit(dirlist, directory, files):
22
if '__init__.py' in files:
23
d = directory[remove:].replace('/','.')
25
self.packageNames = []
26
os.path.walk(os.path.dirname(twisted.__file__),
27
visit, self.packageNames)
29
def testModules(self):
30
"""Looking for docstrings in all modules."""
32
for packageName in self.packageNames:
33
if packageName in ('twisted.test',):
34
# because some stuff in here behaves oddly when imported
37
package = reflect.namedModule(packageName)
38
except ImportError, e:
39
# This is testing doc coverage, not importability.
40
# (Really, I don't want to deal with the fact that I don't
41
# have pyserial installed.)
45
docless.extend(self.modulesInPackage(packageName, package))
46
self.failIf(docless, "No docstrings in module files:\n"
47
"%s" % ('\n'.join(map(errorInFile, docless)),))
49
def modulesInPackage(self, packageName, package):
51
directory = path.dirname(package.__file__)
52
for modfile in glob.glob(path.join(directory, '*.py')):
53
moduleName = inspect.getmodulename(modfile)
54
if moduleName == '__init__':
55
# These are tested by test_packages.
57
elif moduleName in ('spelunk_gnome','gtkmanhole'):
58
# argh special case pygtk evil argh. How does epydoc deal
62
module = reflect.namedModule('.'.join([packageName,
65
# print moduleName, "misbehaved:", e
68
if not inspect.getdoc(module):
69
docless.append(modfile)
72
def testPackages(self):
73
"""Looking for docstrings in all packages."""
75
for packageName in self.packageNames:
77
package = reflect.namedModule(packageName)
79
# This is testing doc coverage, not importability.
80
# (Really, I don't want to deal with the fact that I don't
81
# have pyserial installed.)
85
if not inspect.getdoc(package):
86
docless.append(package.__file__.replace('.pyc','.py'))
87
self.failIf(docless, "No docstrings for package files\n"
88
"%s" % ('\n'.join(map(errorInFile, docless),)))
91
# This test takes a while and doesn't come close to passing. :(
92
testModules.skip = "Activate me when you feel like writing docstrings, and fixing GTK crashing bugs."