DebugClients/Python/coverage/__init__.py

changeset 0
de9c2efb9d02
child 31
744cd0b4b8cd
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
1 """Code coverage measurement for Python.
2
3 Ned Batchelder
4 http://nedbatchelder.com/code/coverage
5
6 """
7
8 __version__ = "3.0.1" # see detailed history in CHANGES.txt
9
10 from control import coverage
11 from data import CoverageData
12 from cmdline import main, CoverageScript
13 from misc import CoverageException
14
15
16 # Module-level functions. The original API to this module was based on
17 # functions defined directly in the module, with a singleton of the coverage()
18 # class. That design hampered programmability. Here we define the top-level
19 # functions to create the singleton when they are first called.
20
21 # Singleton object for use with module-level functions. The singleton is
22 # created as needed when one of the module-level functions is called.
23 _the_coverage = None
24
25 def _singleton_method(name):
26 """Return a function to the `name` method on a singleton `coverage` object.
27
28 The singleton object is created the first time one of these functions is
29 called.
30
31 """
32 def wrapper(*args, **kwargs):
33 """Singleton wrapper around a coverage method."""
34 global _the_coverage
35 if not _the_coverage:
36 _the_coverage = coverage(auto_data=True)
37 return getattr(_the_coverage, name)(*args, **kwargs)
38 return wrapper
39
40
41 # Define the module-level functions.
42 use_cache = _singleton_method('use_cache')
43 start = _singleton_method('start')
44 stop = _singleton_method('stop')
45 erase = _singleton_method('erase')
46 exclude = _singleton_method('exclude')
47 analysis = _singleton_method('analysis')
48 analysis2 = _singleton_method('analysis2')
49 report = _singleton_method('report')
50 annotate = _singleton_method('annotate')
51
52
53 # COPYRIGHT AND LICENSE
54 #
55 # Copyright 2001 Gareth Rees. All rights reserved.
56 # Copyright 2004-2009 Ned Batchelder. All rights reserved.
57 #
58 # Redistribution and use in source and binary forms, with or without
59 # modification, are permitted provided that the following conditions are
60 # met:
61 #
62 # 1. Redistributions of source code must retain the above copyright
63 # notice, this list of conditions and the following disclaimer.
64 #
65 # 2. Redistributions in binary form must reproduce the above copyright
66 # notice, this list of conditions and the following disclaimer in the
67 # documentation and/or other materials provided with the
68 # distribution.
69 #
70 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
71 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
72 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
73 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
74 # HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
75 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
76 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
77 # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
78 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
79 # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
80 # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
81 # DAMAGE.

eric ide

mercurial