tests/coverage.py
author Matt Mackall <mpm@selenic.com>
Wed, 25 Jun 2008 17:34:28 -0500
changeset 6738 336fda65759a
parent 6349 6aaf5b1d8f15
child 7047 277c91fe8384
permissions -rwxr-xr-x
use repo.changectx rather than context.changectx
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
6349
6aaf5b1d8f15 coverage: deal with symlinked input paths (MacOSX issue)
Patrick Mezard <pmezard@gmail.com>
parents: 6047
diff changeset
   415
        omit = [os.path.normcase(os.path.abspath(os.path.realpath(p)))
6aaf5b1d8f15 coverage: deal with symlinked input paths (MacOSX issue)
Patrick Mezard <pmezard@gmail.com>
parents: 6047
diff changeset
   416
                for p in omit]
6aaf5b1d8f15 coverage: deal with symlinked input paths (MacOSX issue)
Patrick Mezard <pmezard@gmail.com>
parents: 6047
diff changeset
   417
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   418
        if settings.get('report'):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   419
            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
   420
        if settings.get('annotate'):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   421
            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
   422
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   423
    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
   424
        self.usecache = usecache
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   425
        if cache_file and not self.cache:
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   426
            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
   427
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   428
    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
   429
        if self.usecache and not self.cache:
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   430
            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
   431
            if self.parallel_mode:
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   432
                self.cache += "." + gethostname() + "." + str(os.getpid())
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   433
            self.restore()
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   434
        self.analysis_cache = {}
5760
0145f9afb0e7 Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5594
diff changeset
   435
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   436
    def start(self, parallel_mode=False):
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   437
        self.get_ready()
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   438
        if self.nesting == 0:                               #pragma: no cover
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   439
            sys.settrace(self.t)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   440
            if hasattr(threading, 'settrace'):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   441
                threading.settrace(self.t)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   442
        self.nesting += 1
5760
0145f9afb0e7 Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5594
diff changeset
   443
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   444
    def stop(self):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   445
        self.nesting -= 1
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   446
        if self.nesting == 0:                               #pragma: no cover
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   447
            sys.settrace(None)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   448
            if hasattr(threading, 'settrace'):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   449
                threading.settrace(None)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   450
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   451
    def erase(self):
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   452
        self.get_ready()
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   453
        self.c = {}
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   454
        self.analysis_cache = {}
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   455
        self.cexecuted = {}
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   456
        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
   457
            os.remove(self.cache)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   458
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   459
    def exclude(self, re):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   460
        if self.exclude_re:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   461
            self.exclude_re += "|"
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   462
        self.exclude_re += "(" + re + ")"
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   463
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   464
    def begin_recursive(self):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   465
        self.cstack.append(self.c)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   466
        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
   467
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   468
    def end_recursive(self):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   469
        self.c = self.cstack.pop()
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   470
        self.exclude_re = self.xstack.pop()
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   471
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   472
    # 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
   473
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   474
    def save(self):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   475
        if self.usecache and self.cache:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   476
            self.canonicalize_filenames()
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   477
            cache = open(self.cache, 'wb')
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   478
            import marshal
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   479
            marshal.dump(self.cexecuted, cache)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   480
            cache.close()
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   481
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   482
    # 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
   483
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   484
    def restore(self):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   485
        self.c = {}
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   486
        self.cexecuted = {}
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   487
        assert self.usecache
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   488
        if os.path.exists(self.cache):
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   489
            self.cexecuted = self.restore_file(self.cache)
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   490
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   491
    def restore_file(self, file_name):
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   492
        try:
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   493
            cache = open(file_name, 'rb')
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   494
            import marshal
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   495
            cexecuted = marshal.load(cache)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   496
            cache.close()
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   497
            if isinstance(cexecuted, types.DictType):
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   498
                return cexecuted
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   499
            else:
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   500
                return {}
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   501
        except:
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   502
            return {}
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   503
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   504
    # 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
   505
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   506
    def collect(self):
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   507
        cache_dir, local = os.path.split(self.cache)
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   508
        for f in os.listdir(cache_dir or '.'):
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   509
            if not f.startswith(local):
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   510
                continue
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   511
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   512
            full_path = os.path.join(cache_dir, f)
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   513
            cexecuted = self.restore_file(full_path)
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   514
            self.merge_data(cexecuted)
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   515
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   516
    def merge_data(self, new_data):
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   517
        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
   518
            if file_name in self.cexecuted:
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   519
                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
   520
            else:
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   521
                self.cexecuted[file_name] = file_data
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   522
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   523
    def merge_file_data(self, cache_data, new_data):
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   524
        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
   525
            if not line_number in cache_data:
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   526
                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
   527
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   528
    # 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
   529
    # 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
   530
    # 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
   531
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   532
    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
   533
        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
   534
            f = filename
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   535
            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
   536
                f = os.path.basename(f)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   537
            if not os.path.isabs(f):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   538
                for path in [os.curdir] + sys.path:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   539
                    g = os.path.join(path, f)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   540
                    if os.path.exists(g):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   541
                        f = g
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   542
                        break
