Merge lp:~jelmer/brz/move-errors-config into lp:brz
- move-errors-config
- Merge into trunk
Proposed by
Jelmer Vernooij
Status: | Merged |
---|---|
Merge reported by: | Jelmer Vernooij |
Merged at revision: | not available |
Proposed branch: | lp:~jelmer/brz/move-errors-config |
Merge into: | lp:brz |
Diff against target: |
586 lines (+134/-133) 3 files modified
breezy/config.py (+108/-20) breezy/errors.py (+0/-88) breezy/tests/test_config.py (+26/-25) |
To merge this branch: | bzr merge lp:~jelmer/brz/move-errors-config |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Martin Packman | Approve | ||
Review via email: mp+327488@code.launchpad.net |
Commit message
Move config-related errors from breezy.errors to breezy.config.
Description of the change
Move config-related errors from breezy.errors to breezy.config.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'breezy/config.py' | |||
2 | --- breezy/config.py 2017-07-04 20:03:11 +0000 | |||
3 | +++ breezy/config.py 2017-07-15 16:04:48 +0000 | |||
4 | @@ -92,7 +92,6 @@ | |||
5 | 92 | controldir, | 92 | controldir, |
6 | 93 | debug, | 93 | debug, |
7 | 94 | directory_service, | 94 | directory_service, |
8 | 95 | errors, | ||
9 | 96 | lazy_regex, | 95 | lazy_regex, |
10 | 97 | library_state, | 96 | library_state, |
11 | 98 | lockdir, | 97 | lockdir, |
12 | @@ -108,6 +107,7 @@ | |||
13 | 108 | """) | 107 | """) |
14 | 109 | from . import ( | 108 | from . import ( |
15 | 110 | commands, | 109 | commands, |
16 | 110 | errors, | ||
17 | 111 | hooks, | 111 | hooks, |
18 | 112 | lazy_regex, | 112 | lazy_regex, |
19 | 113 | registry, | 113 | registry, |
20 | @@ -155,6 +155,94 @@ | |||
21 | 155 | STORE_GLOBAL = 4 | 155 | STORE_GLOBAL = 4 |
22 | 156 | 156 | ||
23 | 157 | 157 | ||
24 | 158 | # FIXME: I would prefer to define the config related exception classes in | ||
25 | 159 | # config.py but the lazy import mechanism proscribes this -- vila 20101222 | ||
26 | 160 | class OptionExpansionLoop(errors.BzrError): | ||
27 | 161 | |||
28 | 162 | _fmt = 'Loop involving %(refs)r while expanding "%(string)s".' | ||
29 | 163 | |||
30 | 164 | def __init__(self, string, refs): | ||
31 | 165 | self.string = string | ||
32 | 166 | self.refs = '->'.join(refs) | ||
33 | 167 | |||
34 | 168 | |||
35 | 169 | class ExpandingUnknownOption(errors.BzrError): | ||
36 | 170 | |||
37 | 171 | _fmt = 'Option "%(name)s" is not defined while expanding "%(string)s".' | ||
38 | 172 | |||
39 | 173 | def __init__(self, name, string): | ||
40 | 174 | self.name = name | ||
41 | 175 | self.string = string | ||
42 | 176 | |||
43 | 177 | |||
44 | 178 | class IllegalOptionName(errors.BzrError): | ||
45 | 179 | |||
46 | 180 | _fmt = 'Option "%(name)s" is not allowed.' | ||
47 | 181 | |||
48 | 182 | def __init__(self, name): | ||
49 | 183 | self.name = name | ||
50 | 184 | |||
51 | 185 | |||
52 | 186 | class ConfigContentError(errors.BzrError): | ||
53 | 187 | |||
54 | 188 | _fmt = "Config file %(filename)s is not UTF-8 encoded\n" | ||
55 | 189 | |||
56 | 190 | def __init__(self, filename): | ||
57 | 191 | errors.BzrError.__init__(self) | ||
58 | 192 | self.filename = filename | ||
59 | 193 | |||
60 | 194 | |||
61 | 195 | class ParseConfigError(errors.BzrError): | ||
62 | 196 | |||
63 | 197 | _fmt = "Error(s) parsing config file %(filename)s:\n%(errors)s" | ||
64 | 198 | |||
65 | 199 | def __init__(self, errors, filename): | ||
66 | 200 | errors.BzrError.__init__(self) | ||
67 | 201 | self.filename = filename | ||
68 | 202 | self.errors = '\n'.join(e.msg for e in errors) | ||
69 | 203 | |||
70 | 204 | |||
71 | 205 | class ConfigOptionValueError(errors.BzrError): | ||
72 | 206 | |||
73 | 207 | _fmt = ('Bad value "%(value)s" for option "%(name)s".\n' | ||
74 | 208 | 'See ``brz help %(name)s``') | ||
75 | 209 | |||
76 | 210 | def __init__(self, name, value): | ||
77 | 211 | errors.BzrError.__init__(self, name=name, value=value) | ||
78 | 212 | |||
79 | 213 | |||
80 | 214 | class NoEmailInUsername(errors.BzrError): | ||
81 | 215 | |||
82 | 216 | _fmt = "%(username)r does not seem to contain a reasonable email address" | ||
83 | 217 | |||
84 | 218 | def __init__(self, username): | ||
85 | 219 | errors.BzrError.__init__(self) | ||
86 | 220 | self.username = username | ||
87 | 221 | |||
88 | 222 | |||
89 | 223 | class NoSuchConfig(errors.BzrError): | ||
90 | 224 | |||
91 | 225 | _fmt = ('The "%(config_id)s" configuration does not exist.') | ||
92 | 226 | |||
93 | 227 | def __init__(self, config_id): | ||
94 | 228 | errors.BzrError.__init__(self, config_id=config_id) | ||
95 | 229 | |||
96 | 230 | |||
97 | 231 | class NoSuchConfigOption(errors.BzrError): | ||
98 | 232 | |||
99 | 233 | _fmt = ('The "%(option_name)s" configuration option does not exist.') | ||
100 | 234 | |||
101 | 235 | def __init__(self, option_name): | ||
102 | 236 | errors.BzrError.__init__(self, option_name=option_name) | ||
103 | 237 | |||
104 | 238 | |||
105 | 239 | class NoWhoami(errors.BzrError): | ||
106 | 240 | |||
107 | 241 | _fmt = ('Unable to determine your name.\n' | ||
108 | 242 | "Please, set your name with the 'whoami' command.\n" | ||
109 | 243 | 'E.g. brz whoami "Your Name <name@example.com>"') | ||
110 | 244 | |||
111 | 245 | |||
112 | 158 | def signature_policy_from_unicode(signature_string): | 246 | def signature_policy_from_unicode(signature_string): |
113 | 159 | """Convert a string to a signing policy.""" | 247 | """Convert a string to a signing policy.""" |
114 | 160 | if signature_string.lower() == 'check-available': | 248 | if signature_string.lower() == 'check-available': |
115 | @@ -342,11 +430,11 @@ | |||
116 | 342 | else: | 430 | else: |
117 | 343 | name = chunk[1:-1] | 431 | name = chunk[1:-1] |
118 | 344 | if name in _ref_stack: | 432 | if name in _ref_stack: |
120 | 345 | raise errors.OptionExpansionLoop(string, _ref_stack) | 433 | raise OptionExpansionLoop(string, _ref_stack) |
121 | 346 | _ref_stack.append(name) | 434 | _ref_stack.append(name) |
122 | 347 | value = self._expand_option(name, env, _ref_stack) | 435 | value = self._expand_option(name, env, _ref_stack) |
123 | 348 | if value is None: | 436 | if value is None: |
125 | 349 | raise errors.ExpandingUnknownOption(name, string) | 437 | raise ExpandingUnknownOption(name, string) |
126 | 350 | if isinstance(value, list): | 438 | if isinstance(value, list): |
127 | 351 | list_value = True | 439 | list_value = True |
128 | 352 | chunks.extend(value) | 440 | chunks.extend(value) |
129 | @@ -666,9 +754,9 @@ | |||
130 | 666 | try: | 754 | try: |
131 | 667 | self._parser = ConfigObj(co_input, encoding='utf-8') | 755 | self._parser = ConfigObj(co_input, encoding='utf-8') |
132 | 668 | except configobj.ConfigObjError as e: | 756 | except configobj.ConfigObjError as e: |
134 | 669 | raise errors.ParseConfigError(e.errors, e.config.filename) | 757 | raise ParseConfigError(e.errors, e.config.filename) |
135 | 670 | except UnicodeDecodeError: | 758 | except UnicodeDecodeError: |
137 | 671 | raise errors.ConfigContentError(self.file_name) | 759 | raise ConfigContentError(self.file_name) |
138 | 672 | # Make sure self.reload() will use the right file name | 760 | # Make sure self.reload() will use the right file name |
139 | 673 | self._parser.filename = self.file_name | 761 | self._parser.filename = self.file_name |
140 | 674 | for hook in OldConfigHooks['load']: | 762 | for hook in OldConfigHooks['load']: |
141 | @@ -840,7 +928,7 @@ | |||
142 | 840 | try: | 928 | try: |
143 | 841 | del section[option_name] | 929 | del section[option_name] |
144 | 842 | except KeyError: | 930 | except KeyError: |
146 | 843 | raise errors.NoSuchConfigOption(option_name) | 931 | raise NoSuchConfigOption(option_name) |
147 | 844 | self._write_config_file() | 932 | self._write_config_file() |
148 | 845 | for hook in OldConfigHooks['remove']: | 933 | for hook in OldConfigHooks['remove']: |
149 | 846 | hook(self, option_name) | 934 | hook(self, option_name) |
150 | @@ -1591,7 +1679,7 @@ | |||
151 | 1591 | """ | 1679 | """ |
152 | 1592 | name, email = parse_username(e) | 1680 | name, email = parse_username(e) |
153 | 1593 | if not email: | 1681 | if not email: |
155 | 1594 | raise errors.NoEmailInUsername(e) | 1682 | raise NoEmailInUsername(e) |
156 | 1595 | return email | 1683 | return email |
157 | 1596 | 1684 | ||
158 | 1597 | 1685 | ||
159 | @@ -1669,9 +1757,9 @@ | |||
160 | 1669 | # encoded, but the values in the ConfigObj are always Unicode. | 1757 | # encoded, but the values in the ConfigObj are always Unicode. |
161 | 1670 | self._config = ConfigObj(self._input, encoding='utf-8') | 1758 | self._config = ConfigObj(self._input, encoding='utf-8') |
162 | 1671 | except configobj.ConfigObjError as e: | 1759 | except configobj.ConfigObjError as e: |
164 | 1672 | raise errors.ParseConfigError(e.errors, e.config.filename) | 1760 | raise ParseConfigError(e.errors, e.config.filename) |
165 | 1673 | except UnicodeError: | 1761 | except UnicodeError: |
167 | 1674 | raise errors.ConfigContentError(self._filename) | 1762 | raise ConfigContentError(self._filename) |
168 | 1675 | return self._config | 1763 | return self._config |
169 | 1676 | 1764 | ||
170 | 1677 | def _check_permissions(self): | 1765 | def _check_permissions(self): |
171 | @@ -2202,9 +2290,9 @@ | |||
172 | 2202 | try: | 2290 | try: |
173 | 2203 | conf = ConfigObj(f, encoding='utf-8') | 2291 | conf = ConfigObj(f, encoding='utf-8') |
174 | 2204 | except configobj.ConfigObjError as e: | 2292 | except configobj.ConfigObjError as e: |
176 | 2205 | raise errors.ParseConfigError(e.errors, self._external_url()) | 2293 | raise ParseConfigError(e.errors, self._external_url()) |
177 | 2206 | except UnicodeDecodeError: | 2294 | except UnicodeDecodeError: |
179 | 2207 | raise errors.ConfigContentError(self._external_url()) | 2295 | raise ConfigContentError(self._external_url()) |
180 | 2208 | finally: | 2296 | finally: |
181 | 2209 | f.close() | 2297 | f.close() |
182 | 2210 | return conf | 2298 | return conf |
183 | @@ -2320,7 +2408,7 @@ | |||
184 | 2320 | trace.warning('Value "%s" is not valid for "%s"', | 2408 | trace.warning('Value "%s" is not valid for "%s"', |
185 | 2321 | unicode_value, self.name) | 2409 | unicode_value, self.name) |
186 | 2322 | elif self.invalid == 'error': | 2410 | elif self.invalid == 'error': |
188 | 2323 | raise errors.ConfigOptionValueError(self.name, unicode_value) | 2411 | raise ConfigOptionValueError(self.name, unicode_value) |
189 | 2324 | return converted | 2412 | return converted |
190 | 2325 | 2413 | ||
191 | 2326 | def get_override(self): | 2414 | def get_override(self): |
192 | @@ -2520,7 +2608,7 @@ | |||
193 | 2520 | :param option_name: The name to validate. | 2608 | :param option_name: The name to validate. |
194 | 2521 | """ | 2609 | """ |
195 | 2522 | if _option_ref_re.match('{%s}' % option_name) is None: | 2610 | if _option_ref_re.match('{%s}' % option_name) is None: |
197 | 2523 | raise errors.IllegalOptionName(option_name) | 2611 | raise IllegalOptionName(option_name) |
198 | 2524 | 2612 | ||
199 | 2525 | def register(self, option): | 2613 | def register(self, option): |
200 | 2526 | """Register a new option to its name. | 2614 | """Register a new option to its name. |
201 | @@ -3153,9 +3241,9 @@ | |||
202 | 3153 | list_values=False) | 3241 | list_values=False) |
203 | 3154 | except configobj.ConfigObjError as e: | 3242 | except configobj.ConfigObjError as e: |
204 | 3155 | self._config_obj = None | 3243 | self._config_obj = None |
206 | 3156 | raise errors.ParseConfigError(e.errors, self.external_url()) | 3244 | raise ParseConfigError(e.errors, self.external_url()) |
207 | 3157 | except UnicodeDecodeError: | 3245 | except UnicodeDecodeError: |
209 | 3158 | raise errors.ConfigContentError(self.external_url()) | 3246 | raise ConfigContentError(self.external_url()) |
210 | 3159 | 3247 | ||
211 | 3160 | def save_changes(self): | 3248 | def save_changes(self): |
212 | 3161 | if not self.is_loaded(): | 3249 | if not self.is_loaded(): |
213 | @@ -3717,11 +3805,11 @@ | |||
214 | 3717 | expanded = True | 3805 | expanded = True |
215 | 3718 | name = chunk[1:-1] | 3806 | name = chunk[1:-1] |
216 | 3719 | if name in _refs: | 3807 | if name in _refs: |
218 | 3720 | raise errors.OptionExpansionLoop(string, _refs) | 3808 | raise OptionExpansionLoop(string, _refs) |
219 | 3721 | _refs.append(name) | 3809 | _refs.append(name) |
220 | 3722 | value = self._expand_option(name, env, _refs) | 3810 | value = self._expand_option(name, env, _refs) |
221 | 3723 | if value is None: | 3811 | if value is None: |
223 | 3724 | raise errors.ExpandingUnknownOption(name, string) | 3812 | raise ExpandingUnknownOption(name, string) |
224 | 3725 | chunks.append(value) | 3813 | chunks.append(value) |
225 | 3726 | _refs.pop() | 3814 | _refs.pop() |
226 | 3727 | result = ''.join(chunks) | 3815 | result = ''.join(chunks) |
227 | @@ -4112,7 +4200,7 @@ | |||
228 | 4112 | if write_access: | 4200 | if write_access: |
229 | 4113 | self.add_cleanup(br.lock_write().unlock) | 4201 | self.add_cleanup(br.lock_write().unlock) |
230 | 4114 | return br.get_config_stack() | 4202 | return br.get_config_stack() |
232 | 4115 | raise errors.NoSuchConfig(scope) | 4203 | raise NoSuchConfig(scope) |
233 | 4116 | else: | 4204 | else: |
234 | 4117 | try: | 4205 | try: |
235 | 4118 | (_, br, _) = ( | 4206 | (_, br, _) = ( |
236 | @@ -4137,7 +4225,7 @@ | |||
237 | 4137 | value = self._quote_multiline(value) | 4225 | value = self._quote_multiline(value) |
238 | 4138 | self.outf.write('%s\n' % (value,)) | 4226 | self.outf.write('%s\n' % (value,)) |
239 | 4139 | else: | 4227 | else: |
241 | 4140 | raise errors.NoSuchConfigOption(name) | 4228 | raise NoSuchConfigOption(name) |
242 | 4141 | 4229 | ||
243 | 4142 | def _show_matching_options(self, name, directory, scope): | 4230 | def _show_matching_options(self, name, directory, scope): |
244 | 4143 | name = lazy_regex.lazy_compile(name) | 4231 | name = lazy_regex.lazy_compile(name) |
245 | @@ -4182,7 +4270,7 @@ | |||
246 | 4182 | # Explicitly save the changes | 4270 | # Explicitly save the changes |
247 | 4183 | conf.store.save_changes() | 4271 | conf.store.save_changes() |
248 | 4184 | except KeyError: | 4272 | except KeyError: |
250 | 4185 | raise errors.NoSuchConfigOption(name) | 4273 | raise NoSuchConfigOption(name) |
251 | 4186 | 4274 | ||
252 | 4187 | 4275 | ||
253 | 4188 | # Test registries | 4276 | # Test registries |
254 | 4189 | 4277 | ||
255 | === modified file 'breezy/errors.py' | |||
256 | --- breezy/errors.py 2017-07-15 15:59:40 +0000 | |||
257 | +++ breezy/errors.py 2017-07-15 16:04:48 +0000 | |||
258 | @@ -1639,43 +1639,6 @@ | |||
259 | 1639 | _fmt = "Working tree has conflicts." | 1639 | _fmt = "Working tree has conflicts." |
260 | 1640 | 1640 | ||
261 | 1641 | 1641 | ||
262 | 1642 | class ConfigContentError(BzrError): | ||
263 | 1643 | |||
264 | 1644 | _fmt = "Config file %(filename)s is not UTF-8 encoded\n" | ||
265 | 1645 | |||
266 | 1646 | def __init__(self, filename): | ||
267 | 1647 | BzrError.__init__(self) | ||
268 | 1648 | self.filename = filename | ||
269 | 1649 | |||
270 | 1650 | |||
271 | 1651 | class ParseConfigError(BzrError): | ||
272 | 1652 | |||
273 | 1653 | _fmt = "Error(s) parsing config file %(filename)s:\n%(errors)s" | ||
274 | 1654 | |||
275 | 1655 | def __init__(self, errors, filename): | ||
276 | 1656 | BzrError.__init__(self) | ||
277 | 1657 | self.filename = filename | ||
278 | 1658 | self.errors = '\n'.join(e.msg for e in errors) | ||
279 | 1659 | |||
280 | 1660 | |||
281 | 1661 | class ConfigOptionValueError(BzrError): | ||
282 | 1662 | |||
283 | 1663 | _fmt = ('Bad value "%(value)s" for option "%(name)s".\n' | ||
284 | 1664 | 'See ``brz help %(name)s``') | ||
285 | 1665 | |||
286 | 1666 | def __init__(self, name, value): | ||
287 | 1667 | BzrError.__init__(self, name=name, value=value) | ||
288 | 1668 | |||
289 | 1669 | |||
290 | 1670 | class NoEmailInUsername(BzrError): | ||
291 | 1671 | |||
292 | 1672 | _fmt = "%(username)r does not seem to contain a reasonable email address" | ||
293 | 1673 | |||
294 | 1674 | def __init__(self, username): | ||
295 | 1675 | BzrError.__init__(self) | ||
296 | 1676 | self.username = username | ||
297 | 1677 | |||
298 | 1678 | |||
299 | 1679 | class DependencyNotPresent(BzrError): | 1642 | class DependencyNotPresent(BzrError): |
300 | 1680 | 1643 | ||
301 | 1681 | _fmt = 'Unable to import library "%(library)s": %(error)s' | 1644 | _fmt = 'Unable to import library "%(library)s": %(error)s' |
302 | @@ -2808,22 +2771,6 @@ | |||
303 | 2808 | self.user_encoding = get_user_encoding() | 2771 | self.user_encoding = get_user_encoding() |
304 | 2809 | 2772 | ||
305 | 2810 | 2773 | ||
306 | 2811 | class NoSuchConfig(BzrError): | ||
307 | 2812 | |||
308 | 2813 | _fmt = ('The "%(config_id)s" configuration does not exist.') | ||
309 | 2814 | |||
310 | 2815 | def __init__(self, config_id): | ||
311 | 2816 | BzrError.__init__(self, config_id=config_id) | ||
312 | 2817 | |||
313 | 2818 | |||
314 | 2819 | class NoSuchConfigOption(BzrError): | ||
315 | 2820 | |||
316 | 2821 | _fmt = ('The "%(option_name)s" configuration option does not exist.') | ||
317 | 2822 | |||
318 | 2823 | def __init__(self, option_name): | ||
319 | 2824 | BzrError.__init__(self, option_name=option_name) | ||
320 | 2825 | |||
321 | 2826 | |||
322 | 2827 | class NoSuchAlias(BzrError): | 2774 | class NoSuchAlias(BzrError): |
323 | 2828 | 2775 | ||
324 | 2829 | _fmt = ('The alias "%(alias_name)s" does not exist.') | 2776 | _fmt = ('The alias "%(alias_name)s" does not exist.') |
325 | @@ -3023,13 +2970,6 @@ | |||
326 | 3023 | self.controldir = controldir | 2970 | self.controldir = controldir |
327 | 3024 | 2971 | ||
328 | 3025 | 2972 | ||
329 | 3026 | class NoWhoami(BzrError): | ||
330 | 3027 | |||
331 | 3028 | _fmt = ('Unable to determine your name.\n' | ||
332 | 3029 | "Please, set your name with the 'whoami' command.\n" | ||
333 | 3030 | 'E.g. brz whoami "Your Name <name@example.com>"') | ||
334 | 3031 | |||
335 | 3032 | |||
336 | 3033 | class RecursiveBind(BzrError): | 2973 | class RecursiveBind(BzrError): |
337 | 3034 | 2974 | ||
338 | 3035 | _fmt = ('Branch "%(branch_url)s" appears to be bound to itself. ' | 2975 | _fmt = ('Branch "%(branch_url)s" appears to be bound to itself. ' |
339 | @@ -3039,34 +2979,6 @@ | |||
340 | 3039 | self.branch_url = branch_url | 2979 | self.branch_url = branch_url |
341 | 3040 | 2980 | ||
342 | 3041 | 2981 | ||
343 | 3042 | # FIXME: I would prefer to define the config related exception classes in | ||
344 | 3043 | # config.py but the lazy import mechanism proscribes this -- vila 20101222 | ||
345 | 3044 | class OptionExpansionLoop(BzrError): | ||
346 | 3045 | |||
347 | 3046 | _fmt = 'Loop involving %(refs)r while expanding "%(string)s".' | ||
348 | 3047 | |||
349 | 3048 | def __init__(self, string, refs): | ||
350 | 3049 | self.string = string | ||
351 | 3050 | self.refs = '->'.join(refs) | ||
352 | 3051 | |||
353 | 3052 | |||
354 | 3053 | class ExpandingUnknownOption(BzrError): | ||
355 | 3054 | |||
356 | 3055 | _fmt = 'Option "%(name)s" is not defined while expanding "%(string)s".' | ||
357 | 3056 | |||
358 | 3057 | def __init__(self, name, string): | ||
359 | 3058 | self.name = name | ||
360 | 3059 | self.string = string | ||
361 | 3060 | |||
362 | 3061 | |||
363 | 3062 | class IllegalOptionName(BzrError): | ||
364 | 3063 | |||
365 | 3064 | _fmt = 'Option "%(name)s" is not allowed.' | ||
366 | 3065 | |||
367 | 3066 | def __init__(self, name): | ||
368 | 3067 | self.name = name | ||
369 | 3068 | |||
370 | 3069 | |||
371 | 3070 | class HpssVfsRequestNotAllowed(BzrError): | 2982 | class HpssVfsRequestNotAllowed(BzrError): |
372 | 3071 | 2983 | ||
373 | 3072 | _fmt = ("VFS requests over the smart server are not allowed. Encountered: " | 2984 | _fmt = ("VFS requests over the smart server are not allowed. Encountered: " |
374 | 3073 | 2985 | ||
375 | === modified file 'breezy/tests/test_config.py' | |||
376 | --- breezy/tests/test_config.py 2017-07-04 20:03:11 +0000 | |||
377 | +++ breezy/tests/test_config.py 2017-07-15 16:04:48 +0000 | |||
378 | @@ -654,7 +654,7 @@ | |||
379 | 654 | 654 | ||
380 | 655 | def test_unknown_ref(self): | 655 | def test_unknown_ref(self): |
381 | 656 | c = self.get_config('') | 656 | c = self.get_config('') |
383 | 657 | self.assertRaises(errors.ExpandingUnknownOption, | 657 | self.assertRaises(config.ExpandingUnknownOption, |
384 | 658 | c.expand_options, '{foo}') | 658 | c.expand_options, '{foo}') |
385 | 659 | 659 | ||
386 | 660 | def test_indirect_ref(self): | 660 | def test_indirect_ref(self): |
387 | @@ -673,14 +673,15 @@ | |||
388 | 673 | 673 | ||
389 | 674 | def test_simple_loop(self): | 674 | def test_simple_loop(self): |
390 | 675 | c = self.get_config('foo={foo}') | 675 | c = self.get_config('foo={foo}') |
392 | 676 | self.assertRaises(errors.OptionExpansionLoop, c.expand_options, '{foo}') | 676 | self.assertRaises(config.OptionExpansionLoop, c.expand_options, |
393 | 677 | '{foo}') | ||
394 | 677 | 678 | ||
395 | 678 | def test_indirect_loop(self): | 679 | def test_indirect_loop(self): |
396 | 679 | c = self.get_config(''' | 680 | c = self.get_config(''' |
397 | 680 | foo={bar} | 681 | foo={bar} |
398 | 681 | bar={baz} | 682 | bar={baz} |
399 | 682 | baz={foo}''') | 683 | baz={foo}''') |
401 | 683 | e = self.assertRaises(errors.OptionExpansionLoop, | 684 | e = self.assertRaises(config.OptionExpansionLoop, |
402 | 684 | c.expand_options, '{foo}') | 685 | c.expand_options, '{foo}') |
403 | 685 | self.assertEqual('foo->bar->baz', e.refs) | 686 | self.assertEqual('foo->bar->baz', e.refs) |
404 | 686 | self.assertEqual('{foo}', e.string) | 687 | self.assertEqual('{foo}', e.string) |
405 | @@ -739,7 +740,7 @@ | |||
406 | 739 | [/another/branch/path] | 740 | [/another/branch/path] |
407 | 740 | bar = {foo}/2 | 741 | bar = {foo}/2 |
408 | 741 | ''') | 742 | ''') |
410 | 742 | self.assertRaises(errors.ExpandingUnknownOption, | 743 | self.assertRaises(config.ExpandingUnknownOption, |
411 | 743 | c.get_user_option, 'bar', expand=True) | 744 | c.get_user_option, 'bar', expand=True) |
412 | 744 | 745 | ||
413 | 745 | def test_cross_related_sections(self): | 746 | def test_cross_related_sections(self): |
414 | @@ -1534,7 +1535,7 @@ | |||
415 | 1534 | def test_extract_email_address(self): | 1535 | def test_extract_email_address(self): |
416 | 1535 | self.assertEqual('jane@test.com', | 1536 | self.assertEqual('jane@test.com', |
417 | 1536 | config.extract_email_address('Jane <jane@test.com>')) | 1537 | config.extract_email_address('Jane <jane@test.com>')) |
419 | 1537 | self.assertRaises(errors.NoEmailInUsername, | 1538 | self.assertRaises(config.NoEmailInUsername, |
420 | 1538 | config.extract_email_address, 'Jane Tester') | 1539 | config.extract_email_address, 'Jane Tester') |
421 | 1539 | 1540 | ||
422 | 1540 | def test_parse_username(self): | 1541 | def test_parse_username(self): |
423 | @@ -1595,14 +1596,14 @@ | |||
424 | 1595 | t = self.get_transport() | 1596 | t = self.get_transport() |
425 | 1596 | t.put_bytes('foo.conf', 'user=foo\n#\xff\n') | 1597 | t.put_bytes('foo.conf', 'user=foo\n#\xff\n') |
426 | 1597 | conf = config.TransportConfig(t, 'foo.conf') | 1598 | conf = config.TransportConfig(t, 'foo.conf') |
428 | 1598 | self.assertRaises(errors.ConfigContentError, conf._get_configobj) | 1599 | self.assertRaises(config.ConfigContentError, conf._get_configobj) |
429 | 1599 | 1600 | ||
430 | 1600 | def test_load_erroneous_content(self): | 1601 | def test_load_erroneous_content(self): |
431 | 1601 | """Ensure we display a proper error on content that can't be parsed.""" | 1602 | """Ensure we display a proper error on content that can't be parsed.""" |
432 | 1602 | t = self.get_transport() | 1603 | t = self.get_transport() |
433 | 1603 | t.put_bytes('foo.conf', '[open_section\n') | 1604 | t.put_bytes('foo.conf', '[open_section\n') |
434 | 1604 | conf = config.TransportConfig(t, 'foo.conf') | 1605 | conf = config.TransportConfig(t, 'foo.conf') |
436 | 1605 | self.assertRaises(errors.ParseConfigError, conf._get_configobj) | 1606 | self.assertRaises(config.ParseConfigError, conf._get_configobj) |
437 | 1606 | 1607 | ||
438 | 1607 | def test_load_permission_denied(self): | 1608 | def test_load_permission_denied(self): |
439 | 1608 | """Ensure we get an empty config file if the file is inaccessible.""" | 1609 | """Ensure we get an empty config file if the file is inaccessible.""" |
440 | @@ -2012,7 +2013,7 @@ | |||
441 | 2012 | warnings[0]) | 2013 | warnings[0]) |
442 | 2013 | 2014 | ||
443 | 2014 | def assertCallsError(self, opt, value): | 2015 | def assertCallsError(self, opt, value): |
445 | 2015 | self.assertRaises(errors.ConfigOptionValueError, | 2016 | self.assertRaises(config.ConfigOptionValueError, |
446 | 2016 | opt.convert_from_unicode, None, value) | 2017 | opt.convert_from_unicode, None, value) |
447 | 2017 | 2018 | ||
448 | 2018 | def assertConvertInvalid(self, opt, invalid_value): | 2019 | def assertConvertInvalid(self, opt, invalid_value): |
449 | @@ -2179,9 +2180,9 @@ | |||
450 | 2179 | self.assertEqual('A simple option', self.registry.get_help('foo')) | 2180 | self.assertEqual('A simple option', self.registry.get_help('foo')) |
451 | 2180 | 2181 | ||
452 | 2181 | def test_dont_register_illegal_name(self): | 2182 | def test_dont_register_illegal_name(self): |
454 | 2182 | self.assertRaises(errors.IllegalOptionName, | 2183 | self.assertRaises(config.IllegalOptionName, |
455 | 2183 | self.registry.register, config.Option(' foo')) | 2184 | self.registry.register, config.Option(' foo')) |
457 | 2184 | self.assertRaises(errors.IllegalOptionName, | 2185 | self.assertRaises(config.IllegalOptionName, |
458 | 2185 | self.registry.register, config.Option('bar,')) | 2186 | self.registry.register, config.Option('bar,')) |
459 | 2186 | 2187 | ||
460 | 2187 | lazy_option = config.Option('lazy_foo', help='Lazy help') | 2188 | lazy_option = config.Option('lazy_foo', help='Lazy help') |
461 | @@ -2202,10 +2203,10 @@ | |||
462 | 2202 | # the option name which indirectly requires that the option name is a | 2203 | # the option name which indirectly requires that the option name is a |
463 | 2203 | # valid python identifier. We violate that rule here (using a key that | 2204 | # valid python identifier. We violate that rule here (using a key that |
464 | 2204 | # doesn't match the option name) to test the option name checking. | 2205 | # doesn't match the option name) to test the option name checking. |
466 | 2205 | self.assertRaises(errors.IllegalOptionName, | 2206 | self.assertRaises(config.IllegalOptionName, |
467 | 2206 | self.registry.register_lazy, ' foo', self.__module__, | 2207 | self.registry.register_lazy, ' foo', self.__module__, |
468 | 2207 | 'TestOptionRegistry.lazy_option') | 2208 | 'TestOptionRegistry.lazy_option') |
470 | 2208 | self.assertRaises(errors.IllegalOptionName, | 2209 | self.assertRaises(config.IllegalOptionName, |
471 | 2209 | self.registry.register_lazy, '1,2', self.__module__, | 2210 | self.registry.register_lazy, '1,2', self.__module__, |
472 | 2210 | 'TestOptionRegistry.lazy_option') | 2211 | 'TestOptionRegistry.lazy_option') |
473 | 2211 | 2212 | ||
474 | @@ -2519,14 +2520,14 @@ | |||
475 | 2519 | t = self.get_transport() | 2520 | t = self.get_transport() |
476 | 2520 | t.put_bytes('foo.conf', 'user=foo\n#%s\n' % (self.invalid_utf8_char,)) | 2521 | t.put_bytes('foo.conf', 'user=foo\n#%s\n' % (self.invalid_utf8_char,)) |
477 | 2521 | store = config.TransportIniFileStore(t, 'foo.conf') | 2522 | store = config.TransportIniFileStore(t, 'foo.conf') |
479 | 2522 | self.assertRaises(errors.ConfigContentError, store.load) | 2523 | self.assertRaises(config.ConfigContentError, store.load) |
480 | 2523 | 2524 | ||
481 | 2524 | def test_load_erroneous_content(self): | 2525 | def test_load_erroneous_content(self): |
482 | 2525 | """Ensure we display a proper error on content that can't be parsed.""" | 2526 | """Ensure we display a proper error on content that can't be parsed.""" |
483 | 2526 | t = self.get_transport() | 2527 | t = self.get_transport() |
484 | 2527 | t.put_bytes('foo.conf', '[open_section\n') | 2528 | t.put_bytes('foo.conf', '[open_section\n') |
485 | 2528 | store = config.TransportIniFileStore(t, 'foo.conf') | 2529 | store = config.TransportIniFileStore(t, 'foo.conf') |
487 | 2529 | self.assertRaises(errors.ParseConfigError, store.load) | 2530 | self.assertRaises(config.ParseConfigError, store.load) |
488 | 2530 | 2531 | ||
489 | 2531 | def test_load_permission_denied(self): | 2532 | def test_load_permission_denied(self): |
490 | 2532 | """Ensure we get warned when trying to load an inaccessible file.""" | 2533 | """Ensure we get warned when trying to load an inaccessible file.""" |
491 | @@ -2576,14 +2577,14 @@ | |||
492 | 2576 | with open('foo.conf', 'wb') as f: | 2577 | with open('foo.conf', 'wb') as f: |
493 | 2577 | f.write('user=foo\n#%s\n' % (self.invalid_utf8_char,)) | 2578 | f.write('user=foo\n#%s\n' % (self.invalid_utf8_char,)) |
494 | 2578 | conf = config.IniBasedConfig(file_name='foo.conf') | 2579 | conf = config.IniBasedConfig(file_name='foo.conf') |
496 | 2579 | self.assertRaises(errors.ConfigContentError, conf._get_parser) | 2580 | self.assertRaises(config.ConfigContentError, conf._get_parser) |
497 | 2580 | 2581 | ||
498 | 2581 | def test_load_erroneous_content(self): | 2582 | def test_load_erroneous_content(self): |
499 | 2582 | """Ensure we display a proper error on content that can't be parsed.""" | 2583 | """Ensure we display a proper error on content that can't be parsed.""" |
500 | 2583 | with open('foo.conf', 'wb') as f: | 2584 | with open('foo.conf', 'wb') as f: |
501 | 2584 | f.write('[open_section\n') | 2585 | f.write('[open_section\n') |
502 | 2585 | conf = config.IniBasedConfig(file_name='foo.conf') | 2586 | conf = config.IniBasedConfig(file_name='foo.conf') |
504 | 2586 | self.assertRaises(errors.ParseConfigError, conf._get_parser) | 2587 | self.assertRaises(config.ParseConfigError, conf._get_parser) |
505 | 2587 | 2588 | ||
506 | 2588 | 2589 | ||
507 | 2589 | class TestMutableStore(TestStore): | 2590 | class TestMutableStore(TestStore): |
508 | @@ -2868,7 +2869,7 @@ | |||
509 | 2868 | store = config.TransportIniFileStore(self.get_transport(), 'foo.conf') | 2869 | store = config.TransportIniFileStore(self.get_transport(), 'foo.conf') |
510 | 2869 | self.assertEqual(False, store.is_loaded()) | 2870 | self.assertEqual(False, store.is_loaded()) |
511 | 2870 | exc = self.assertRaises( | 2871 | exc = self.assertRaises( |
513 | 2871 | errors.ParseConfigError, store._load_from_string, | 2872 | config.ParseConfigError, store._load_from_string, |
514 | 2872 | 'this is invalid !') | 2873 | 'this is invalid !') |
515 | 2873 | self.assertEndsWith(exc.filename, 'foo.conf') | 2874 | self.assertEndsWith(exc.filename, 'foo.conf') |
516 | 2874 | # And the load failed | 2875 | # And the load failed |
517 | @@ -3668,7 +3669,7 @@ | |||
518 | 3668 | self.assertExpansion('xxx', '{foo}') | 3669 | self.assertExpansion('xxx', '{foo}') |
519 | 3669 | 3670 | ||
520 | 3670 | def test_unknown_ref(self): | 3671 | def test_unknown_ref(self): |
522 | 3671 | self.assertRaises(errors.ExpandingUnknownOption, | 3672 | self.assertRaises(config.ExpandingUnknownOption, |
523 | 3672 | self.conf.expand_options, '{foo}') | 3673 | self.conf.expand_options, '{foo}') |
524 | 3673 | 3674 | ||
525 | 3674 | def test_illegal_def_is_ignored(self): | 3675 | def test_illegal_def_is_ignored(self): |
526 | @@ -3692,7 +3693,7 @@ | |||
527 | 3692 | 3693 | ||
528 | 3693 | def test_simple_loop(self): | 3694 | def test_simple_loop(self): |
529 | 3694 | self.conf.store._load_from_string('foo={foo}') | 3695 | self.conf.store._load_from_string('foo={foo}') |
531 | 3695 | self.assertRaises(errors.OptionExpansionLoop, | 3696 | self.assertRaises(config.OptionExpansionLoop, |
532 | 3696 | self.conf.expand_options, '{foo}') | 3697 | self.conf.expand_options, '{foo}') |
533 | 3697 | 3698 | ||
534 | 3698 | def test_indirect_loop(self): | 3699 | def test_indirect_loop(self): |
535 | @@ -3700,7 +3701,7 @@ | |||
536 | 3700 | foo={bar} | 3701 | foo={bar} |
537 | 3701 | bar={baz} | 3702 | bar={baz} |
538 | 3702 | baz={foo}''') | 3703 | baz={foo}''') |
540 | 3703 | e = self.assertRaises(errors.OptionExpansionLoop, | 3704 | e = self.assertRaises(config.OptionExpansionLoop, |
541 | 3704 | self.conf.expand_options, '{foo}') | 3705 | self.conf.expand_options, '{foo}') |
542 | 3705 | self.assertEqual('foo->bar->baz', e.refs) | 3706 | self.assertEqual('foo->bar->baz', e.refs) |
543 | 3706 | self.assertEqual('{foo}', e.string) | 3707 | self.assertEqual('{foo}', e.string) |
544 | @@ -3771,7 +3772,7 @@ | |||
545 | 3771 | [/another/branch/path] | 3772 | [/another/branch/path] |
546 | 3772 | bar = {foo}/2 | 3773 | bar = {foo}/2 |
547 | 3773 | ''') | 3774 | ''') |
549 | 3774 | self.assertRaises(errors.ExpandingUnknownOption, | 3775 | self.assertRaises(config.ExpandingUnknownOption, |
550 | 3775 | c.get, 'bar', expand=True) | 3776 | c.get, 'bar', expand=True) |
551 | 3776 | 3777 | ||
552 | 3777 | def test_cross_related_sections(self): | 3778 | def test_cross_related_sections(self): |
553 | @@ -3859,7 +3860,7 @@ | |||
554 | 3859 | ''') | 3860 | ''') |
555 | 3860 | g_store.save() | 3861 | g_store.save() |
556 | 3861 | stack = config.LocationStack('/home/user/project/branch') | 3862 | stack = config.LocationStack('/home/user/project/branch') |
558 | 3862 | self.assertRaises(errors.ExpandingUnknownOption, | 3863 | self.assertRaises(config.ExpandingUnknownOption, |
559 | 3863 | stack.get, 'gfoo', expand=True) | 3864 | stack.get, 'gfoo', expand=True) |
560 | 3864 | 3865 | ||
561 | 3865 | def test_expand_local_option_locally(self): | 3866 | def test_expand_local_option_locally(self): |
562 | @@ -4166,7 +4167,7 @@ | |||
563 | 4166 | 4167 | ||
564 | 4167 | def test_non_utf8_config(self): | 4168 | def test_non_utf8_config(self): |
565 | 4168 | conf = config.AuthenticationConfig(_file=BytesIO(b'foo = bar\xff')) | 4169 | conf = config.AuthenticationConfig(_file=BytesIO(b'foo = bar\xff')) |
567 | 4169 | self.assertRaises(errors.ConfigContentError, conf._get_config) | 4170 | self.assertRaises(config.ConfigContentError, conf._get_config) |
568 | 4170 | 4171 | ||
569 | 4171 | def test_missing_auth_section_header(self): | 4172 | def test_missing_auth_section_header(self): |
570 | 4172 | conf = config.AuthenticationConfig(_file=BytesIO(b'foo = bar')) | 4173 | conf = config.AuthenticationConfig(_file=BytesIO(b'foo = bar')) |
571 | @@ -4174,7 +4175,7 @@ | |||
572 | 4174 | 4175 | ||
573 | 4175 | def test_auth_section_header_not_closed(self): | 4176 | def test_auth_section_header_not_closed(self): |
574 | 4176 | conf = config.AuthenticationConfig(_file=BytesIO(b'[DEF')) | 4177 | conf = config.AuthenticationConfig(_file=BytesIO(b'[DEF')) |
576 | 4177 | self.assertRaises(errors.ParseConfigError, conf._get_config) | 4178 | self.assertRaises(config.ParseConfigError, conf._get_config) |
577 | 4178 | 4179 | ||
578 | 4179 | def test_auth_value_not_boolean(self): | 4180 | def test_auth_value_not_boolean(self): |
579 | 4180 | conf = config.AuthenticationConfig(_file=BytesIO(b"""\ | 4181 | conf = config.AuthenticationConfig(_file=BytesIO(b"""\ |
580 | @@ -4765,5 +4766,5 @@ | |||
581 | 4765 | 4766 | ||
582 | 4766 | def test_unknown(self): | 4767 | def test_unknown(self): |
583 | 4767 | conf = config.MemoryStack('mail_client=firebird') | 4768 | conf = config.MemoryStack('mail_client=firebird') |
585 | 4768 | self.assertRaises(errors.ConfigOptionValueError, conf.get, | 4769 | self.assertRaises(config.ConfigOptionValueError, conf.get, |
586 | 4769 | 'mail_client') | 4770 | 'mail_client') |
See inline comment, otherwise looks sane.