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