6349
6aaf5b1d8f15 coverage: deal with symlinked input paths (MacOSX issue)
Patrick Mezard <pmezard@gmail.com>
parents: 6047
diff changeset
   543
            cf = os.path.normcase(os.path.abspath(os.path.realpath(f)))
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   544
            self.canonical_filename_cache[filename] = cf
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   545
        return self.canonical_filename_cache[filename]
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   546
5760
0145f9afb0e7 Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5594
diff changeset
   547
    # 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
   548
    # 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
   549
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   550
    def canonicalize_filenames(self):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   551
        for filename, lineno in self.c.keys():
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   552
            if filename == '<string>':
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   553
                # 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
   554
                continue
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   555
            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
   556
            if not f in self.cexecuted:
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   557
                self.cexecuted[f] = {}
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   558
            self.cexecuted[f][lineno] = 1
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   559
        self.c = {}
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   560
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   561
    # 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
   562
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   563
    def morf_filename(self, morf):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   564
        if isinstance(morf, types.ModuleType):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   565
            if not hasattr(morf, '__file__'):
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   566
                raise CoverageException, "Module has no __file__ attribute."
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   567
            f = morf.__file__
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   568
        else:
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   569
            f = morf
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   570
        return self.canonical_filename(f)
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   571
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   572
    # 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
   573
    # 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
   574
    # 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
   575
    # 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
   576
    # 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
   577
    # 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
   578
    # statements that cross lines.
5760
0145f9afb0e7 Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5594
diff changeset
   579
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   580
    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
   581
        if morf in self.analysis_cache:
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   582
            return self.analysis_cache[morf]
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   583
        filename = self.morf_filename(morf)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   584
        ext = os.path.splitext(filename)[1]
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   585
        if ext == '.pyc':
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   586
            if not os.path.exists(filename[0:-1]):
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   587
                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
   588
                                   % filename)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   589
            filename = filename[0:-1]
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   590
        elif ext != '.py':
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   591
            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
   592
        source = open(filename, 'r')
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   593
        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
   594
            source.read(), exclude=self.exclude_re
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   595
            )
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   596
        source.close()
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   597
        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
   598
        self.analysis_cache[morf] = result
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   599
        return result
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   600
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   601
    def first_line_of_tree(self, tree):
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   602
        while True:
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   603
            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
   604
                return tree[2]
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   605
            tree = tree[1]
5760
0145f9afb0e7 Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5594
diff changeset
   606
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   607
    def last_line_of_tree(self, tree):
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   608
        while True:
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   609
            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
   610
                return tree[2]
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   611
            tree = tree[-1]
