1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
7 from twisted.trial import unittest
8 from twisted.python import reflect
9 from twisted.python.modules import getModule
13 def errorInFile(f, line=17, name=''):
15 Return a filename formatted so emacs will recognize it as an error point
17 @param line: Line number in file. Defaults to 17 because that's about how
18 long the copyright headers are.
20 return '%s:%d:%s' % (f, line, name)
21 # return 'File "%s", line %d, in %s' % (f, line, name)
24 class DocCoverage(unittest.TestCase):
26 Looking for docstrings in all modules and packages.
29 self.packageNames = []
30 for mod in getModule('twisted').walkModules():
32 self.packageNames.append(mod.name)
35 def testModules(self):
37 Looking for docstrings in all modules.
40 for packageName in self.packageNames:
41 if packageName in ('twisted.test',):
42 # because some stuff in here behaves oddly when imported
45 package = reflect.namedModule(packageName)
46 except ImportError, e:
47 # This is testing doc coverage, not importability.
48 # (Really, I don't want to deal with the fact that I don't
49 # have pyserial installed.)
53 docless.extend(self.modulesInPackage(packageName, package))
54 self.failIf(docless, "No docstrings in module files:\n"
55 "%s" % ('\n'.join(map(errorInFile, docless)),))
58 def modulesInPackage(self, packageName, package):
60 directory = path.dirname(package.__file__)
61 for modfile in glob.glob(path.join(directory, '*.py')):
62 moduleName = inspect.getmodulename(modfile)
63 if moduleName == '__init__':
64 # These are tested by test_packages.
66 elif moduleName in ('spelunk_gnome','gtkmanhole'):
67 # argh special case pygtk evil argh. How does epydoc deal
71 module = reflect.namedModule('.'.join([packageName,
74 # print moduleName, "misbehaved:", e
77 if not inspect.getdoc(module):
78 docless.append(modfile)
82 def testPackages(self):
84 Looking for docstrings in all packages.
87 for packageName in self.packageNames:
89 package = reflect.namedModule(packageName)
91 # This is testing doc coverage, not importability.
92 # (Really, I don't want to deal with the fact that I don't
93 # have pyserial installed.)
97 if not inspect.getdoc(package):
98 docless.append(package.__file__.replace('.pyc','.py'))
99 self.failIf(docless, "No docstrings for package files\n"
100 "%s" % ('\n'.join(map(errorInFile, docless),)))
103 # This test takes a while and doesn't come close to passing. :(
104 testModules.skip = "Activate me when you feel like writing docstrings, and fixing GTK crashing bugs."