| OLD | NEW |
| (Empty) |
| 1 from twisted.trial import unittest | |
| 2 import inspect, glob, os | |
| 3 from os import path | |
| 4 | |
| 5 from twisted.python import reflect | |
| 6 | |
| 7 import twisted | |
| 8 | |
| 9 def errorInFile(f, line=17, name=''): | |
| 10 """Return a filename formatted so emacs will recognize it as an error point | |
| 11 | |
| 12 @param line: Line number in file. Defaults to 17 because that's about how | |
| 13 long the copyright headers are. | |
| 14 """ | |
| 15 return '%s:%d:%s' % (f, line, name) | |
| 16 # return 'File "%s", line %d, in %s' % (f, line, name) | |
| 17 | |
| 18 class DocCoverage(unittest.TestCase): | |
| 19 def setUp(self): | |
| 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('/','.') | |
| 24 dirlist.append(d) | |
| 25 self.packageNames = [] | |
| 26 os.path.walk(os.path.dirname(twisted.__file__), | |
| 27 visit, self.packageNames) | |
| 28 | |
| 29 def testModules(self): | |
| 30 """Looking for docstrings in all modules.""" | |
| 31 docless = [] | |
| 32 for packageName in self.packageNames: | |
| 33 if packageName in ('twisted.test',): | |
| 34 # because some stuff in here behaves oddly when imported | |
| 35 continue | |
| 36 try: | |
| 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.) | |
| 42 # print e | |
| 43 pass | |
| 44 else: | |
| 45 docless.extend(self.modulesInPackage(packageName, package)) | |
| 46 self.failIf(docless, "No docstrings in module files:\n" | |
| 47 "%s" % ('\n'.join(map(errorInFile, docless)),)) | |
| 48 | |
| 49 def modulesInPackage(self, packageName, package): | |
| 50 docless = [] | |
| 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. | |
| 56 continue | |
| 57 elif moduleName in ('spelunk_gnome','gtkmanhole'): | |
| 58 # argh special case pygtk evil argh. How does epydoc deal | |
| 59 # with this? | |
| 60 continue | |
| 61 try: | |
| 62 module = reflect.namedModule('.'.join([packageName, | |
| 63 moduleName])) | |
| 64 except Exception, e: | |
| 65 # print moduleName, "misbehaved:", e | |
| 66 pass | |
| 67 else: | |
| 68 if not inspect.getdoc(module): | |
| 69 docless.append(modfile) | |
| 70 return docless | |
| 71 | |
| 72 def testPackages(self): | |
| 73 """Looking for docstrings in all packages.""" | |
| 74 docless = [] | |
| 75 for packageName in self.packageNames: | |
| 76 try: | |
| 77 package = reflect.namedModule(packageName) | |
| 78 except Exception, e: | |
| 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.) | |
| 82 # print e | |
| 83 pass | |
| 84 else: | |
| 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),))) | |
| 89 | |
| 90 | |
| 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 f
ixing GTK crashing bugs." | |
| OLD | NEW |