5760
0145f9afb0e7 Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5594
diff changeset
   612
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   613
    def find_docstring_pass_pair(self, tree, spots):
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   614
        for i in range(1, len(tree)):
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   615
            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
   616
                first_line = self.first_line_of_tree(tree[i])
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   617
                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
   618
                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
   619
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   620
    def is_string_constant(self, tree):
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   621
        try:
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   622
            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
   623
        except:
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   624
            return False
5760
0145f9afb0e7 Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5594
diff changeset
   625
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   626
    def is_pass_stmt(self, tree):
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   627
        try:
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   628
            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
   629
        except:
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   630
            return False
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   631
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   632
    def record_multiline(self, spots, i, j):
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   633
        for l in range(i, j+1):
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   634
            spots[l] = (i, j)
5760
0145f9afb0e7 Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5594
diff changeset
   635
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   636
    def get_suite_spots(self, tree, spots):
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   637
        """ 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
   638
            of lines.
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   639
        """
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   640
        for i in range(1, len(tree)):
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   641
            if type(tree[i]) == type(()):
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   642
                if tree[i][0] == symbol.suite:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   643
                    # 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
   644
                    lineno_colon = lineno_word = None
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   645
                    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
   646
                        if tree[j][0] == token.COLON:
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   647
                            # Colons are never executed themselves: we want the
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   648
                            # line number of the last token before the colon.
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   649
                            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
   650
                        elif tree[j][0] == token.NAME:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   651
                            if tree[j][1] == 'elif':
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   652
                                # 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
   653
                                # after the keyword.
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   654
                                t = tree[j+1]
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   655
                                while t and token.ISNONTERMINAL(t[0]):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   656
                                    t = t[1]
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   657
                                if t:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   658
                                    lineno_word = t[2]
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   659
                            else:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   660
                                lineno_word = tree[j][2]
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   661
                            break
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   662
                        elif tree[j][0] == symbol.except_clause:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   663
                            # "except" clauses look like:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   664
                            # ('except_clause', ('NAME', 'except', lineno), ...)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   665
                            if tree[j][1][0] == token.NAME:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   666
                                lineno_word = tree[j][1][2]
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   667
                                break
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   668
                    if lineno_colon and lineno_word:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   669
                        # 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
   670
                        # between the two with the two line numbers.
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   671
                        self.record_multiline(spots, lineno_word, lineno_colon)
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   672
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   673
                    # "pass" statements are tricky: different versions of Python
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   674
                    # 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
   675
                    # 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
   676
                    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
   677
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   678
                elif tree[i][0] == symbol.simple_stmt:
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   679
                    first_line = self.first_line_of_tree(tree[i])
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   680
                    last_line = self.last_line_of_tree(tree[i])
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   681
                    if first_line != last_line:
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   682
                        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
   683
                self.get_suite_spots(tree[i], spots)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   684
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   685
    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
   686
        # Find lines which match an exclusion pattern.
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   687
        excluded = {}
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   688
        suite_spots = {}
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   689
        if exclude:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   690
            reExclude = re.compile(exclude)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   691
            lines = text.split('\n')
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   692
            for i in range(len(lines)):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   693
                if reExclude.search(lines[i]):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   694
                    excluded[i+1] = 1
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   695
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   696
        # 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
   697
        # 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
   698
        import parser
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   699
        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
   700
        self.get_suite_spots(tree, suite_spots)
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   701
        #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
   702
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   703
        # 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
   704
        # 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
   705
        statements = {}
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   706
        ast = compiler.parse(text+'\n\n')
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   707
        visitor = StatementFindingAstVisitor(statements, excluded, suite_spots)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   708
        compiler.walk(ast, visitor, walker=visitor)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   709
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   710
        lines = statements.keys()
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   711
        lines.sort()
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   712
        excluded_lines = excluded.keys()
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   713
        excluded_lines.sort()
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   714
        return lines, excluded_lines, suite_spots
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   715
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   716
    # 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
   717
    # 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
   718
    # 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
   719
    # 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
   720
    # [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
   721
    # 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
   722
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   723
    def format_lines(self, statements, lines):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   724
        pairs = []
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   725
        i = 0
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   726
        j = 0
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   727
        start = None
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   728
        pairs = []
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   729
        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
   730
            if statements[i] == lines[j]:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   731
                if start == None:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   732
                    start = lines[j]
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   733
                end = lines[j]
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   734
                j = j + 1
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   735
            elif start:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   736
                pairs.append((start, end))
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   737
                start = None
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   738
            i = i + 1
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   739
        if start:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   740
            pairs.append((start, end))
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   741
        def stringify(pair):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   742
            start, end = pair
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   743
            if start == end:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   744
                return "%d" % start
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   745
            else:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   746
                return "%d-%d" % (start, end)
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   747
        ret = string.join(map(stringify, pairs), ", ")
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   748
        return ret
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   749
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   750
    # Backward compatibility with version 1.
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   751
    def analysis(self, morf):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   752
        f, s, _, m, mf = self.analysis2(morf)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   753
        return f, s, m, mf
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   754
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   755
    def analysis2(self, morf):
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   756
        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
   757
        self.canonicalize_filenames()
