Changeset 39

Show
Ignore:
Timestamp:
06/03/06 15:05:29 (6 years ago)
Author:
mk
Message:

Added more unit tests for docstring indexing code (closes ticket #13).

Files:

Legend:

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

    r38 r39  
    99    """ 
    1010 
    11     # Word in reST can also contain hyphens and punctuation characters. 
     11    # Handy regular expressions. 
    1212    mapping = {'ALPHA': r'[-.,?!\w]', 'WORD': r'[-.,?!\s\w]', 
    1313                       'START': r'(^|\s)', 'END': r'([.,?!\s]|$)'} 
  • branches/mk/tests/data/module1.py

    r37 r39  
    9999class Class3(object): 
    100100    """ 
    101     Class with epytext link: U{http://pycheesecake.org}. 
     101    New-style class with epytext link: U{http://pycheesecake.org}. 
    102102    """ 
    103103    pass 
    104104 
     105 
     106def outer_function(*args): 
     107    x = 42 
     108 
     109    def inner_function(): 
     110        """Short docstring.""" 
     111        pass 
     112 
     113    return x 
  • branches/mk/tests/test_code_parser.py

    r37 r39  
    4343            "module1.func7", 
    4444            "module1.func8", 
     45            "module1.outer_function", 
     46            "module1.outer_function.inner_function", 
    4547        ] 
    4648 
    4749    def test_count(self): 
    48         assert self.code1.object_count() == 19 
    49         assert self.code1.docstring_count() == 16 
     50        assert self.code1.object_count() == 21 
     51        assert self.code1.docstring_count() == 17 
    5052        assert self.code1.docstring_count_by_type('reST') == 2 
    5153        assert self.code1.docstring_count_by_type('epytext') == 3 
     
    7072            "module1.func7", 
    7173            "module1.func8", 
     74            "module1.outer_function.inner_function", 
    7275        ] 
    7376        objects_with_rest_docstrings = [ 
  • branches/mk/tests/test_index_docstrings.py

    r33 r39  
    99class TestIndexDocstrings(object): 
    1010    def setUp(self): 
    11         self.cheesecake = Cheesecake(path=os.path.join(datadir, "package1.tar.gz")) 
    12         self.code = CodeParser(os.path.join(self.cheesecake.sandbox, "package1/module1.py")) 
    13         self.index_float = float(self.code.docstring_count()) / float(self.code.object_count()) 
     11        self.cheesecake = Cheesecake(path=os.path.join(datadir, "package2.tar.gz")) 
     12 
     13        modules = 5 
     14        classes = 2 
     15        functions = 4 
     16        methods = 3 
     17 
     18        self.documentable_objects = modules + classes + functions + methods 
     19        self.docstring_count = 7 
     20 
     21        self.index_float = float(self.docstring_count) / self.documentable_objects 
    1422        self.index_int = int(ceil(self.index_float*100)) 
    1523 
     
    1927    def test_index_docstrings(self): 
    2028        index = self.cheesecake.index_docstrings() 
     29 
    2130        assert index.name == "index_docstrings" 
    2231        assert index.value == self.index_int 
    2332        assert index.details == "found %d/%d=%.2f%% modules/classes/methods/functions with docstrings" %\ 
    24                             (self.code.docstring_count(), self.code.object_count(), self.index_float*100) 
     33                            (self.docstring_count, self.documentable_objects, self.index_float*100)