File: test_doc.py

package info (click to toggle)
mpi4py 1.3.1%2Bhg20131106-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,224 kB
  • ctags: 6,415
  • sloc: python: 12,056; ansic: 7,022; makefile: 697; f90: 158; cpp: 103; sh: 60
file content (51 lines) | stat: -rw-r--r-- 1,626 bytes parent folder | download
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
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)
        docstrings[name] = doc
        for k, v in vars(mc).items():
            getdocstr(v, docstrings, name)
    elif type(mc) in (FunctionType, MethodDescrType, GetSetDescrType):
        doc = getattr(mc, '__doc__', None)
        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()