5915
d0576d065993 Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents: 5760
diff changeset
   758
        if not filename in self.cexecuted:
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   759
            self.cexecuted[filename] = {}
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   760
        missing = []
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   761
        for line in statements:
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   762
            lines = line_map.get(line, [line, line])
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   763
            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
   764
                if l in self.cexecuted[filename]:
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   765
                    break
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   766
            else:
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   767
                missing.append(line)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   768
        return (filename, statements, excluded, missing,
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   769
                self.format_lines(statements, missing))
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
    def relative_filename(self, filename):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   772
        """ 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
   773
        """
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   774
        return filename.replace(self.relative_dir, "")
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
    def morf_name(self, morf):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   777
        """ 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
   778
        """
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   779
        if isinstance(morf, types.ModuleType):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   780
            return morf.__name__
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   781
        else:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   782
            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
   783
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   784
    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
   785
        """ 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
   786
            with any one of the omit_prefixes.
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   787
        """
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   788
        filtered_morfs = []
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   789
        for morf in morfs:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   790
            for prefix in omit_prefixes:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   791
                if self.morf_name(morf).startswith(prefix):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   792
                    break
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   793
            else:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   794
                filtered_morfs.append(morf)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   795
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   796
        return filtered_morfs
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 morf_name_compare(self, x, y):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   799
        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
   800
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   801
    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
   802
        if not isinstance(morfs, types.ListType):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   803
            morfs = [morfs]
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   804
        # 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
   805
        globbed = []
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   806
        for morf in morfs:
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   807
            if isinstance(morf, strclass):
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   808
                globbed.extend(glob.glob(morf))
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   809
            else:
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   810
                globbed.append(morf)
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   811
        morfs = globbed
