Sun, 04 Oct 2015 22:37:56 +0200
Updated coverage to 4.0 (breaks with Python 3.2 support).
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 |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
12 | from coverage.misc import CoverageException |
3495 | 13 | |
14 | ||
15 | class HandyConfigParser(configparser.RawConfigParser): | |
16 | """Our specialization of ConfigParser.""" | |
17 | ||
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
18 | 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
|
19 | 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
|
20 | 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
|
21 | |
3495 | 22 | 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
|
23 | """Read a file name as UTF-8 configuration data.""" |
3495 | 24 | kwargs = {} |
25 | if sys.version_info >= (3, 2): | |
26 | kwargs['encoding'] = "utf-8" | |
27 | return configparser.RawConfigParser.read(self, filename, **kwargs) | |
28 | ||
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
29 | 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
|
30 | 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
|
31 | 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
|
32 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
33 | 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
|
34 | 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
|
35 | 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
|
36 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
37 | 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
|
38 | 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
|
39 | 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
|
40 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
41 | 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
|
42 | """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
|
43 | d = {} |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
44 | 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
|
45 | 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
|
46 | return d |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
47 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
48 | 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
|
49 | """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
|
50 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
51 | 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
|
52 | 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
|
53 | 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
|
54 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
55 | 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
|
56 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
57 | """ |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
58 | 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
|
59 | v = configparser.RawConfigParser.get(self, section, *args, **kwargs) |
3495 | 60 | def dollar_replace(m): |
61 | """Called for each $replacement.""" | |
62 | # 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
|
63 | word = next(w for w in m.groups() if w is not None) # pragma: part covered |
3495 | 64 | if word == "$": |
65 | return "$" | |
66 | else: | |
67 | return os.environ.get(word, '') | |
68 | ||
69 | dollar_pattern = r"""(?x) # Use extended regex syntax | |
70 | \$(?: # A dollar sign, then | |
71 | (?P<v1>\w+) | # a plain word, | |
72 | {(?P<v2>\w+)} | # or a {-wrapped word, | |
73 | (?P<char>[$]) # or a dollar sign. | |
74 | ) | |
75 | """ | |
76 | v = re.sub(dollar_pattern, dollar_replace, v) | |
77 | return v | |
78 | ||
79 | def getlist(self, section, option): | |
80 | """Read a list of strings. | |
81 | ||
82 | The value of `section` and `option` is treated as a comma- and newline- | |
83 | separated list of strings. Each value is stripped of whitespace. | |
84 | ||
85 | Returns the list of strings. | |
86 | ||
87 | """ | |
88 | value_list = self.get(section, option) | |
89 | values = [] | |
90 | for value_line in value_list.split('\n'): | |
91 | for value in value_line.split(','): | |
92 | value = value.strip() | |
93 | if value: | |
94 | values.append(value) | |
95 | return values | |
96 | ||
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
97 | 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
|
98 | """Read a list of full-line regexes. |
3495 | 99 | |
100 | 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
|
101 | list of regexes. Each value is stripped of whitespace. |
3495 | 102 | |
103 | Returns the list of strings. | |
104 | ||
105 | """ | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
106 | 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
|
107 | value_list = [] |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
108 | 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
|
109 | 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
|
110 | try: |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
111 | 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
|
112 | 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
|
113 | raise CoverageException( |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
114 | "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
|
115 | ) |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
116 | if value: |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
117 | 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
|
118 | return value_list |
3495 | 119 | |
120 | ||
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
121 | # The default line exclusion regexes. |
3495 | 122 | 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
|
123 | 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
|
124 | ] |
3495 | 125 | |
126 | # The default partial branch regexes, to be modified by the user. | |
127 | 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
|
128 | 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
|
129 | ] |
3495 | 130 | |
131 | # The default partial branch regexes, based on Python semantics. | |
132 | # These are any Python branching constructs that can't actually execute all | |
133 | # their branches. | |
134 | DEFAULT_PARTIAL_ALWAYS = [ | |
135 | 'while (True|1|False|0):', | |
136 | '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
|
137 | ] |
3495 | 138 | |
139 | ||
140 | class CoverageConfig(object): | |
141 | """Coverage.py configuration. | |
142 | ||
143 | The attributes of this class are the various settings that control the | |
144 | operation of coverage.py. | |
145 | ||
146 | """ | |
147 | def __init__(self): | |
148 | """Initialize the configuration attributes to their defaults.""" | |
149 | # Metadata about the config. | |
150 | self.attempted_config_files = [] | |
151 | self.config_files = [] | |
152 | ||
153 | # Defaults for [run] | |
154 | 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
|
155 | self.concurrency = None |
3495 | 156 | self.cover_pylib = False |
157 | 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
|
158 | self.debug = [] |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
159 | self.note = None |
3495 | 160 | 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
|
161 | self.plugins = [] |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
162 | self.source = None |
3495 | 163 | self.timid = False |
164 | ||
165 | # Defaults for [report] | |
166 | 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
|
167 | self.fail_under = 0 |
3495 | 168 | self.ignore_errors = False |
169 | self.include = None | |
170 | 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
|
171 | self.partial_always_list = DEFAULT_PARTIAL_ALWAYS[:] |
3495 | 172 | self.partial_list = DEFAULT_PARTIAL[:] |
173 | self.precision = 0 | |
174 | 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
|
175 | self.skip_covered = False |
3495 | 176 | |
177 | # 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
|
178 | self.extra_css = None |
3495 | 179 | self.html_dir = "htmlcov" |
180 | self.html_title = "Coverage report" | |
181 | ||
182 | # Defaults for [xml] | |
183 | 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
|
184 | self.xml_package_depth = 99 |
3495 | 185 | |
186 | # Defaults for [paths] | |
187 | self.paths = {} | |
188 | ||
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
189 | # 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
|
190 | self.plugin_options = {} |
3495 | 191 | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
192 | MUST_BE_LIST = ["omit", "include", "debug", "plugins"] |
3495 | 193 | |
194 | def from_args(self, **kwargs): | |
195 | """Read config values from `kwargs`.""" | |
196 | for k, v in iitems(kwargs): | |
197 | if v is not None: | |
198 | if k in self.MUST_BE_LIST and isinstance(v, string_class): | |
199 | v = [v] | |
200 | setattr(self, k, v) | |
201 | ||
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
202 | def from_file(self, filename, section_prefix=""): |
3495 | 203 | """Read configuration from a .rc file. |
204 | ||
205 | `filename` is a file name to read. | |
206 | ||
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
207 | 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
|
208 | |
3495 | 209 | """ |
210 | self.attempted_config_files.append(filename) | |
211 | ||
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
212 | 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
|
213 | try: |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
214 | 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
|
215 | 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
|
216 | 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
|
217 | 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
|
218 | return False |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
219 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
220 | 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
|
221 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
222 | try: |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
223 | 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
|
224 | 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
|
225 | 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
|
226 | raise CoverageException("Couldn't read config file %s: %s" % (filename, err)) |
3495 | 227 | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
228 | # 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
|
229 | all_options = collections.defaultdict(set) |
3495 | 230 | 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
|
231 | 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
|
232 | 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
|
233 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
234 | 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
|
235 | 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
|
236 | 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
|
237 | 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
|
238 | 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
|
239 | raise CoverageException( |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
240 | "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
|
241 | 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
|
242 | ) |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
243 | ) |
3495 | 244 | |
245 | # [paths] is special | |
246 | if cp.has_section('paths'): | |
247 | for option in cp.options('paths'): | |
248 | self.paths[option] = cp.getlist('paths', option) | |
249 | ||
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
250 | # 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
|
251 | 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
|
252 | 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
|
253 | 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
|
254 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
255 | return True |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
256 | |
3495 | 257 | 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
|
258 | # 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
|
259 | # (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
|
260 | # |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
261 | # 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
|
262 | # 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
|
263 | # 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
|
264 | # 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
|
265 | |
3495 | 266 | # [run] |
267 | ('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
|
268 | ('concurrency', 'run:concurrency'), |
3495 | 269 | ('cover_pylib', 'run:cover_pylib', 'boolean'), |
270 | ('data_file', 'run:data_file'), | |
271 | ('debug', 'run:debug', 'list'), | |
272 | ('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
|
273 | ('note', 'run:note'), |
3495 | 274 | ('omit', 'run:omit', 'list'), |
275 | ('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
|
276 | ('plugins', 'run:plugins', 'list'), |
3495 | 277 | ('source', 'run:source', 'list'), |
278 | ('timid', 'run:timid', 'boolean'), | |
279 | ||
280 | # [report] | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
281 | ('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
|
282 | ('fail_under', 'report:fail_under', 'int'), |
3495 | 283 | ('ignore_errors', 'report:ignore_errors', 'boolean'), |
284 | ('include', 'report:include', 'list'), | |
285 | ('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
|
286 | ('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
|
287 | ('partial_list', 'report:partial_branches', 'regexlist'), |
3495 | 288 | ('precision', 'report:precision', 'int'), |
289 | ('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
|
290 | ('skip_covered', 'report:skip_covered', 'boolean'), |
3495 | 291 | |
292 | # [html] | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
293 | ('extra_css', 'html:extra_css'), |
3495 | 294 | ('html_dir', 'html:directory'), |
295 | ('html_title', 'html:title'), | |
296 | ||
297 | # [xml] | |
298 | ('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
|
299 | ('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
|
300 | ] |
3495 | 301 | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
302 | def _set_attr_from_config_option(self, cp, attr, where, type_=''): |
3495 | 303 | """Set an attribute on self if it exists in the ConfigParser.""" |
304 | section, option = where.split(":") | |
305 | 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
|
306 | method = getattr(cp, 'get' + type_) |
3495 | 307 | 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
|
308 | |
4489
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
309 | 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
|
310 | """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
|
311 | 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
|
312 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
313 | 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
|
314 | """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
|
315 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
316 | `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
|
317 | 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
|
318 | 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
|
319 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
320 | `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
|
321 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
322 | """ |
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 | # 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
|
325 | 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
|
326 | 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
|
327 | 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
|
328 | 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
|
329 | return |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
330 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
331 | # 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
|
332 | 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
|
333 | 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
|
334 | 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
|
335 | return |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
336 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
337 | # 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
|
338 | 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
|
339 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
340 | 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
|
341 | """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
|
342 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
343 | `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
|
344 | 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
|
345 | 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
|
346 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
347 | 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
|
348 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
349 | """ |
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 | # 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
|
352 | 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
|
353 | 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
|
354 | 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
|
355 | 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
|
356 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
357 | # 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
|
358 | 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
|
359 | 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
|
360 | 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
|
361 | |
d0d6e4ad31bd
Updated coverage to 4.0 (breaks with Python 3.2 support).
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3499
diff
changeset
|
362 | # 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
|
363 | raise CoverageException("No such option: %r" % option_name) |