# 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
|
|
15 | 15 | tests = [] |
16 | 16 | good = [] |
17 | 17 | 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*:') |
18 | 23 | while True: |
19 | | i = file.find('def ') |
20 | | if i == -1: |
| 24 | i = df.search(file) |
| 25 | if i is None: |
21 | 26 | break |
| 27 | i = i.start() |
22 | 28 | |
23 | | e = re.compile('\)\s*:') |
24 | | m = e.search(file[i:]) |
| 29 | m = ee.search(file[i:]) |
25 | 30 | if m is None: |
26 | 31 | break |
27 | 32 | j = m.end() + i |
… |
… |
|
32 | 37 | |
33 | 38 | # Skip line if it is commented out. |
34 | 39 | if prev.lstrip().startswith('#'): |
35 | | file = file[j:] |
| 40 | file = file[:i] + file[j:] |
36 | 41 | continue |
37 | 42 | |
38 | 43 | #Skip functions which are defined in doctests |
39 | 44 | if 'sage:' in prev or '...' in prev: |
40 | | file = file[j:] |
| 45 | file = file[:i] + file[j:] |
41 | 46 | continue |
42 | 47 | |
43 | 48 | function_name = ' '.join(file[i:j].lstrip('def').split()) |
… |
… |
|
52 | 57 | file = file[j:] |
53 | 58 | skip_this = True |
54 | 59 | 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 | |
55 | 73 | if skip_this: |
56 | 74 | 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 | |
58 | 80 | k = file[j:].find('\n') |
59 | 81 | if k == -1: |
60 | 82 | break |