示例#1
0
    def test_docstrings(self):
        #import mvpa2.suite as mv
        from mvpa2.suite import suite_stats
        # Lets do compliance checks
        # Get gross information on what we have in general
        #mv_scope = dict((x, getattr(mv, x)) for x in dir(mv))
        gs = suite_stats()#mv_scope)

        # all functions/classes/types should have some docstring
        missing = []
        # We should not have both :Parameters: and new style Parameters
        conflicting = []
        con_re1 = re.compile(':Parameters?:')
        con_re2 = re.compile('(?::Parameters?:.*Parameters?\s*\n\s*-------'
                             '|Parameters?\s*\n\s*-------.*:Parameters?:)',
                             flags=re.DOTALL)
        for c in ('functions', 'modules', 'objects', 'types') \
          + ('classes',) if sys.version_info[0] < 3 else ():
            missing1 = []
            conflicting1 = []
            self.assertTrue(gs[c])
            for k, i in gs[c].iteritems():
                try:
                    s = i.__doc__.strip()
                except: # pragma: no cover - should not be hit if ok_
                    s = ""
                if s == "":
                    missing1.append(k)

                if hasattr(i, '__init__') and not c in ['objects']:
                    # Smoke test get_docstring_split which would be used
                    # if someone specifies incorrect keyword argument
                    _ = get_docstring_split(i.__init__)
                    #if not None in _:
                    #    print [x[0] for x in _[1]]
                    si = i.__init__.__doc__
                    k += '.__init__'
                    if si is None or si == "":
                        try:
                            i_file = inspect.getfile(i)
                            if i_file == inspect.getfile(i.__init__) \
                               and 'mvpa' in i_file:
                                # if __init__ wasn't simply taken from some parent
                                # which is not within MVPA
                                missing1.append(k)
                        except TypeError:
                            # for some things like 'debug' inspect can't figure path
                            # just skip for now
                            pass
                else:
                    si = s

                if si is not None \
                       and  con_re1.search(si) and con_re2.search(si):
                    conflicting1.append(k)
            if len(missing1): # pragma: no cover - should not be hit if ok_
                missing.append("%s: " % c + ', '.join(missing1))
            if len(conflicting1): # pragma: no cover - should not be hit if ok_
                conflicting.append("%s: " % c + ', '.join(conflicting1))

        sfailures = []
        if len(missing): # pragma: no cover - should not be hit if ok_
            sfailures += ["Some items have missing docstrings:\n "
                          + '\n '.join(missing)]
        if len(conflicting): # pragma: no cover - should not be hit if ok_
            sfailures += ["Some items have conflicting formats of docstrings:\n "
                      + '\n '.join(conflicting)]
        if len(sfailures): # pragma: no cover - should not be hit if ok_
            self.fail('\n'.join(sfailures))
示例#2
0
    def test_docstrings(self):
        #import mvpa2.suite as mv
        from mvpa2.suite import suite_stats
        # Lets do compliance checks
        # Get gross information on what we have in general
        #mv_scope = dict((x, getattr(mv, x)) for x in dir(mv))
        gs = suite_stats()  #mv_scope)

        # all functions/classes/types should have some docstring
        missing = []
        # We should not have both :Parameters: and new style Parameters
        conflicting = []
        con_re1 = re.compile(':Parameters?:')
        con_re2 = re.compile(
            '(?::Parameters?:.*Parameters?\s*\n\s*-------'
            '|Parameters?\s*\n\s*-------.*:Parameters?:)',
            flags=re.DOTALL)
        for c in ('functions', 'modules', 'objects', 'types') \
          + ('classes',) if sys.version_info[0] < 3 else ():
            missing1 = []
            conflicting1 = []
            self.assertTrue(gs[c])
            for k, i in gs[c].iteritems():
                try:
                    s = i.__doc__.strip()
                except:  # pragma: no cover - should not be hit if ok_
                    s = ""
                if s == "":
                    missing1.append(k)

                if hasattr(i, '__init__') and not c in ['objects']:
                    # Smoke test get_docstring_split which would be used
                    # if someone specifies incorrect keyword argument
                    _ = get_docstring_split(i.__init__)
                    #if not None in _:
                    #    print [x[0] for x in _[1]]
                    si = i.__init__.__doc__
                    k += '.__init__'
                    if si is None or si == "":
                        try:
                            i_file = inspect.getfile(i)
                            if i_file == inspect.getfile(i.__init__) \
                               and 'mvpa' in i_file:
                                # if __init__ wasn't simply taken from some parent
                                # which is not within MVPA
                                missing1.append(k)
                        except TypeError:
                            # for some things like 'debug' inspect can't figure path
                            # just skip for now
                            pass
                else:
                    si = s

                if si is not None \
                       and  con_re1.search(si) and con_re2.search(si):
                    conflicting1.append(k)
            if len(missing1):  # pragma: no cover - should not be hit if ok_
                missing.append("%s: " % c + ', '.join(missing1))
            if len(conflicting1
                   ):  # pragma: no cover - should not be hit if ok_
                conflicting.append("%s: " % c + ', '.join(conflicting1))

        sfailures = []
        if len(missing):  # pragma: no cover - should not be hit if ok_
            sfailures += [
                "Some items have missing docstrings:\n " + '\n '.join(missing)
            ]
        if len(conflicting):  # pragma: no cover - should not be hit if ok_
            sfailures += [
                "Some items have conflicting formats of docstrings:\n " +
                '\n '.join(conflicting)
            ]
        if len(sfailures):  # pragma: no cover - should not be hit if ok_
            self.fail('\n'.join(sfailures))
示例#3
0
    def test_docstrings(self):
        from mvpa2.suite import suite_stats
        # Lets do compliance checks
        # Get gross information on what we have in general
        gs = suite_stats()

        # all functions/classes/types should have some docstring
        missing = []
        # We should not have both :Parameters: and new style Parameters
        conflicting = []
        con_re1 = re.compile(':Parameters?:')
        con_re2 = re.compile('(?::Parameters?:.*Parameters?\s*\n\s*-------'
                             '|Parameters?\s*\n\s*-------.*:Parameters?:)',
                             flags=re.DOTALL)
        for c in ('classes', 'functions', 'modules', 'objects',
                  'types'):
            missing1 = []
            conflicting1 = []
            for k, i in gs[c].iteritems():
                try:
                    s = i.__doc__.strip()
                except:
                    s = ""
                if s == "":
                    missing1.append(k)

                if hasattr(i, '__init__') and not c in ['objects']:
                    si = i.__init__.__doc__
                    k += '.__init__'
                    if si is None or si == "":
                        try:
                            i_file = inspect.getfile(i)
                            if i_file == inspect.getfile(i.__init__) \
                               and 'mvpa' in i_file:
                                # if __init__ wasn't simply taken from some parent
                                # which is not within MVPA
                                missing1.append(k)
                        except TypeError:
                            # for some things like 'debug' inspect can't figure path
                            # just skip for now
                            pass
                else:
                    si = s

                if si is not None \
                       and  con_re1.search(si) and con_re2.search(si):
                    conflicting1.append(k)
            if len(missing1):
                missing.append("%s: " % c + ', '.join(missing1))
            if len(conflicting1):
                conflicting.append("%s: " % c + ', '.join(conflicting1))

        sfailures = []
        if len(missing):
            sfailures += ["Some items have missing docstrings:\n "
                          + '\n '.join(missing)]
        if len(conflicting):
            sfailures += ["Some items have conflicting formats of docstrings:\n "
                      + '\n '.join(conflicting)]
        if len(sfailures):
            self.fail('\n'.join(sfailures))