5760
0145f9afb0e7 Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5594
diff changeset
   812
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   813
        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
   814
        morfs.sort(self.morf_name_compare)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   815
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   816
        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
   817
        fmt_name = "%%- %ds  " % max_name
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   818
        fmt_err = fmt_name + "%s: %s"
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   819
        header = fmt_name % "Name" + " Stmts   Exec  Cover"
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   820
        fmt_coverage = fmt_name + "% 6d % 6d % 5d%%"
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   821
        if show_missing:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   822
            header = header + "   Missing"
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   823
            fmt_coverage = fmt_coverage + "   %s"
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   824
        if not file:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   825
            file = sys.stdout
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   826
        print >>file, header
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   827
        print >>file, "-" * len(header)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   828
        total_statements = 0
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   829
        total_executed = 0
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   830
        for morf in morfs:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   831
            name = self.morf_name(morf)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   832
            try:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   833
                _, statements, _, missing, readable  = self.analysis2(morf)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   834
                n = len(statements)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   835
                m = n - len(missing)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   836
                if n > 0:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   837
                    pc = 100.0 * m / n
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   838
                else:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   839
                    pc = 100.0
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   840
                args = (name, n, m, pc)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   841
                if show_missing:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   842
                    args = args + (readable,)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   843
                print >>file, fmt_coverage % args
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   844
                total_statements = total_statements + n
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   845
                total_executed = total_executed + m
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   846
            except KeyboardInterrupt:                       #pragma: no cover
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   847
                raise
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   848
            except:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   849
                if not ignore_errors:
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   850
                    typ, msg = sys.exc_info()[0:2]
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   851
                    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
   852
        if len(morfs) > 1:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   853
            print >>file, "-" * len(header)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   854
            if total_statements > 0:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   855
                pc = 100.0 * total_executed / total_statements
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   856
            else:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   857
                pc = 100.0
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   858
            args = ("TOTAL", total_statements, total_executed, pc)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   859
            if show_missing:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   860
                args = args + ("",)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   861
            print >>file, fmt_coverage % args
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   862
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   863
    # annotate(morfs, ignore_errors).
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
    blank_re = re.compile(r"\s*(#|$)")
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   866
    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
   867
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   868
    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
   869
        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
   870
        for morf in morfs:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   871
            try:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   872
                filename, statements, excluded, missing, _ = self.analysis2(morf)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   873
                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
   874
            except KeyboardInterrupt:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   875
                raise
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   876
            except:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   877
                if not ignore_errors:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   878
                    raise
5760
0145f9afb0e7 Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5594
diff changeset
   879
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   880
    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
   881
        source = open(filename, 'r')
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   882
        if directory:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   883
            dest_file = os.path.join(directory,
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   884
                                     os.path.basename(filename)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   885
                                     + ',cover')
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   886
        else:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   887
            dest_file = filename + ',cover'
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   888
        dest = open(dest_file, 'w')
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   889
        lineno = 0
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   890
        i = 0
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   891
        j = 0
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   892
        covered = 1
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   893
        while 1:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   894
            line = source.readline()
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   895
            if line == '':
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   896
                break
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   897
            lineno = lineno + 1
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   898
            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
   899
                i = i + 1
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   900
            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
   901
                j = j + 1
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   902
            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
   903
                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
   904
            if self.blank_re.match(line):
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   905
                dest.write('  ')
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   906
            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
   907
                # 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
   908
                # See [GDR 2001-12-04b, 3.2].
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   909
                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
   910
                    dest.write('! ')
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   911
                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
   912
                    dest.write('> ')
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   913
                elif statements[i] == missing[j]:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   914
                    dest.write('! ')
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   915
                else:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   916
                    dest.write('> ')
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   917
            elif lineno in excluded:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   918
                dest.write('- ')
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   919
            elif covered:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   920
                dest.write('> ')
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   921
            else:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   922
                dest.write('! ')
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   923
            dest.write(line)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   924
        source.close()
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   925
        dest.close()
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
# Singleton object.
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   928
the_coverage = coverage()
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   929
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   930
# 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
   931
