3 Ned Batchelder |
3 Ned Batchelder |
4 http://nedbatchelder.com/code/coverage |
4 http://nedbatchelder.com/code/coverage |
5 |
5 |
6 """ |
6 """ |
7 |
7 |
8 __version__ = "3.2" # see detailed history in CHANGES.txt |
8 from .version import __version__, __url__ |
9 |
9 |
10 __url__ = "http://nedbatchelder.com/code/coverage" |
10 from .control import coverage, process_startup |
11 |
|
12 from .control import coverage |
|
13 from .data import CoverageData |
11 from .data import CoverageData |
14 from .cmdline import main, CoverageScript |
12 from .cmdline import main, CoverageScript |
15 from .misc import CoverageException |
13 from .misc import CoverageException |
16 |
14 |
17 |
|
18 # Module-level functions. The original API to this module was based on |
15 # Module-level functions. The original API to this module was based on |
19 # functions defined directly in the module, with a singleton of the coverage() |
16 # functions defined directly in the module, with a singleton of the coverage() |
20 # class. That design hampered programmability. Here we define the top-level |
17 # class. That design hampered programmability, so the current api uses |
21 # functions to create the singleton when they are first called. |
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. |
22 |
21 |
23 # Singleton object for use with module-level functions. The singleton is |
22 # Singleton object for use with module-level functions. The singleton is |
24 # created as needed when one of the module-level functions is called. |
23 # created as needed when one of the module-level functions is called. |
25 _the_coverage = None |
24 _the_coverage = None |
26 |
25 |
29 |
28 |
30 The singleton object is created the first time one of these functions is |
29 The singleton object is created the first time one of these functions is |
31 called. |
30 called. |
32 |
31 |
33 """ |
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 |
34 def wrapper(*args, **kwargs): |
37 def wrapper(*args, **kwargs): |
35 """Singleton wrapper around a coverage method.""" |
38 """Singleton wrapper around a coverage method.""" |
36 global _the_coverage |
39 global _the_coverage |
37 if not _the_coverage: |
40 if not _the_coverage: |
38 _the_coverage = coverage(auto_data=True) |
41 _the_coverage = coverage(auto_data=True) |
39 return getattr(_the_coverage, name)(*args, **kwargs) |
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 |
40 return wrapper |
61 return wrapper |
41 |
62 |
42 |
63 |
43 # Define the module-level functions. |
64 # Define the module-level functions. |
44 use_cache = _singleton_method('use_cache') |
65 use_cache = _singleton_method('use_cache') |
50 analysis2 = _singleton_method('analysis2') |
71 analysis2 = _singleton_method('analysis2') |
51 report = _singleton_method('report') |
72 report = _singleton_method('report') |
52 annotate = _singleton_method('annotate') |
73 annotate = _singleton_method('annotate') |
53 |
74 |
54 |
75 |
|
76 # 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. |
|
78 # Adding a reference here prevents it from being unloaded. Yuk. |
|
79 import encodings.utf_8 |
|
80 |
|
81 # Because of the "from .control import fooey" lines at the top of the |
|
82 # 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 |
|
84 # coverage.coverage. So remove that entry. |
|
85 import sys |
|
86 try: |
|
87 del sys.modules['coverage.coverage'] |
|
88 except KeyError: |
|
89 pass |
|
90 |
|
91 |
55 # COPYRIGHT AND LICENSE |
92 # COPYRIGHT AND LICENSE |
56 # |
93 # |
57 # Copyright 2001 Gareth Rees. All rights reserved. |
94 # Copyright 2001 Gareth Rees. All rights reserved. |
58 # Copyright 2004-2009 Ned Batchelder. All rights reserved. |
95 # Copyright 2004-2013 Ned Batchelder. All rights reserved. |
59 # |
96 # |
60 # Redistribution and use in source and binary forms, with or without |
97 # Redistribution and use in source and binary forms, with or without |
61 # modification, are permitted provided that the following conditions are |
98 # modification, are permitted provided that the following conditions are |
62 # met: |
99 # met: |
63 # |
100 # |
79 # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
116 # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
80 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
117 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
81 # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
118 # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
82 # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
119 # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
83 # DAMAGE. |
120 # DAMAGE. |
84 |
|
85 # |
|
86 # eflag: FileType = Python2 |
|