DebugClients/Python/coverage/__init__.py

changeset 4491
0d8612e24fef
parent 4489
d0d6e4ad31bd
child 5051
3586ebd9fac8
equal deleted inserted replaced
4487:4ba7a8ab24f2 4491:0d8612e24fef
1 # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
2 # For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
3
1 """Code coverage measurement for Python. 4 """Code coverage measurement for Python.
2 5
3 Ned Batchelder 6 Ned Batchelder
4 http://nedbatchelder.com/code/coverage 7 http://nedbatchelder.com/code/coverage
5 8
6 """ 9 """
7 10
8 from .version import __version__, __url__ 11 from coverage.version import __version__, __url__, version_info
9 12
10 from .control import coverage, process_startup 13 from coverage.control import Coverage, process_startup
11 from .data import CoverageData 14 from coverage.data import CoverageData
12 from .cmdline import main, CoverageScript 15 from coverage.misc import CoverageException
13 from .misc import CoverageException 16 from coverage.plugin import CoveragePlugin, FileTracer, FileReporter
14 17
15 # Module-level functions. The original API to this module was based on 18 # Backward compatibility.
16 # functions defined directly in the module, with a singleton of the coverage() 19 coverage = Coverage
17 # class. That design hampered programmability, so the current api uses
18 # explicitly-created coverage objects. But for backward compatibility, here we
19 # define the top-level functions to create the singleton when they are first
20 # called.
21
22 # Singleton object for use with module-level functions. The singleton is
23 # created as needed when one of the module-level functions is called.
24 _the_coverage = None
25
26 def _singleton_method(name):
27 """Return a function to the `name` method on a singleton `coverage` object.
28
29 The singleton object is created the first time one of these functions is
30 called.
31
32 """
33 # Disable pylint msg W0612, because a bunch of variables look unused, but
34 # they're accessed via locals().
35 # pylint: disable=W0612
36
37 def wrapper(*args, **kwargs):
38 """Singleton wrapper around a coverage method."""
39 global _the_coverage
40 if not _the_coverage:
41 _the_coverage = coverage(auto_data=True)
42 return getattr(_the_coverage, name)(*args, **kwargs)
43
44 import inspect
45 meth = getattr(coverage, name)
46 args, varargs, kw, defaults = inspect.getargspec(meth)
47 argspec = inspect.formatargspec(args[1:], varargs, kw, defaults)
48 docstring = meth.__doc__
49 wrapper.__doc__ = ("""\
50 A first-use-singleton wrapper around coverage.%(name)s.
51
52 This wrapper is provided for backward compatibility with legacy code.
53 New code should use coverage.%(name)s directly.
54
55 %(name)s%(argspec)s:
56
57 %(docstring)s
58 """ % locals()
59 )
60
61 return wrapper
62
63
64 # Define the module-level functions.
65 use_cache = _singleton_method('use_cache')
66 start = _singleton_method('start')
67 stop = _singleton_method('stop')
68 erase = _singleton_method('erase')
69 exclude = _singleton_method('exclude')
70 analysis = _singleton_method('analysis')
71 analysis2 = _singleton_method('analysis2')
72 report = _singleton_method('report')
73 annotate = _singleton_method('annotate')
74
75 20
76 # On Windows, we encode and decode deep enough that something goes wrong and 21 # On Windows, we encode and decode deep enough that something goes wrong and
77 # the encodings.utf_8 module is loaded and then unloaded, I don't know why. 22 # the encodings.utf_8 module is loaded and then unloaded, I don't know why.
78 # Adding a reference here prevents it from being unloaded. Yuk. 23 # Adding a reference here prevents it from being unloaded. Yuk.
79 import encodings.utf_8 24 import encodings.utf_8
80 25
81 # Because of the "from .control import fooey" lines at the top of the 26 # Because of the "from coverage.control import fooey" lines at the top of the
82 # file, there's an entry for coverage.coverage in sys.modules, mapped to None. 27 # file, there's an entry for coverage.coverage in sys.modules, mapped to None.
83 # This makes some inspection tools (like pydoc) unable to find the class 28 # This makes some inspection tools (like pydoc) unable to find the class
84 # coverage.coverage. So remove that entry. 29 # coverage.coverage. So remove that entry.
85 import sys 30 import sys
86 try: 31 try:
87 del sys.modules['coverage.coverage'] 32 del sys.modules['coverage.coverage']
88 except KeyError: 33 except KeyError:
89 pass 34 pass
90 35
91
92 # COPYRIGHT AND LICENSE
93 #
94 # Copyright 2001 Gareth Rees. All rights reserved.
95 # Copyright 2004-2013 Ned Batchelder. All rights reserved.
96 #
97 # Redistribution and use in source and binary forms, with or without
98 # modification, are permitted provided that the following conditions are
99 # met:
100 #
101 # 1. Redistributions of source code must retain the above copyright
102 # notice, this list of conditions and the following disclaimer.
103 #
104 # 2. Redistributions in binary form must reproduce the above copyright
105 # notice, this list of conditions and the following disclaimer in the
106 # documentation and/or other materials provided with the
107 # distribution.
108 #
109 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
110 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
111 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
112 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
113 # HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
114 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
115 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
116 # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
117 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
118 # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
119 # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
120 # DAMAGE.
121
122 # 36 #
123 # eflag: FileType = Python2 37 # eflag: FileType = Python2

eric ide

mercurial