def use_cache(*args, **kw):
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   932
    return the_coverage.use_cache(*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 start(*args, **kw):
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   935
    return the_coverage.start(*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 stop(*args, **kw):
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   938
    return the_coverage.stop(*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 erase(*args, **kw):
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   941
    return the_coverage.erase(*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 begin_recursive(*args, **kw):
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   944
    return the_coverage.begin_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 end_recursive(*args, **kw):
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   947
    return the_coverage.end_recursive(*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 exclude(*args, **kw):
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   950
    return the_coverage.exclude(*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 analysis(*args, **kw):
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   953
    return the_coverage.analysis(*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 analysis2(*args, **kw):
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   956
    return the_coverage.analysis2(*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 report(*args, **kw):
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   959
    return the_coverage.report(*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(*args, **kw):
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   962
    return the_coverage.annotate(*args, **kw)
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   963
5760
0145f9afb0e7 Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5594
diff changeset
   964
def annotate_file(*args, **kw):
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   965
    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
   966
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   967
# 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
   968
# 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
   969
# available.)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   970
try:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   971
    import atexit
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   972
    atexit.register(the_coverage.save)
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   973
except ImportError:
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   974
    sys.exitfunc = the_coverage.save
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   975
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   976
# Command-line interface.
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   977
if __name__ == '__main__':
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
   978
    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
   979
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   980
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   981
# A. REFERENCES
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   982
#
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   983
# [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
   984
# Ravenbrook Limited; 2001-12-04;
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   985
# <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
   986
#
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   987
# [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
   988
# 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
   989
# <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
   990
#
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   991
# [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
   992
# Guide van Rossum; 2001-07-20;
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   993
# <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
   994
#
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   995
# [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
   996
# 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
   997
#
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   998
#
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   999
# B. DOCUMENT HISTORY
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1000
#
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1001
# 2001-12-04 GDR Created.
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-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
  1004
# annotation.
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1005
#
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1006
# 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
  1007
#
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1008
# 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
  1009
# 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
  1010
#
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1011
# 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
  1012
# 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
  1013
#
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1014
# 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
  1015
# 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
  1016
#
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1017
# 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
  1018
#
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1019
# 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
  1020
# 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
  1021
# its own.
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1022
#
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1023
# 2004-12-12 NMB Significant code changes.
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1024
# - 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
  1025
#   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
  1026
#   lines.
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1027
# - 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
  1028
# - 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
  1029
# - Modernized the code.
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1030
#
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1031
# 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
  1032
# 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
  1033
# 'annotate_file'.
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
# 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
  1036
# Thanks, Allen.
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1037
#
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1038
# 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
  1039
# 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
  1040
# captured to a different destination.
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1041
#
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1042
# 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
  1043
#
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1044
# 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
  1045
# 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
  1046
#
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
  1047
# 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
  1048
#
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
  1049
# 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
  1050
# handling.
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
  1051
#
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
  1052
# 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
  1053
#
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
  1054
# 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
  1055
# logic for parallel mode and collect.
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
  1056
#
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
  1057
# 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
  1058
#
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
  1059
# 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
  1060
# 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
  1061
# Minor changes to avoid lint warnings.
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
  1062
#
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
  1063
# 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
  1064
# 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
  1065
# cache when called programmatically.
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
  1066
#
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
  1067
# 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
  1068
# do anything useful with it anyway.
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
  1069
# Better file handling on Linux, thanks Guillaume Chazarain.
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
  1070
# Better shell support on Windows, thanks Noel O'Boyle.
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
  1071
# Python 2.2 support maintained, thanks Catherine Proulx.
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
  1072
#
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
  1073
# 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
  1074
# 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
  1075
# 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
  1076
# disappearance during execution won't throw off the measurement.
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-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
  1079
# new with statement is counted as executable.
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
  1080
#
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
  1081
# 2007-07-29 NMB Better packaging.
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
  1082
2066
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1083
# C. COPYRIGHT AND LICENCE
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
# Copyright 2001 Gareth Rees.  All rights reserved.
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
  1086
# 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
  1087
#
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1088
# 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
  1089
# 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
  1090
# met:
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
# 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
  1093
#    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
  1094
#
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1095
# 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
  1096
#    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
  1097
#    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
  1098
#    distribution.
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1099
#
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1100
# 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
  1101
# "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
  1102
# 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
  1103
# 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
  1104
# 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
  1105
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1106
# 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
  1107
# 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
  1108
# 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
  1109
# 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
  1110
# 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
  1111
# DAMAGE.
a5d072f38a4a add coverage.py module to tests directory.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
  1112
#
5592
7a4d846b178f import latest coverage.py version
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 4874
diff changeset
  1113
# $Id: coverage.py 74 2007-07-29 22:28:35Z nedbat $