Mercurial > hg
annotate tests/coverage.py @ 6289:91ac1726730a
issue 1003: send all data properly
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Sun, 16 Mar 2008 22:59:04 -0700 |
parents | a7178d4ed8ee |
children | 6aaf5b1d8f15 |
rev | line source |
---|---|
5594
8623debad845
coverage: return to not assuming that python is in /usr/bin
Bryan O'Sullivan <bos@serpentine.com>
parents:
5592
diff
changeset
|
1 #!/usr/bin/env python |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
2 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
3 # Perforce Defect Tracking Integration Project |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
4 # <http://www.ravenbrook.com/project/p4dti/> |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
5 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
6 # COVERAGE.PY -- COVERAGE TESTING |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
7 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
8 # Gareth Rees, Ravenbrook Limited, 2001-12-04 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
9 # Ned Batchelder, 2004-12-12 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
10 # http://nedbatchelder.com/code/modules/coverage.html |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
11 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
12 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
13 # 1. INTRODUCTION |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
14 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
15 # This module provides coverage testing for Python code. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
16 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
17 # The intended readership is all Python developers. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
18 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
19 # This document is not confidential. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
20 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
21 # See [GDR 2001-12-04a] for the command-line interface, programmatic |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
22 # interface and limitations. See [GDR 2001-12-04b] for requirements and |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
23 # design. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
24 |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
25 r"""Usage: |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
26 |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
27 coverage.py -x [-p] MODULE.py [ARG1 ARG2 ...] |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
28 Execute module, passing the given command-line arguments, collecting |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
29 coverage data. With the -p option, write to a temporary file containing |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
30 the machine name and process ID. |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
31 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
32 coverage.py -e |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
33 Erase collected coverage data. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
34 |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
35 coverage.py -c |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
36 Collect data from multiple coverage files (as created by -p option above) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
37 and store it into a single file representing the union of the coverage. |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
38 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
39 coverage.py -r [-m] [-o dir1,dir2,...] FILE1 FILE2 ... |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
40 Report on the statement coverage for the given files. With the -m |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
41 option, show line numbers of the statements that weren't executed. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
42 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
43 coverage.py -a [-d dir] [-o dir1,dir2,...] FILE1 FILE2 ... |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
44 Make annotated copies of the given files, marking statements that |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
45 are executed with > and statements that are missed with !. With |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
46 the -d option, make the copies in that directory. Without the -d |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
47 option, make each copy in the same directory as the original. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
48 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
49 -o dir,dir2,... |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
50 Omit reporting or annotating files when their filename path starts with |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
51 a directory listed in the omit list. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
52 e.g. python coverage.py -i -r -o c:\python23,lib\enthought\traits |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
53 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
54 Coverage data is saved in the file .coverage by default. Set the |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
55 COVERAGE_FILE environment variable to save it somewhere else.""" |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
56 |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
57 __version__ = "2.77.20070729" # see detailed history at the end of this file. |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
58 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
59 import compiler |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
60 import compiler.visitor |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
61 import glob |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
62 import os |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
63 import re |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
64 import string |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
65 import symbol |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
66 import sys |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
67 import threading |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
68 import token |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
69 import types |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
70 from socket import gethostname |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
71 |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
72 # Python version compatibility |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
73 try: |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
74 strclass = basestring # new to 2.3 |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
75 except: |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
76 strclass = str |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
77 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
78 # 2. IMPLEMENTATION |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
79 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
80 # This uses the "singleton" pattern. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
81 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
82 # The word "morf" means a module object (from which the source file can |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
83 # be deduced by suitable manipulation of the __file__ attribute) or a |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
84 # filename. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
85 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
86 # When we generate a coverage report we have to canonicalize every |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
87 # filename in the coverage dictionary just in case it refers to the |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
88 # module we are reporting on. It seems a shame to throw away this |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
89 # information so the data in the coverage dictionary is transferred to |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
90 # the 'cexecuted' dictionary under the canonical filenames. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
91 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
92 # The coverage dictionary is called "c" and the trace function "t". The |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
93 # reason for these short names is that Python looks up variables by name |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
94 # at runtime and so execution time depends on the length of variables! |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
95 # In the bottleneck of this application it's appropriate to abbreviate |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
96 # names to increase speed. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
97 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
98 class StatementFindingAstVisitor(compiler.visitor.ASTVisitor): |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
99 """ A visitor for a parsed Abstract Syntax Tree which finds executable |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
100 statements. |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
101 """ |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
102 def __init__(self, statements, excluded, suite_spots): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
103 compiler.visitor.ASTVisitor.__init__(self) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
104 self.statements = statements |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
105 self.excluded = excluded |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
106 self.suite_spots = suite_spots |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
107 self.excluding_suite = 0 |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
108 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
109 def doRecursive(self, node): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
110 for n in node.getChildNodes(): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
111 self.dispatch(n) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
112 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
113 visitStmt = visitModule = doRecursive |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
114 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
115 def doCode(self, node): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
116 if hasattr(node, 'decorators') and node.decorators: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
117 self.dispatch(node.decorators) |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
118 self.recordAndDispatch(node.code) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
119 else: |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
120 self.doSuite(node, node.code) |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
121 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
122 visitFunction = visitClass = doCode |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
123 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
124 def getFirstLine(self, node): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
125 # Find the first line in the tree node. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
126 lineno = node.lineno |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
127 for n in node.getChildNodes(): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
128 f = self.getFirstLine(n) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
129 if lineno and f: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
130 lineno = min(lineno, f) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
131 else: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
132 lineno = lineno or f |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
133 return lineno |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
134 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
135 def getLastLine(self, node): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
136 # Find the first line in the tree node. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
137 lineno = node.lineno |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
138 for n in node.getChildNodes(): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
139 lineno = max(lineno, self.getLastLine(n)) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
140 return lineno |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
141 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
142 def doStatement(self, node): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
143 self.recordLine(self.getFirstLine(node)) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
144 |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
145 visitAssert = visitAssign = visitAssTuple = visitPrint = \ |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
146 visitPrintnl = visitRaise = visitSubscript = visitDecorators = \ |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
147 doStatement |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
148 |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
149 def visitPass(self, node): |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
150 # Pass statements have weird interactions with docstrings. If this |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
151 # pass statement is part of one of those pairs, claim that the statement |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
152 # is on the later of the two lines. |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
153 l = node.lineno |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
154 if l: |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
155 lines = self.suite_spots.get(l, [l,l]) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
156 self.statements[lines[1]] = 1 |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
157 |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
158 def visitDiscard(self, node): |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
159 # Discard nodes are statements that execute an expression, but then |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
160 # discard the results. This includes function calls, so we can't |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
161 # ignore them all. But if the expression is a constant, the statement |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
162 # won't be "executed", so don't count it now. |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
163 if node.expr.__class__.__name__ != 'Const': |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
164 self.doStatement(node) |
3223
53e843840349
Whitespace/Tab cleanup
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2144
diff
changeset
|
165 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
166 def recordNodeLine(self, node): |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
167 # Stmt nodes often have None, but shouldn't claim the first line of |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
168 # their children (because the first child might be an ignorable line |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
169 # like "global a"). |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
170 if node.__class__.__name__ != 'Stmt': |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
171 return self.recordLine(self.getFirstLine(node)) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
172 else: |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
173 return 0 |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
174 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
175 def recordLine(self, lineno): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
176 # Returns a bool, whether the line is included or excluded. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
177 if lineno: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
178 # Multi-line tests introducing suites have to get charged to their |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
179 # keyword. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
180 if lineno in self.suite_spots: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
181 lineno = self.suite_spots[lineno][0] |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
182 # If we're inside an excluded suite, record that this line was |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
183 # excluded. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
184 if self.excluding_suite: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
185 self.excluded[lineno] = 1 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
186 return 0 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
187 # If this line is excluded, or suite_spots maps this line to |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
188 # another line that is exlcuded, then we're excluded. |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5760
diff
changeset
|
189 elif lineno in self.excluded or \ |
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5760
diff
changeset
|
190 lineno in self.suite_spots and \ |
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5760
diff
changeset
|
191 self.suite_spots[lineno][1] in self.excluded: |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
192 return 0 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
193 # Otherwise, this is an executable line. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
194 else: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
195 self.statements[lineno] = 1 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
196 return 1 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
197 return 0 |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
198 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
199 default = recordNodeLine |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
200 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
201 def recordAndDispatch(self, node): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
202 self.recordNodeLine(node) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
203 self.dispatch(node) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
204 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
205 def doSuite(self, intro, body, exclude=0): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
206 exsuite = self.excluding_suite |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
207 if exclude or (intro and not self.recordNodeLine(intro)): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
208 self.excluding_suite = 1 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
209 self.recordAndDispatch(body) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
210 self.excluding_suite = exsuite |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
211 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
212 def doPlainWordSuite(self, prevsuite, suite): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
213 # Finding the exclude lines for else's is tricky, because they aren't |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
214 # present in the compiler parse tree. Look at the previous suite, |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
215 # and find its last line. If any line between there and the else's |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
216 # first line are excluded, then we exclude the else. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
217 lastprev = self.getLastLine(prevsuite) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
218 firstelse = self.getFirstLine(suite) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
219 for l in range(lastprev+1, firstelse): |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5760
diff
changeset
|
220 if l in self.suite_spots: |
6047
a7178d4ed8ee
fix syntax in coverage.py, fixing run-tests.py -C
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5915
diff
changeset
|
221 self.doSuite(None, suite, exclude=l in self.excluded) |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
222 break |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
223 else: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
224 self.doSuite(None, suite) |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
225 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
226 def doElse(self, prevsuite, node): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
227 if node.else_: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
228 self.doPlainWordSuite(prevsuite, node.else_) |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
229 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
230 def visitFor(self, node): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
231 self.doSuite(node, node.body) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
232 self.doElse(node.body, node) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
233 |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
234 visitWhile = visitFor |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
235 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
236 def visitIf(self, node): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
237 # The first test has to be handled separately from the rest. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
238 # The first test is credited to the line with the "if", but the others |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
239 # are credited to the line with the test for the elif. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
240 self.doSuite(node, node.tests[0][1]) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
241 for t, n in node.tests[1:]: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
242 self.doSuite(t, n) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
243 self.doElse(node.tests[-1][1], node) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
244 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
245 def visitTryExcept(self, node): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
246 self.doSuite(node, node.body) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
247 for i in range(len(node.handlers)): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
248 a, b, h = node.handlers[i] |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
249 if not a: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
250 # It's a plain "except:". Find the previous suite. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
251 if i > 0: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
252 prev = node.handlers[i-1][2] |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
253 else: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
254 prev = node.body |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
255 self.doPlainWordSuite(prev, h) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
256 else: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
257 self.doSuite(a, h) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
258 self.doElse(node.handlers[-1][2], node) |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
259 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
260 def visitTryFinally(self, node): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
261 self.doSuite(node, node.body) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
262 self.doPlainWordSuite(node.body, node.final) |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
263 |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
264 def visitWith(self, node): |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
265 self.doSuite(node, node.body) |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
266 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
267 def visitGlobal(self, node): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
268 # "global" statements don't execute like others (they don't call the |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
269 # trace function), so don't record their line numbers. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
270 pass |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
271 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
272 the_coverage = None |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
273 |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
274 class CoverageException(Exception): pass |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
275 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
276 class coverage: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
277 # Name of the cache file (unless environment variable is set). |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
278 cache_default = ".coverage" |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
279 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
280 # Environment variable naming the cache file. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
281 cache_env = "COVERAGE_FILE" |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
282 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
283 # A dictionary with an entry for (Python source file name, line number |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
284 # in that file) if that line has been executed. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
285 c = {} |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
286 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
287 # A map from canonical Python source file name to a dictionary in |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
288 # which there's an entry for each line number that has been |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
289 # executed. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
290 cexecuted = {} |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
291 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
292 # Cache of results of calling the analysis2() method, so that you can |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
293 # specify both -r and -a without doing double work. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
294 analysis_cache = {} |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
295 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
296 # Cache of results of calling the canonical_filename() method, to |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
297 # avoid duplicating work. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
298 canonical_filename_cache = {} |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
299 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
300 def __init__(self): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
301 global the_coverage |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
302 if the_coverage: |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
303 raise CoverageException, "Only one coverage object allowed." |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
304 self.usecache = 1 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
305 self.cache = None |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
306 self.parallel_mode = False |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
307 self.exclude_re = '' |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
308 self.nesting = 0 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
309 self.cstack = [] |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
310 self.xstack = [] |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
311 self.relative_dir = os.path.normcase(os.path.abspath(os.curdir)+os.sep) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
312 self.exclude('# *pragma[: ]*[nN][oO] *[cC][oO][vV][eE][rR]') |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
313 |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
314 # t(f, x, y). This method is passed to sys.settrace as a trace function. |
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
315 # See [van Rossum 2001-07-20b, 9.2] for an explanation of sys.settrace and |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
316 # the arguments and return value of the trace function. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
317 # See [van Rossum 2001-07-20a, 3.2] for a description of frame and code |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
318 # objects. |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
319 |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
320 def t(self, f, w, unused): #pragma: no cover |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
321 if w == 'line': |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
322 #print "Executing %s @ %d" % (f.f_code.co_filename, f.f_lineno) |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
323 self.c[(f.f_code.co_filename, f.f_lineno)] = 1 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
324 for c in self.cstack: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
325 c[(f.f_code.co_filename, f.f_lineno)] = 1 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
326 return self.t |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
327 |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
328 def help(self, error=None): #pragma: no cover |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
329 if error: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
330 print error |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
331 print |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
332 print __doc__ |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
333 sys.exit(1) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
334 |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
335 def command_line(self, argv, help_fn=None): |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
336 import getopt |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
337 help_fn = help_fn or self.help |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
338 settings = {} |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
339 optmap = { |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
340 '-a': 'annotate', |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
341 '-c': 'collect', |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
342 '-d:': 'directory=', |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
343 '-e': 'erase', |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
344 '-h': 'help', |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
345 '-i': 'ignore-errors', |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
346 '-m': 'show-missing', |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
347 '-p': 'parallel-mode', |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
348 '-r': 'report', |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
349 '-x': 'execute', |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
350 '-o:': 'omit=', |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
351 } |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
352 short_opts = string.join(map(lambda o: o[1:], optmap.keys()), '') |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
353 long_opts = optmap.values() |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
354 options, args = getopt.getopt(argv, short_opts, long_opts) |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
355 for o, a in options: |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5760
diff
changeset
|
356 if o in optmap: |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
357 settings[optmap[o]] = 1 |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5760
diff
changeset
|
358 elif o + ':' in optmap: |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
359 settings[optmap[o + ':']] = a |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
360 elif o[2:] in long_opts: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
361 settings[o[2:]] = 1 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
362 elif o[2:] + '=' in long_opts: |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
363 settings[o[2:]+'='] = a |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
364 else: #pragma: no cover |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
365 pass # Can't get here, because getopt won't return anything unknown. |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
366 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
367 if settings.get('help'): |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
368 help_fn() |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
369 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
370 for i in ['erase', 'execute']: |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
371 for j in ['annotate', 'report', 'collect']: |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
372 if settings.get(i) and settings.get(j): |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
373 help_fn("You can't specify the '%s' and '%s' " |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
374 "options at the same time." % (i, j)) |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
375 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
376 args_needed = (settings.get('execute') |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
377 or settings.get('annotate') |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
378 or settings.get('report')) |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
379 action = (settings.get('erase') |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
380 or settings.get('collect') |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
381 or args_needed) |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
382 if not action: |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
383 help_fn("You must specify at least one of -e, -x, -c, -r, or -a.") |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
384 if not args_needed and args: |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
385 help_fn("Unexpected arguments: %s" % " ".join(args)) |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
386 |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
387 self.parallel_mode = settings.get('parallel-mode') |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
388 self.get_ready() |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
389 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
390 if settings.get('erase'): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
391 self.erase() |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
392 if settings.get('execute'): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
393 if not args: |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
394 help_fn("Nothing to do.") |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
395 sys.argv = args |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
396 self.start() |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
397 import __main__ |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
398 sys.path[0] = os.path.dirname(sys.argv[0]) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
399 execfile(sys.argv[0], __main__.__dict__) |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
400 if settings.get('collect'): |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
401 self.collect() |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
402 if not args: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
403 args = self.cexecuted.keys() |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
404 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
405 ignore_errors = settings.get('ignore-errors') |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
406 show_missing = settings.get('show-missing') |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
407 directory = settings.get('directory=') |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
408 |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
409 omit = settings.get('omit=') |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
410 if omit is not None: |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
411 omit = omit.split(',') |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
412 else: |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
413 omit = [] |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
414 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
415 if settings.get('report'): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
416 self.report(args, show_missing, ignore_errors, omit_prefixes=omit) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
417 if settings.get('annotate'): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
418 self.annotate(args, directory, ignore_errors, omit_prefixes=omit) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
419 |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
420 def use_cache(self, usecache, cache_file=None): |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
421 self.usecache = usecache |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
422 if cache_file and not self.cache: |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
423 self.cache_default = cache_file |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
424 |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
425 def get_ready(self, parallel_mode=False): |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
426 if self.usecache and not self.cache: |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
427 self.cache = os.environ.get(self.cache_env, self.cache_default) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
428 if self.parallel_mode: |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
429 self.cache += "." + gethostname() + "." + str(os.getpid()) |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
430 self.restore() |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
431 self.analysis_cache = {} |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
432 |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
433 def start(self, parallel_mode=False): |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
434 self.get_ready() |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
435 if self.nesting == 0: #pragma: no cover |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
436 sys.settrace(self.t) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
437 if hasattr(threading, 'settrace'): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
438 threading.settrace(self.t) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
439 self.nesting += 1 |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
440 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
441 def stop(self): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
442 self.nesting -= 1 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
443 if self.nesting == 0: #pragma: no cover |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
444 sys.settrace(None) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
445 if hasattr(threading, 'settrace'): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
446 threading.settrace(None) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
447 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
448 def erase(self): |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
449 self.get_ready() |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
450 self.c = {} |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
451 self.analysis_cache = {} |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
452 self.cexecuted = {} |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
453 if self.cache and os.path.exists(self.cache): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
454 os.remove(self.cache) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
455 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
456 def exclude(self, re): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
457 if self.exclude_re: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
458 self.exclude_re += "|" |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
459 self.exclude_re += "(" + re + ")" |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
460 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
461 def begin_recursive(self): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
462 self.cstack.append(self.c) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
463 self.xstack.append(self.exclude_re) |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
464 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
465 def end_recursive(self): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
466 self.c = self.cstack.pop() |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
467 self.exclude_re = self.xstack.pop() |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
468 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
469 # save(). Save coverage data to the coverage cache. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
470 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
471 def save(self): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
472 if self.usecache and self.cache: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
473 self.canonicalize_filenames() |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
474 cache = open(self.cache, 'wb') |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
475 import marshal |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
476 marshal.dump(self.cexecuted, cache) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
477 cache.close() |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
478 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
479 # restore(). Restore coverage data from the coverage cache (if it exists). |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
480 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
481 def restore(self): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
482 self.c = {} |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
483 self.cexecuted = {} |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
484 assert self.usecache |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
485 if os.path.exists(self.cache): |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
486 self.cexecuted = self.restore_file(self.cache) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
487 |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
488 def restore_file(self, file_name): |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
489 try: |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
490 cache = open(file_name, 'rb') |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
491 import marshal |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
492 cexecuted = marshal.load(cache) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
493 cache.close() |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
494 if isinstance(cexecuted, types.DictType): |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
495 return cexecuted |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
496 else: |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
497 return {} |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
498 except: |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
499 return {} |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
500 |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
501 # collect(). Collect data in multiple files produced by parallel mode |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
502 |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
503 def collect(self): |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
504 cache_dir, local = os.path.split(self.cache) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
505 for f in os.listdir(cache_dir or '.'): |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
506 if not f.startswith(local): |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
507 continue |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
508 |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
509 full_path = os.path.join(cache_dir, f) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
510 cexecuted = self.restore_file(full_path) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
511 self.merge_data(cexecuted) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
512 |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
513 def merge_data(self, new_data): |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
514 for file_name, file_data in new_data.items(): |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5760
diff
changeset
|
515 if file_name in self.cexecuted: |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
516 self.merge_file_data(self.cexecuted[file_name], file_data) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
517 else: |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
518 self.cexecuted[file_name] = file_data |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
519 |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
520 def merge_file_data(self, cache_data, new_data): |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
521 for line_number in new_data.keys(): |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5760
diff
changeset
|
522 if not line_number in cache_data: |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
523 cache_data[line_number] = new_data[line_number] |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
524 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
525 # canonical_filename(filename). Return a canonical filename for the |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
526 # file (that is, an absolute path with no redundant components and |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
527 # normalized case). See [GDR 2001-12-04b, 3.3]. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
528 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
529 def canonical_filename(self, filename): |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5760
diff
changeset
|
530 if not filename in self.canonical_filename_cache: |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
531 f = filename |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
532 if os.path.isabs(f) and not os.path.exists(f): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
533 f = os.path.basename(f) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
534 if not os.path.isabs(f): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
535 for path in [os.curdir] + sys.path: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
536 g = os.path.join(path, f) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
537 if os.path.exists(g): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
538 f = g |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
539 break |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
540 cf = os.path.normcase(os.path.abspath(f)) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
541 self.canonical_filename_cache[filename] = cf |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
542 return self.canonical_filename_cache[filename] |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
543 |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
544 # canonicalize_filenames(). Copy results from "c" to "cexecuted", |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
545 # canonicalizing filenames on the way. Clear the "c" map. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
546 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
547 def canonicalize_filenames(self): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
548 for filename, lineno in self.c.keys(): |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
549 if filename == '<string>': |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
550 # Can't do anything useful with exec'd strings, so skip them. |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
551 continue |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
552 f = self.canonical_filename(filename) |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5760
diff
changeset
|
553 if not f in self.cexecuted: |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
554 self.cexecuted[f] = {} |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
555 self.cexecuted[f][lineno] = 1 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
556 self.c = {} |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
557 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
558 # morf_filename(morf). Return the filename for a module or file. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
559 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
560 def morf_filename(self, morf): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
561 if isinstance(morf, types.ModuleType): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
562 if not hasattr(morf, '__file__'): |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
563 raise CoverageException, "Module has no __file__ attribute." |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
564 f = morf.__file__ |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
565 else: |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
566 f = morf |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
567 return self.canonical_filename(f) |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
568 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
569 # analyze_morf(morf). Analyze the module or filename passed as |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
570 # the argument. If the source code can't be found, raise an error. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
571 # Otherwise, return a tuple of (1) the canonical filename of the |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
572 # source code for the module, (2) a list of lines of statements |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
573 # in the source code, (3) a list of lines of excluded statements, |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
574 # and (4), a map of line numbers to multi-line line number ranges, for |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
575 # statements that cross lines. |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
576 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
577 def analyze_morf(self, morf): |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5760
diff
changeset
|
578 if morf in self.analysis_cache: |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
579 return self.analysis_cache[morf] |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
580 filename = self.morf_filename(morf) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
581 ext = os.path.splitext(filename)[1] |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
582 if ext == '.pyc': |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
583 if not os.path.exists(filename[0:-1]): |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
584 raise CoverageException, ("No source for compiled code '%s'." |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
585 % filename) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
586 filename = filename[0:-1] |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
587 elif ext != '.py': |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
588 raise CoverageException, "File '%s' not Python source." % filename |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
589 source = open(filename, 'r') |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
590 lines, excluded_lines, line_map = self.find_executable_statements( |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
591 source.read(), exclude=self.exclude_re |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
592 ) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
593 source.close() |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
594 result = filename, lines, excluded_lines, line_map |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
595 self.analysis_cache[morf] = result |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
596 return result |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
597 |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
598 def first_line_of_tree(self, tree): |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
599 while True: |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
600 if len(tree) == 3 and type(tree[2]) == type(1): |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
601 return tree[2] |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
602 tree = tree[1] |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
603 |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
604 def last_line_of_tree(self, tree): |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
605 while True: |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
606 if len(tree) == 3 and type(tree[2]) == type(1): |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
607 return tree[2] |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
608 tree = tree[-1] |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
609 |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
610 def find_docstring_pass_pair(self, tree, spots): |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
611 for i in range(1, len(tree)): |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
612 if self.is_string_constant(tree[i]) and self.is_pass_stmt(tree[i+1]): |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
613 first_line = self.first_line_of_tree(tree[i]) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
614 last_line = self.last_line_of_tree(tree[i+1]) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
615 self.record_multiline(spots, first_line, last_line) |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
616 |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
617 def is_string_constant(self, tree): |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
618 try: |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
619 return tree[0] == symbol.stmt and tree[1][1][1][0] == symbol.expr_stmt |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
620 except: |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
621 return False |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
622 |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
623 def is_pass_stmt(self, tree): |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
624 try: |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
625 return tree[0] == symbol.stmt and tree[1][1][1][0] == symbol.pass_stmt |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
626 except: |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
627 return False |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
628 |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
629 def record_multiline(self, spots, i, j): |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
630 for l in range(i, j+1): |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
631 spots[l] = (i, j) |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
632 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
633 def get_suite_spots(self, tree, spots): |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
634 """ Analyze a parse tree to find suite introducers which span a number |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
635 of lines. |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
636 """ |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
637 for i in range(1, len(tree)): |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
638 if type(tree[i]) == type(()): |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
639 if tree[i][0] == symbol.suite: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
640 # Found a suite, look back for the colon and keyword. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
641 lineno_colon = lineno_word = None |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
642 for j in range(i-1, 0, -1): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
643 if tree[j][0] == token.COLON: |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
644 # Colons are never executed themselves: we want the |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
645 # line number of the last token before the colon. |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
646 lineno_colon = self.last_line_of_tree(tree[j-1]) |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
647 elif tree[j][0] == token.NAME: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
648 if tree[j][1] == 'elif': |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
649 # Find the line number of the first non-terminal |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
650 # after the keyword. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
651 t = tree[j+1] |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
652 while t and token.ISNONTERMINAL(t[0]): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
653 t = t[1] |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
654 if t: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
655 lineno_word = t[2] |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
656 else: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
657 lineno_word = tree[j][2] |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
658 break |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
659 elif tree[j][0] == symbol.except_clause: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
660 # "except" clauses look like: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
661 # ('except_clause', ('NAME', 'except', lineno), ...) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
662 if tree[j][1][0] == token.NAME: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
663 lineno_word = tree[j][1][2] |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
664 break |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
665 if lineno_colon and lineno_word: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
666 # Found colon and keyword, mark all the lines |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
667 # between the two with the two line numbers. |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
668 self.record_multiline(spots, lineno_word, lineno_colon) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
669 |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
670 # "pass" statements are tricky: different versions of Python |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
671 # treat them differently, especially in the common case of a |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
672 # function with a doc string and a single pass statement. |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
673 self.find_docstring_pass_pair(tree[i], spots) |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
674 |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
675 elif tree[i][0] == symbol.simple_stmt: |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
676 first_line = self.first_line_of_tree(tree[i]) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
677 last_line = self.last_line_of_tree(tree[i]) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
678 if first_line != last_line: |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
679 self.record_multiline(spots, first_line, last_line) |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
680 self.get_suite_spots(tree[i], spots) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
681 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
682 def find_executable_statements(self, text, exclude=None): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
683 # Find lines which match an exclusion pattern. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
684 excluded = {} |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
685 suite_spots = {} |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
686 if exclude: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
687 reExclude = re.compile(exclude) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
688 lines = text.split('\n') |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
689 for i in range(len(lines)): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
690 if reExclude.search(lines[i]): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
691 excluded[i+1] = 1 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
692 |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
693 # Parse the code and analyze the parse tree to find out which statements |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
694 # are multiline, and where suites begin and end. |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
695 import parser |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
696 tree = parser.suite(text+'\n\n').totuple(1) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
697 self.get_suite_spots(tree, suite_spots) |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
698 #print "Suite spots:", suite_spots |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
699 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
700 # Use the compiler module to parse the text and find the executable |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
701 # statements. We add newlines to be impervious to final partial lines. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
702 statements = {} |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
703 ast = compiler.parse(text+'\n\n') |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
704 visitor = StatementFindingAstVisitor(statements, excluded, suite_spots) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
705 compiler.walk(ast, visitor, walker=visitor) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
706 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
707 lines = statements.keys() |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
708 lines.sort() |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
709 excluded_lines = excluded.keys() |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
710 excluded_lines.sort() |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
711 return lines, excluded_lines, suite_spots |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
712 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
713 # format_lines(statements, lines). Format a list of line numbers |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
714 # for printing by coalescing groups of lines as long as the lines |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
715 # represent consecutive statements. This will coalesce even if |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
716 # there are gaps between statements, so if statements = |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
717 # [1,2,3,4,5,10,11,12,13,14] and lines = [1,2,5,10,11,13,14] then |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
718 # format_lines will return "1-2, 5-11, 13-14". |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
719 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
720 def format_lines(self, statements, lines): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
721 pairs = [] |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
722 i = 0 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
723 j = 0 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
724 start = None |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
725 pairs = [] |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
726 while i < len(statements) and j < len(lines): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
727 if statements[i] == lines[j]: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
728 if start == None: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
729 start = lines[j] |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
730 end = lines[j] |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
731 j = j + 1 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
732 elif start: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
733 pairs.append((start, end)) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
734 start = None |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
735 i = i + 1 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
736 if start: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
737 pairs.append((start, end)) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
738 def stringify(pair): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
739 start, end = pair |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
740 if start == end: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
741 return "%d" % start |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
742 else: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
743 return "%d-%d" % (start, end) |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
744 ret = string.join(map(stringify, pairs), ", ") |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
745 return ret |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
746 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
747 # Backward compatibility with version 1. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
748 def analysis(self, morf): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
749 f, s, _, m, mf = self.analysis2(morf) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
750 return f, s, m, mf |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
751 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
752 def analysis2(self, morf): |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
753 filename, statements, excluded, line_map = self.analyze_morf(morf) |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
754 self.canonicalize_filenames() |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5760
diff
changeset
|
755 if not filename in self.cexecuted: |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
756 self.cexecuted[filename] = {} |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
757 missing = [] |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
758 for line in statements: |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
759 lines = line_map.get(line, [line, line]) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
760 for l in range(lines[0], lines[1]+1): |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5760
diff
changeset
|
761 if l in self.cexecuted[filename]: |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
762 break |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
763 else: |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
764 missing.append(line) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
765 return (filename, statements, excluded, missing, |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
766 self.format_lines(statements, missing)) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
767 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
768 def relative_filename(self, filename): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
769 """ Convert filename to relative filename from self.relative_dir. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
770 """ |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
771 return filename.replace(self.relative_dir, "") |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
772 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
773 def morf_name(self, morf): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
774 """ Return the name of morf as used in report. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
775 """ |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
776 if isinstance(morf, types.ModuleType): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
777 return morf.__name__ |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
778 else: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
779 return self.relative_filename(os.path.splitext(morf)[0]) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
780 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
781 def filter_by_prefix(self, morfs, omit_prefixes): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
782 """ Return list of morfs where the morf name does not begin |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
783 with any one of the omit_prefixes. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
784 """ |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
785 filtered_morfs = [] |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
786 for morf in morfs: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
787 for prefix in omit_prefixes: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
788 if self.morf_name(morf).startswith(prefix): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
789 break |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
790 else: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
791 filtered_morfs.append(morf) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
792 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
793 return filtered_morfs |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
794 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
795 def morf_name_compare(self, x, y): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
796 return cmp(self.morf_name(x), self.morf_name(y)) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
797 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
798 def report(self, morfs, show_missing=1, ignore_errors=0, file=None, omit_prefixes=[]): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
799 if not isinstance(morfs, types.ListType): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
800 morfs = [morfs] |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
801 # On windows, the shell doesn't expand wildcards. Do it here. |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
802 globbed = [] |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
803 for morf in morfs: |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
804 if isinstance(morf, strclass): |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
805 globbed.extend(glob.glob(morf)) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
806 else: |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
807 globbed.append(morf) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
808 morfs = globbed |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
809 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
810 morfs = self.filter_by_prefix(morfs, omit_prefixes) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
811 morfs.sort(self.morf_name_compare) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
812 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
813 max_name = max([5,] + map(len, map(self.morf_name, morfs))) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
814 fmt_name = "%%- %ds " % max_name |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
815 fmt_err = fmt_name + "%s: %s" |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
816 header = fmt_name % "Name" + " Stmts Exec Cover" |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
817 fmt_coverage = fmt_name + "% 6d % 6d % 5d%%" |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
818 if show_missing: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
819 header = header + " Missing" |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
820 fmt_coverage = fmt_coverage + " %s" |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
821 if not file: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
822 file = sys.stdout |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
823 print >>file, header |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
824 print >>file, "-" * len(header) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
825 total_statements = 0 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
826 total_executed = 0 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
827 for morf in morfs: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
828 name = self.morf_name(morf) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
829 try: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
830 _, statements, _, missing, readable = self.analysis2(morf) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
831 n = len(statements) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
832 m = n - len(missing) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
833 if n > 0: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
834 pc = 100.0 * m / n |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
835 else: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
836 pc = 100.0 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
837 args = (name, n, m, pc) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
838 if show_missing: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
839 args = args + (readable,) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
840 print >>file, fmt_coverage % args |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
841 total_statements = total_statements + n |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
842 total_executed = total_executed + m |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
843 except KeyboardInterrupt: #pragma: no cover |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
844 raise |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
845 except: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
846 if not ignore_errors: |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
847 typ, msg = sys.exc_info()[0:2] |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
848 print >>file, fmt_err % (name, typ, msg) |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
849 if len(morfs) > 1: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
850 print >>file, "-" * len(header) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
851 if total_statements > 0: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
852 pc = 100.0 * total_executed / total_statements |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
853 else: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
854 pc = 100.0 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
855 args = ("TOTAL", total_statements, total_executed, pc) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
856 if show_missing: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
857 args = args + ("",) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
858 print >>file, fmt_coverage % args |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
859 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
860 # annotate(morfs, ignore_errors). |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
861 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
862 blank_re = re.compile(r"\s*(#|$)") |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
863 else_re = re.compile(r"\s*else\s*:\s*(#|$)") |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
864 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
865 def annotate(self, morfs, directory=None, ignore_errors=0, omit_prefixes=[]): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
866 morfs = self.filter_by_prefix(morfs, omit_prefixes) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
867 for morf in morfs: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
868 try: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
869 filename, statements, excluded, missing, _ = self.analysis2(morf) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
870 self.annotate_file(filename, statements, excluded, missing, directory) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
871 except KeyboardInterrupt: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
872 raise |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
873 except: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
874 if not ignore_errors: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
875 raise |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
876 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
877 def annotate_file(self, filename, statements, excluded, missing, directory=None): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
878 source = open(filename, 'r') |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
879 if directory: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
880 dest_file = os.path.join(directory, |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
881 os.path.basename(filename) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
882 + ',cover') |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
883 else: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
884 dest_file = filename + ',cover' |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
885 dest = open(dest_file, 'w') |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
886 lineno = 0 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
887 i = 0 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
888 j = 0 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
889 covered = 1 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
890 while 1: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
891 line = source.readline() |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
892 if line == '': |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
893 break |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
894 lineno = lineno + 1 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
895 while i < len(statements) and statements[i] < lineno: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
896 i = i + 1 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
897 while j < len(missing) and missing[j] < lineno: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
898 j = j + 1 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
899 if i < len(statements) and statements[i] == lineno: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
900 covered = j >= len(missing) or missing[j] > lineno |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
901 if self.blank_re.match(line): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
902 dest.write(' ') |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
903 elif self.else_re.match(line): |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
904 # Special logic for lines containing only 'else:'. |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
905 # See [GDR 2001-12-04b, 3.2]. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
906 if i >= len(statements) and j >= len(missing): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
907 dest.write('! ') |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
908 elif i >= len(statements) or j >= len(missing): |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
909 dest.write('> ') |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
910 elif statements[i] == missing[j]: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
911 dest.write('! ') |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
912 else: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
913 dest.write('> ') |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
914 elif lineno in excluded: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
915 dest.write('- ') |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
916 elif covered: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
917 dest.write('> ') |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
918 else: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
919 dest.write('! ') |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
920 dest.write(line) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
921 source.close() |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
922 dest.close() |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
923 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
924 # Singleton object. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
925 the_coverage = coverage() |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
926 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
927 # Module functions call methods in the singleton object. |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
928 def use_cache(*args, **kw): |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
929 return the_coverage.use_cache(*args, **kw) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
930 |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
931 def start(*args, **kw): |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
932 return the_coverage.start(*args, **kw) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
933 |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
934 def stop(*args, **kw): |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
935 return the_coverage.stop(*args, **kw) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
936 |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
937 def erase(*args, **kw): |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
938 return the_coverage.erase(*args, **kw) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
939 |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
940 def begin_recursive(*args, **kw): |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
941 return the_coverage.begin_recursive(*args, **kw) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
942 |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
943 def end_recursive(*args, **kw): |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
944 return the_coverage.end_recursive(*args, **kw) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
945 |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
946 def exclude(*args, **kw): |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
947 return the_coverage.exclude(*args, **kw) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
948 |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
949 def analysis(*args, **kw): |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
950 return the_coverage.analysis(*args, **kw) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
951 |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
952 def analysis2(*args, **kw): |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
953 return the_coverage.analysis2(*args, **kw) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
954 |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
955 def report(*args, **kw): |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
956 return the_coverage.report(*args, **kw) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
957 |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
958 def annotate(*args, **kw): |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
959 return the_coverage.annotate(*args, **kw) |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
960 |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
961 def annotate_file(*args, **kw): |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
962 return the_coverage.annotate_file(*args, **kw) |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
963 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
964 # Save coverage data when Python exits. (The atexit module wasn't |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
965 # introduced until Python 2.0, so use sys.exitfunc when it's not |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
966 # available.) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
967 try: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
968 import atexit |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
969 atexit.register(the_coverage.save) |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
970 except ImportError: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
971 sys.exitfunc = the_coverage.save |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
972 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
973 # Command-line interface. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
974 if __name__ == '__main__': |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
975 the_coverage.command_line(sys.argv[1:]) |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
976 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
977 |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
978 # A. REFERENCES |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
979 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
980 # [GDR 2001-12-04a] "Statement coverage for Python"; Gareth Rees; |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
981 # Ravenbrook Limited; 2001-12-04; |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
982 # <http://www.nedbatchelder.com/code/modules/rees-coverage.html>. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
983 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
984 # [GDR 2001-12-04b] "Statement coverage for Python: design and |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
985 # analysis"; Gareth Rees; Ravenbrook Limited; 2001-12-04; |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
986 # <http://www.nedbatchelder.com/code/modules/rees-design.html>. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
987 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
988 # [van Rossum 2001-07-20a] "Python Reference Manual (releae 2.1.1)"; |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
989 # Guide van Rossum; 2001-07-20; |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
990 # <http://www.python.org/doc/2.1.1/ref/ref.html>. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
991 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
992 # [van Rossum 2001-07-20b] "Python Library Reference"; Guido van Rossum; |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
993 # 2001-07-20; <http://www.python.org/doc/2.1.1/lib/lib.html>. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
994 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
995 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
996 # B. DOCUMENT HISTORY |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
997 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
998 # 2001-12-04 GDR Created. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
999 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1000 # 2001-12-06 GDR Added command-line interface and source code |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1001 # annotation. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1002 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1003 # 2001-12-09 GDR Moved design and interface to separate documents. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1004 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1005 # 2001-12-10 GDR Open cache file as binary on Windows. Allow |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1006 # simultaneous -e and -x, or -a and -r. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1007 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1008 # 2001-12-12 GDR Added command-line help. Cache analysis so that it |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1009 # only needs to be done once when you specify -a and -r. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1010 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1011 # 2001-12-13 GDR Improved speed while recording. Portable between |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1012 # Python 1.5.2 and 2.1.1. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1013 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1014 # 2002-01-03 GDR Module-level functions work correctly. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1015 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1016 # 2002-01-07 GDR Update sys.path when running a file with the -x option, |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1017 # so that it matches the value the program would get if it were run on |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1018 # its own. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1019 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1020 # 2004-12-12 NMB Significant code changes. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1021 # - Finding executable statements has been rewritten so that docstrings and |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1022 # other quirks of Python execution aren't mistakenly identified as missing |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1023 # lines. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1024 # - Lines can be excluded from consideration, even entire suites of lines. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1025 # - The filesystem cache of covered lines can be disabled programmatically. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1026 # - Modernized the code. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1027 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1028 # 2004-12-14 NMB Minor tweaks. Return 'analysis' to its original behavior |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1029 # and add 'analysis2'. Add a global for 'annotate', and factor it, adding |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1030 # 'annotate_file'. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1031 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1032 # 2004-12-31 NMB Allow for keyword arguments in the module global functions. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1033 # Thanks, Allen. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1034 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1035 # 2005-12-02 NMB Call threading.settrace so that all threads are measured. |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5594
diff
changeset
|
1036 # Thanks Martin Fuzzey. Add a file argument to report so that reports can be |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1037 # captured to a different destination. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1038 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1039 # 2005-12-03 NMB coverage.py can now measure itself. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1040 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1041 # 2005-12-04 NMB Adapted Greg Rogers' patch for using relative filenames, |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1042 # and sorting and omitting files to report on. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1043 # |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1044 # 2006-07-23 NMB Applied Joseph Tate's patch for function decorators. |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1045 # |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1046 # 2006-08-21 NMB Applied Sigve Tjora and Mark van der Wal's fixes for argument |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1047 # handling. |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1048 # |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1049 # 2006-08-22 NMB Applied Geoff Bache's parallel mode patch. |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1050 # |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1051 # 2006-08-23 NMB Refactorings to improve testability. Fixes to command-line |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1052 # logic for parallel mode and collect. |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1053 # |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1054 # 2006-08-25 NMB "#pragma: nocover" is excluded by default. |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1055 # |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1056 # 2006-09-10 NMB Properly ignore docstrings and other constant expressions that |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1057 # appear in the middle of a function, a problem reported by Tim Leslie. |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1058 # Minor changes to avoid lint warnings. |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1059 # |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1060 # 2006-09-17 NMB coverage.erase() shouldn't clobber the exclude regex. |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1061 # Change how parallel mode is invoked, and fix erase() so that it erases the |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1062 # cache when called programmatically. |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1063 # |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1064 # 2007-07-21 NMB In reports, ignore code executed from strings, since we can't |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1065 # do anything useful with it anyway. |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1066 # Better file handling on Linux, thanks Guillaume Chazarain. |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1067 # Better shell support on Windows, thanks Noel O'Boyle. |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1068 # Python 2.2 support maintained, thanks Catherine Proulx. |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1069 # |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1070 # 2007-07-22 NMB Python 2.5 now fully supported. The method of dealing with |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1071 # multi-line statements is now less sensitive to the exact line that Python |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1072 # reports during execution. Pass statements are handled specially so that their |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1073 # disappearance during execution won't throw off the measurement. |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1074 # |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1075 # 2007-07-23 NMB Now Python 2.5 is *really* fully supported: the body of the |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1076 # new with statement is counted as executable. |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1077 # |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1078 # 2007-07-29 NMB Better packaging. |
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1079 |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1080 # C. COPYRIGHT AND LICENCE |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1081 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1082 # Copyright 2001 Gareth Rees. All rights reserved. |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1083 # Copyright 2004-2007 Ned Batchelder. All rights reserved. |
2066
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1084 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1085 # Redistribution and use in source and binary forms, with or without |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1086 # modification, are permitted provided that the following conditions are |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1087 # met: |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1088 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1089 # 1. Redistributions of source code must retain the above copyright |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1090 # notice, this list of conditions and the following disclaimer. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1091 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1092 # 2. Redistributions in binary form must reproduce the above copyright |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1093 # notice, this list of conditions and the following disclaimer in the |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1094 # documentation and/or other materials provided with the |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1095 # distribution. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1096 # |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1097 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1098 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1099 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1100 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1101 # HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1102 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1103 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1104 # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1105 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1106 # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1107 # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1108 # DAMAGE. |
a5d072f38a4a
add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1109 # |
5592
7a4d846b178f
import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
4874
diff
changeset
|
1110 # $Id: coverage.py 74 2007-07-29 22:28:35Z nedbat $ |