1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
import sys, types
from mpi4py import MPI
import mpiunittest as unittest
ModuleType = type(MPI)
ClassType = type(MPI.Comm)
FunctionType = type(MPI.Init)
MethodDescrType = type(MPI.Comm.Get_rank)
GetSetDescrType = type(MPI.Comm.rank)
def getdocstr(mc, docstrings, namespace=None):
name = getattr(mc, '__name__', None)
if name is None: return
if name in ('__builtin__', 'builtins'): return
if name.startswith('_'): return
if namespace: name = '%s.%s' % (namespace, name)
if type(mc) in (ModuleType, ClassType):
doc = getattr(mc, '__doc__', None)
if doc == "<undocumented>": return
docstrings[name] = doc
for k, v in vars(mc).items():
if isinstance(v, staticmethod):
v = v.__get__(object)
getdocstr(v, docstrings, name)
elif type(mc) in (FunctionType, MethodDescrType, GetSetDescrType):
doc = getattr(mc, '__doc__', None)
if doc == "<undocumented>": return
docstrings[name] = doc
class TestDoc(unittest.TestCase):
def testDoc(self):
missing = False
docs = { }
getdocstr(MPI, docs)
for k in docs:
if not k.startswith('_'):
doc = docs[k]
if doc is None:
print ("'%s': missing docstring" % k)
missing = True
else:
doc = doc.strip()
if not doc:
print ("'%s': empty docstring" % k)
missing = True
if 'mpi4py.MPI' in doc:
print ("'%s': bad format docstring" % k)
self.assertFalse(missing)
if hasattr(sys, 'pypy_version_info'):
del TestDoc.testDoc
if __name__ == '__main__':
unittest.main()
|