Changeset 89

Show
Ignore:
Timestamp:
07/19/06 09:36:58 (2 years ago)
Author:
mk
Message:

Search for doctests inside docstrings (closes ticket #45).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/mk/cheesecake/cheesecake_index.py

    r87 r89  
    820820        return self.value 
    821821 
     822class IndexUseTestFramework(Index): 
     823    """Check if a package uses any of known test frameworks. 
     824 
     825    Currently only checking for doctest. 
     826    """ 
     827    max_value = 30 
     828 
     829    def compute(self, doctests_count): 
     830        if doctests_count > 0: 
     831            self.value = self.max_value 
     832            self.details = "found doctests" 
     833        else: 
     834            self.value = 0 
     835            self.details = "doesn't use any of known test frameworks" 
     836 
     837        return self.value 
     838 
    822839class IndexPyLint(Index): 
    823840    """Compute pylint index as average of positive pylint scores obtained for 
     
    903920        IndexPyLint, 
    904921        IndexUnitTests, 
     922        IndexUseTestFramework, 
    905923    ] 
    906924 
     
    13041322          docformat_cnt : int 
    13051323              Number of formatted docstrings found in all package objects. 
     1324          doctests_count : int 
     1325              Number of docstrings that include doctests. 
    13061326          files_list : list 
    13071327              List of files package contains. 
     
    13221342        self.docstring_cnt = 0 
    13231343        self.docformat_cnt = 0 
     1344        self.doctests_count = 0 
    13241345        self.functions = [] 
    13251346        self.classes = [] 
     
    13361357            self.functions += code.functions 
    13371358            self.classes += code.classes 
     1359            self.doctests_count += code.doctests_count 
    13381360 
    13391361        # Log a bit of debugging info. 
  • branches/mk/cheesecake/codeparser.py

    r83 r89  
     1import doctest 
    12import os 
    23import re 
    34 
    45from model import System, Module, Class, Function, parseFile, processModuleAst 
     6 
     7 
     8# Python 2.3/2.4 compatibilty hacks. 
     9if getattr(doctest, 'DocTestParser', False): 
     10    # Python 2.4 have DocTestParser class. 
     11    get_doctests = doctest.DocTestParser().get_examples 
     12else: 
     13    # Python 2.3 have _extract_examples function. 
     14    get_doctests = doctest._extract_examples 
    515 
    616 
     
    112122        self.docstrings_by_format = {} 
    113123        self.formatted_docstrings_count = 0 
     124        self.doctests_count = 0 
    114125 
    115126        # Initialize lists of format docstrings. 
     
    146157                    self.formatted_docstrings_count += 1 
    147158 
     159                # Check if docstring include any doctests. 
     160                if get_doctests(obj.docstring): 
     161                    self.doctests_count += 1 
     162 
    148163        for method_or_func in self.method_func: 
    149164            method_found = 0 
     
    161176        self.log("functions: " + ",".join(self.functions)) 
    162177        self.log("docstrings: %s" % self.docstrings_by_format) 
     178        self.log("number of doctests: %d" % self.doctests_count) 
    163179 
    164180    def object_count(self): 
  • branches/mk/tests/unit/test_index_unittests.py

    r83 r89  
    77import _path_cheesecake 
    88 
    9 from _helper_cheesecake import Glutton 
    109from cheesecake.cheesecake_index import IndexUnitTests 
    1110from cheesecake import logger