Fri, 02 Sep 2016 19:08:02 +0200
Fixed two little issues related to wrong parameter types.
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
1 | # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
2 | # For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
3 | |
3495 | 4 | """Config file for coverage.py""" |
5 | ||
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
6 | import collections |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
7 | import os |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
8 | import re |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
9 | import sys |
3495 | 10 | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
11 | from coverage.backward import configparser, iitems, string_class |
5051
3586ebd9fac8
Updated coverage.py to version 4.1.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4491
diff
changeset
|
12 | from coverage.misc import CoverageException, isolate_module |
3586ebd9fac8
Updated coverage.py to version 4.1.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4491
diff
changeset
|
13 | |
3586ebd9fac8
Updated coverage.py to version 4.1.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4491
diff
changeset
|
14 | os = isolate_module(os) |
3495 | 15 | |
16 | ||
17 | class HandyConfigParser(configparser.RawConfigParser): | |
18 | """Our specialization of ConfigParser.""" | |
19 | ||
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
20 | def __init__(self, section_prefix): |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
21 | configparser.RawConfigParser.__init__(self) |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
22 | self.section_prefix = section_prefix |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
23 | |
3495 | 24 | def read(self, filename): |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
25 | """Read a file name as UTF-8 configuration data.""" |
3495 | 26 | kwargs = {} |
27 | if sys.version_info >= (3, 2): | |
28 | kwargs['encoding'] = "utf-8" | |
29 | return configparser.RawConfigParser.read(self, filename, **kwargs) | |
30 | ||
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
31 | def has_option(self, section, option): |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
32 | section = self.section_prefix + section |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
33 | return configparser.RawConfigParser.has_option(self, section, option) |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
34 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
35 | def has_section(self, section): |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
36 | section = self.section_prefix + section |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
37 | return configparser.RawConfigParser.has_section(self, section) |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
38 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
39 | def options(self, section): |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
40 | section = self.section_prefix + section |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
41 | return configparser.RawConfigParser.options(self, section) |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
42 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
43 | def get_section(self, section): |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
44 | """Get the contents of a section, as a dictionary.""" |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
45 | d = {} |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
46 | for opt in self.options(section): |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
47 | d[opt] = self.get(section, opt) |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
48 | return d |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
49 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
50 | def get(self, section, *args, **kwargs): |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
51 | """Get a value, replacing environment variables also. |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
52 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
53 | The arguments are the same as `RawConfigParser.get`, but in the found |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
54 | value, ``$WORD`` or ``${WORD}`` are replaced by the value of the |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
55 | environment variable ``WORD``. |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
56 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
57 | Returns the finished value. |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
58 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
59 | """ |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
60 | section = self.section_prefix + section |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
61 | v = configparser.RawConfigParser.get(self, section, *args, **kwargs) |
3495 | 62 | def dollar_replace(m): |
63 | """Called for each $replacement.""" | |
64 | # Only one of the groups will have matched, just get its text. | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
65 | word = next(w for w in m.groups() if w is not None) # pragma: part covered |
3495 | 66 | if word == "$": |
67 | return "$" | |
68 | else: | |
69 | return os.environ.get(word, '') | |
70 | ||
71 | dollar_pattern = r"""(?x) # Use extended regex syntax | |
72 | \$(?: # A dollar sign, then | |
73 | (?P<v1>\w+) | # a plain word, | |
74 | {(?P<v2>\w+)} | # or a {-wrapped word, | |
75 | (?P<char>[$]) # or a dollar sign. | |
76 | ) | |
77 | """ | |
78 | v = re.sub(dollar_pattern, dollar_replace, v) | |
79 | return v | |
80 | ||
81 | def getlist(self, section, option): | |
82 | """Read a list of strings. | |
83 | ||
84 | The value of `section` and `option` is treated as a comma- and newline- | |
85 | separated list of strings. Each value is stripped of whitespace. | |
86 | ||
87 | Returns the list of strings. | |
88 | ||
89 | """ | |
90 | value_list = self.get(section, option) | |
91 | values = [] | |
92 | for value_line in value_list.split('\n'): | |
93 | for value in value_line.split(','): | |
94 | value = value.strip() | |
95 | if value: | |
96 | values.append(value) | |
97 | return values | |
98 | ||
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
99 | def getregexlist(self, section, option): |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
100 | """Read a list of full-line regexes. |
3495 | 101 | |
102 | The value of `section` and `option` is treated as a newline-separated | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
103 | list of regexes. Each value is stripped of whitespace. |
3495 | 104 | |
105 | Returns the list of strings. | |
106 | ||
107 | """ | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
108 | line_list = self.get(section, option) |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
109 | value_list = [] |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
110 | for value in line_list.splitlines(): |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
111 | value = value.strip() |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
112 | try: |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
113 | re.compile(value) |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
114 | except re.error as e: |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
115 | raise CoverageException( |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
116 | "Invalid [%s].%s value %r: %s" % (section, option, value, e) |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
117 | ) |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
118 | if value: |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
119 | value_list.append(value) |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
120 | return value_list |
3495 | 121 | |
122 | ||
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
123 | # The default line exclusion regexes. |
3495 | 124 | DEFAULT_EXCLUDE = [ |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
125 | r'(?i)#\s*pragma[:\s]?\s*no\s*cover', |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
126 | ] |
3495 | 127 | |
128 | # The default partial branch regexes, to be modified by the user. | |
129 | DEFAULT_PARTIAL = [ | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
130 | r'(?i)#\s*pragma[:\s]?\s*no\s*branch', |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
131 | ] |
3495 | 132 | |
133 | # The default partial branch regexes, based on Python semantics. | |
134 | # These are any Python branching constructs that can't actually execute all | |
135 | # their branches. | |
136 | DEFAULT_PARTIAL_ALWAYS = [ | |
137 | 'while (True|1|False|0):', | |
138 | 'if (True|1|False|0):', | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
139 | ] |
3495 | 140 | |
141 | ||
142 | class CoverageConfig(object): | |
143 | """Coverage.py configuration. | |
144 | ||
145 | The attributes of this class are the various settings that control the | |
146 | operation of coverage.py. | |
147 | ||
148 | """ | |
149 | def __init__(self): | |
150 | """Initialize the configuration attributes to their defaults.""" | |
151 | # Metadata about the config. | |
152 | self.attempted_config_files = [] | |
153 | self.config_files = [] | |
154 | ||
155 | # Defaults for [run] | |
156 | self.branch = False | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
157 | self.concurrency = None |
3495 | 158 | self.cover_pylib = False |
159 | self.data_file = ".coverage" | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
160 | self.debug = [] |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
161 | self.note = None |
3495 | 162 | self.parallel = False |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
163 | self.plugins = [] |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
164 | self.source = None |
3495 | 165 | self.timid = False |
166 | ||
167 | # Defaults for [report] | |
168 | self.exclude_list = DEFAULT_EXCLUDE[:] | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
169 | self.fail_under = 0 |
3495 | 170 | self.ignore_errors = False |
171 | self.include = None | |
172 | self.omit = None | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
173 | self.partial_always_list = DEFAULT_PARTIAL_ALWAYS[:] |
3495 | 174 | self.partial_list = DEFAULT_PARTIAL[:] |
175 | self.precision = 0 | |
176 | self.show_missing = False | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
177 | self.skip_covered = False |
3495 | 178 | |
179 | # Defaults for [html] | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
180 | self.extra_css = None |
3495 | 181 | self.html_dir = "htmlcov" |
182 | self.html_title = "Coverage report" | |
183 | ||
184 | # Defaults for [xml] | |
185 | self.xml_output = "coverage.xml" | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
186 | self.xml_package_depth = 99 |
3495 | 187 | |
188 | # Defaults for [paths] | |
189 | self.paths = {} | |
190 | ||
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
191 | # Options for plugins |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
192 | self.plugin_options = {} |
3495 | 193 | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
194 | MUST_BE_LIST = ["omit", "include", "debug", "plugins"] |
3495 | 195 | |
196 | def from_args(self, **kwargs): | |
197 | """Read config values from `kwargs`.""" | |
198 | for k, v in iitems(kwargs): | |
199 | if v is not None: | |
200 | if k in self.MUST_BE_LIST and isinstance(v, string_class): | |
201 | v = [v] | |
202 | setattr(self, k, v) | |
203 | ||
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
204 | def from_file(self, filename, section_prefix=""): |
3495 | 205 | """Read configuration from a .rc file. |
206 | ||
207 | `filename` is a file name to read. | |
208 | ||
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
209 | Returns True or False, whether the file could be read. |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
210 | |
3495 | 211 | """ |
212 | self.attempted_config_files.append(filename) | |
213 | ||
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
214 | cp = HandyConfigParser(section_prefix) |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
215 | try: |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
216 | files_read = cp.read(filename) |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
217 | except configparser.Error as err: |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
218 | raise CoverageException("Couldn't read config file %s: %s" % (filename, err)) |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
219 | if not files_read: |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
220 | return False |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
221 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
222 | self.config_files.extend(files_read) |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
223 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
224 | try: |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
225 | for option_spec in self.CONFIG_FILE_OPTIONS: |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
226 | self._set_attr_from_config_option(cp, *option_spec) |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
227 | except ValueError as err: |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
228 | raise CoverageException("Couldn't read config file %s: %s" % (filename, err)) |
3495 | 229 | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
230 | # Check that there are no unrecognized options. |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
231 | all_options = collections.defaultdict(set) |
3495 | 232 | for option_spec in self.CONFIG_FILE_OPTIONS: |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
233 | section, option = option_spec[1].split(":") |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
234 | all_options[section].add(option) |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
235 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
236 | for section, options in iitems(all_options): |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
237 | if cp.has_section(section): |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
238 | for unknown in set(cp.options(section)) - options: |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
239 | if section_prefix: |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
240 | section = section_prefix + section |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
241 | raise CoverageException( |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
242 | "Unrecognized option '[%s] %s=' in config file %s" % ( |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
243 | section, unknown, filename |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
244 | ) |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
245 | ) |
3495 | 246 | |
247 | # [paths] is special | |
248 | if cp.has_section('paths'): | |
249 | for option in cp.options('paths'): | |
250 | self.paths[option] = cp.getlist('paths', option) | |
251 | ||
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
252 | # plugins can have options |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
253 | for plugin in self.plugins: |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
254 | if cp.has_section(plugin): |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
255 | self.plugin_options[plugin] = cp.get_section(plugin) |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
256 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
257 | return True |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
258 | |
3495 | 259 | CONFIG_FILE_OPTIONS = [ |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
260 | # These are *args for _set_attr_from_config_option: |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
261 | # (attr, where, type_="") |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
262 | # |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
263 | # attr is the attribute to set on the CoverageConfig object. |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
264 | # where is the section:name to read from the configuration file. |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
265 | # type_ is the optional type to apply, by using .getTYPE to read the |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
266 | # configuration value from the file. |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
267 | |
3495 | 268 | # [run] |
269 | ('branch', 'run:branch', 'boolean'), | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
270 | ('concurrency', 'run:concurrency'), |
3495 | 271 | ('cover_pylib', 'run:cover_pylib', 'boolean'), |
272 | ('data_file', 'run:data_file'), | |
273 | ('debug', 'run:debug', 'list'), | |
274 | ('include', 'run:include', 'list'), | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
275 | ('note', 'run:note'), |
3495 | 276 | ('omit', 'run:omit', 'list'), |
277 | ('parallel', 'run:parallel', 'boolean'), | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
278 | ('plugins', 'run:plugins', 'list'), |
3495 | 279 | ('source', 'run:source', 'list'), |
280 | ('timid', 'run:timid', 'boolean'), | |
281 | ||
282 | # [report] | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
283 | ('exclude_list', 'report:exclude_lines', 'regexlist'), |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
284 | ('fail_under', 'report:fail_under', 'int'), |
3495 | 285 | ('ignore_errors', 'report:ignore_errors', 'boolean'), |
286 | ('include', 'report:include', 'list'), | |
287 | ('omit', 'report:omit', 'list'), | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
288 | ('partial_always_list', 'report:partial_branches_always', 'regexlist'), |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
289 | ('partial_list', 'report:partial_branches', 'regexlist'), |
3495 | 290 | ('precision', 'report:precision', 'int'), |
291 | ('show_missing', 'report:show_missing', 'boolean'), | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
292 | ('skip_covered', 'report:skip_covered', 'boolean'), |
3495 | 293 | |
294 | # [html] | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
295 | ('extra_css', 'html:extra_css'), |
3495 | 296 | ('html_dir', 'html:directory'), |
297 | ('html_title', 'html:title'), | |
298 | ||
299 | # [xml] | |
300 | ('xml_output', 'xml:output'), | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
301 | ('xml_package_depth', 'xml:package_depth', 'int'), |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
302 | ] |
3495 | 303 | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
304 | def _set_attr_from_config_option(self, cp, attr, where, type_=''): |
3495 | 305 | """Set an attribute on self if it exists in the ConfigParser.""" |
306 | section, option = where.split(":") | |
307 | if cp.has_option(section, option): | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
308 | method = getattr(cp, 'get' + type_) |
3495 | 309 | setattr(self, attr, method(section, option)) |
3499
f2d4b02c7e88
Modified the Python2 coverage files to include the Python2 eflags line and fixed an issue in both variants.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3495
diff
changeset
|
310 | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
311 | def get_plugin_options(self, plugin): |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
312 | """Get a dictionary of options for the plugin named `plugin`.""" |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
313 | return self.plugin_options.get(plugin, {}) |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
314 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
315 | def set_option(self, option_name, value): |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
316 | """Set an option in the configuration. |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
317 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
318 | `option_name` is a colon-separated string indicating the section and |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
319 | option name. For example, the ``branch`` option in the ``[run]`` |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
320 | section of the config file would be indicated with `"run:branch"`. |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
321 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
322 | `value` is the new value for the option. |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
323 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
324 | """ |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
325 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
326 | # Check all the hard-coded options. |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
327 | for option_spec in self.CONFIG_FILE_OPTIONS: |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
328 | attr, where = option_spec[:2] |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
329 | if where == option_name: |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
330 | setattr(self, attr, value) |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
331 | return |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
332 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
333 | # See if it's a plugin option. |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
334 | plugin_name, _, key = option_name.partition(":") |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
335 | if key and plugin_name in self.plugins: |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
336 | self.plugin_options.setdefault(plugin_name, {})[key] = value |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
337 | return |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
338 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
339 | # If we get here, we didn't find the option. |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
340 | raise CoverageException("No such option: %r" % option_name) |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
341 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
342 | def get_option(self, option_name): |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
343 | """Get an option from the configuration. |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
344 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
345 | `option_name` is a colon-separated string indicating the section and |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
346 | option name. For example, the ``branch`` option in the ``[run]`` |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
347 | section of the config file would be indicated with `"run:branch"`. |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
348 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
349 | Returns the value of the option. |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
350 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
351 | """ |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
352 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
353 | # Check all the hard-coded options. |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
354 | for option_spec in self.CONFIG_FILE_OPTIONS: |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
355 | attr, where = option_spec[:2] |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
356 | if where == option_name: |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
357 | return getattr(self, attr) |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
358 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
359 | # See if it's a plugin option. |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
360 | plugin_name, _, key = option_name.partition(":") |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
361 | if key and plugin_name in self.plugins: |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
362 | return self.plugin_options.get(plugin_name, {}).get(key) |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
363 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
364 | # If we get here, we didn't find the option. |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
365 | raise CoverageException("No such option: %r" % option_name) |
4491
0d8612e24fef
Merged with coverage.py update.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4489
diff
changeset
|
366 | |
0d8612e24fef
Merged with coverage.py update.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4489
diff
changeset
|
367 | # |
0d8612e24fef
Merged with coverage.py update.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
4489
diff
changeset
|
368 | # eflag: FileType = Python2 |