Ticket #877: trac_877-scripts-coverage2.patch

File trac_877-scripts-coverage2.patch, 2.6 KB (added by jhpalmieri, 8 months ago)

use this version instead

  • sage-coverage

    # HG changeset patch
    # User J. H. Palmieri <palmieri@math.washington.edu>
    # Date 1248533921 25200
    # Node ID 53bfb91ca24c08cea470d70b85f19ff8605e43d5
    # Parent  50fc172b894f6edc599718d5255814fdababdf91
    try to deal with closures in sage -coverage (#877)
    
    diff -r 50fc172b894f -r 53bfb91ca24c sage-coverage
    a b  
    1515    tests = [] 
    1616    good  = [] 
    1717    possibly_wrong = [] 
     18    closures = []  # functions nested within others -- ignore when computing coverage 
     19    indentation = 0 
     20    cython = re.search('c[p]?def', file)  # true if it looks like a cython file 
     21    df = re.compile('def\s+\w') 
     22    ee = re.compile('\)\s*:') 
    1823    while True: 
    19         i = file.find('def ') 
    20         if i == -1: 
     24        i = df.search(file) 
     25        if i is None: 
    2126            break 
     27        i = i.start() 
    2228 
    23         e = re.compile('\)\s*:') 
    24         m = e.search(file[i:]) 
     29        m = ee.search(file[i:]) 
    2530        if m is None: 
    2631            break 
    2732        j = m.end() + i 
     
    3237             
    3338            # Skip line if it is commented out. 
    3439            if prev.lstrip().startswith('#'): 
    35                 file = file[j:] 
     40                file = file[:i] + file[j:] 
    3641                continue 
    3742 
    3843            #Skip functions which are defined in doctests 
    3944            if 'sage:' in prev or '...' in prev: 
    40                 file = file[j:] 
     45                file = file[:i] + file[j:] 
    4146                continue 
    4247         
    4348        function_name = ' '.join(file[i:j].lstrip('def').split()) 
     
    5257                file = file[j:] 
    5358                skip_this = True 
    5459                break 
     60 
     61        new_indentation = file[z:i].count(' ') 
     62        # try to determine if this is a closure (i.e., nested function). 
     63        # don't worry about cython files, just plain python. 
     64        if not cython: 
     65            clss = re.search("^\s*(cdef)?\s*class\s+", file[:i], re.M) 
     66            if not clss:  # not the first function after a class definition 
     67                # if indented more than current indentation level, it's a closure 
     68                if new_indentation > indentation: 
     69                    file = file[i+2:] 
     70                    closures.append(function_name) 
     71                    skip_this = True 
     72 
    5573        if skip_this: 
    5674            continue 
    57              
     75 
     76        # number of spaces this def is indented.  use this to check if 
     77        # the next def is nested. 
     78        indentation = new_indentation 
     79         
    5880        k = file[j:].find('\n') 
    5981        if k == -1: 
    6082            break