Ticket #877: trac_877-scripts-coverage.patch

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

apply to scripts repository

  • sage-coverage

    # HG changeset patch
    # User J. H. Palmieri <palmieri@math.washington.edu>
    # Date 1248479707 25200
    # Node ID a78172995c6e10994667f120cc9299036c201a62
    # Parent  50fc172b894f6edc599718d5255814fdababdf91
    try to deal with closures in sage -coverage (#877)
    
    diff -r 50fc172b894f -r a78172995c6e sage-coverage
    a b  
    1515    tests = [] 
    1616    good  = [] 
    1717    possibly_wrong = [] 
     18    indentation = 0 
     19    cython = re.search('c[p]?def', file)  # true if it looks like a cython file 
    1820    while True: 
    19         i = file.find('def ') 
    20         if i == -1: 
     21        df = re.compile('def\s+\w') 
     22        i = df.search(file) 
     23        if i is None: 
    2124            break 
     25        i = i.start() 
    2226 
    2327        e = re.compile('\)\s*:') 
    2428        m = e.search(file[i:]) 
     
    3236             
    3337            # Skip line if it is commented out. 
    3438            if prev.lstrip().startswith('#'): 
    35                 file = file[j:] 
     39                file = file[:i] + file[j:] 
    3640                continue 
    3741 
    3842            #Skip functions which are defined in doctests 
    3943            if 'sage:' in prev or '...' in prev: 
    40                 file = file[j:] 
     44                file = file[:i] + file[j:] 
    4145                continue 
    4246         
    4347        function_name = ' '.join(file[i:j].lstrip('def').split()) 
     
    5256                file = file[j:] 
    5357                skip_this = True 
    5458                break 
     59 
     60        new_indentation = file[z:i].count(' ') 
     61        # try to determine if this is a closure (i.e., nested function). 
     62        # don't worry about cython files, just plain python. 
     63        if not cython: 
     64            clss = re.search("^\s*(cdef)?\s*class\s+", file[:i], re.M) 
     65            if not clss:  # not the first function after a class definition 
     66                # if indented more than current indentation level, it's a closure 
     67                if new_indentation > indentation: 
     68                    file = file[i+2:] 
     69                    skip_this = True 
     70 
    5571        if skip_this: 
    5672            continue 
    57              
     73 
     74        # number of spaces this def is indented.  use this to check if 
     75        # the next def is nested. 
     76        indentation = new_indentation 
     77         
    5878        k = file[j:].find('\n') 
    5979        if k == -1: 
    6080            break