Merge lp:~jelmer/brz/move-errors-config into lp:brz

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
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.
Revision history for this message
Martin Packman (gz) wrote :

See inline comment, otherwise looks sane.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'breezy/config.py'
--- breezy/config.py 2017-07-04 20:03:11 +0000
+++ breezy/config.py 2017-07-15 16:04:48 +0000
@@ -92,7 +92,6 @@
92 controldir,92 controldir,
93 debug,93 debug,
94 directory_service,94 directory_service,
95 errors,
96 lazy_regex,95 lazy_regex,
97 library_state,96 library_state,
98 lockdir,97 lockdir,
@@ -108,6 +107,7 @@
108""")107""")
109from . import (108from . import (
110 commands,109 commands,
110 errors,
111 hooks,111 hooks,
112 lazy_regex,112 lazy_regex,
113 registry,113 registry,
@@ -155,6 +155,94 @@
155STORE_GLOBAL = 4155STORE_GLOBAL = 4
156156
157157
158# FIXME: I would prefer to define the config related exception classes in
159# config.py but the lazy import mechanism proscribes this -- vila 20101222
160class OptionExpansionLoop(errors.BzrError):
161
162 _fmt = 'Loop involving %(refs)r while expanding "%(string)s".'
163
164 def __init__(self, string, refs):
165 self.string = string
166 self.refs = '->'.join(refs)
167
168
169class ExpandingUnknownOption(errors.BzrError):
170
171 _fmt = 'Option "%(name)s" is not defined while expanding "%(string)s".'
172
173 def __init__(self, name, string):
174 self.name = name
175 self.string = string
176
177
178class IllegalOptionName(errors.BzrError):
179
180 _fmt = 'Option "%(name)s" is not allowed.'
181
182 def __init__(self, name):
183 self.name = name
184
185
186class ConfigContentError(errors.BzrError):
187
188 _fmt = "Config file %(filename)s is not UTF-8 encoded\n"
189
190 def __init__(self, filename):
191 errors.BzrError.__init__(self)
192 self.filename = filename
193
194
195class ParseConfigError(errors.BzrError):
196
197 _fmt = "Error(s) parsing config file %(filename)s:\n%(errors)s"
198
199 def __init__(self, errors, filename):
200 errors.BzrError.__init__(self)
201 self.filename = filename
202 self.errors = '\n'.join(e.msg for e in errors)
203
204
205class ConfigOptionValueError(errors.BzrError):
206
207 _fmt = ('Bad value "%(value)s" for option "%(name)s".\n'
208 'See ``brz help %(name)s``')
209
210 def __init__(self, name, value):
211 errors.BzrError.__init__(self, name=name, value=value)
212
213
214class NoEmailInUsername(errors.BzrError):
215
216 _fmt = "%(username)r does not seem to contain a reasonable email address"
217
218 def __init__(self, username):
219 errors.BzrError.__init__(self)
220 self.username = username
221
222
223class NoSuchConfig(errors.BzrError):
224
225 _fmt = ('The "%(config_id)s" configuration does not exist.')
226
227 def __init__(self, config_id):
228 errors.BzrError.__init__(self, config_id=config_id)
229
230
231class NoSuchConfigOption(errors.BzrError):
232
233 _fmt = ('The "%(option_name)s" configuration option does not exist.')
234
235 def __init__(self, option_name):
236 errors.BzrError.__init__(self, option_name=option_name)
237
238
239class NoWhoami(errors.BzrError):
240
241 _fmt = ('Unable to determine your name.\n'
242 "Please, set your name with the 'whoami' command.\n"
243 'E.g. brz whoami "Your Name <name@example.com>"')
244
245
158def signature_policy_from_unicode(signature_string):246def signature_policy_from_unicode(signature_string):
159 """Convert a string to a signing policy."""247 """Convert a string to a signing policy."""
160 if signature_string.lower() == 'check-available':248 if signature_string.lower() == 'check-available':
@@ -342,11 +430,11 @@
342 else:430 else:
343 name = chunk[1:-1]431 name = chunk[1:-1]
344 if name in _ref_stack:432 if name in _ref_stack:
345 raise errors.OptionExpansionLoop(string, _ref_stack)433 raise OptionExpansionLoop(string, _ref_stack)
346 _ref_stack.append(name)434 _ref_stack.append(name)
347 value = self._expand_option(name, env, _ref_stack)435 value = self._expand_option(name, env, _ref_stack)
348 if value is None:436 if value is None:
349 raise errors.ExpandingUnknownOption(name, string)437 raise ExpandingUnknownOption(name, string)
350 if isinstance(value, list):438 if isinstance(value, list):
351 list_value = True439 list_value = True
352 chunks.extend(value)440 chunks.extend(value)
@@ -666,9 +754,9 @@
666 try:754 try:
667 self._parser = ConfigObj(co_input, encoding='utf-8')755 self._parser = ConfigObj(co_input, encoding='utf-8')
668 except configobj.ConfigObjError as e:756 except configobj.ConfigObjError as e:
669 raise errors.ParseConfigError(e.errors, e.config.filename)757 raise ParseConfigError(e.errors, e.config.filename)
670 except UnicodeDecodeError:758 except UnicodeDecodeError:
671 raise errors.ConfigContentError(self.file_name)759 raise ConfigContentError(self.file_name)
672 # Make sure self.reload() will use the right file name760 # Make sure self.reload() will use the right file name
673 self._parser.filename = self.file_name761 self._parser.filename = self.file_name
674 for hook in OldConfigHooks['load']:762 for hook in OldConfigHooks['load']:
@@ -840,7 +928,7 @@
840 try:928 try:
841 del section[option_name]929 del section[option_name]
842 except KeyError:930 except KeyError:
843 raise errors.NoSuchConfigOption(option_name)931 raise NoSuchConfigOption(option_name)
844 self._write_config_file()932 self._write_config_file()
845 for hook in OldConfigHooks['remove']:933 for hook in OldConfigHooks['remove']:
846 hook(self, option_name)934 hook(self, option_name)
@@ -1591,7 +1679,7 @@
1591 """1679 """
1592 name, email = parse_username(e)1680 name, email = parse_username(e)
1593 if not email:1681 if not email:
1594 raise errors.NoEmailInUsername(e)1682 raise NoEmailInUsername(e)
1595 return email1683 return email
15961684
15971685
@@ -1669,9 +1757,9 @@
1669 # encoded, but the values in the ConfigObj are always Unicode.1757 # encoded, but the values in the ConfigObj are always Unicode.
1670 self._config = ConfigObj(self._input, encoding='utf-8')1758 self._config = ConfigObj(self._input, encoding='utf-8')
1671 except configobj.ConfigObjError as e:1759 except configobj.ConfigObjError as e:
1672 raise errors.ParseConfigError(e.errors, e.config.filename)1760 raise ParseConfigError(e.errors, e.config.filename)
1673 except UnicodeError:1761 except UnicodeError:
1674 raise errors.ConfigContentError(self._filename)1762 raise ConfigContentError(self._filename)
1675 return self._config1763 return self._config
16761764
1677 def _check_permissions(self):1765 def _check_permissions(self):
@@ -2202,9 +2290,9 @@
2202 try:2290 try:
2203 conf = ConfigObj(f, encoding='utf-8')2291 conf = ConfigObj(f, encoding='utf-8')
2204 except configobj.ConfigObjError as e:2292 except configobj.ConfigObjError as e:
2205 raise errors.ParseConfigError(e.errors, self._external_url())2293 raise ParseConfigError(e.errors, self._external_url())
2206 except UnicodeDecodeError:2294 except UnicodeDecodeError:
2207 raise errors.ConfigContentError(self._external_url())2295 raise ConfigContentError(self._external_url())
2208 finally:2296 finally:
2209 f.close()2297 f.close()
2210 return conf2298 return conf
@@ -2320,7 +2408,7 @@
2320 trace.warning('Value "%s" is not valid for "%s"',2408 trace.warning('Value "%s" is not valid for "%s"',
2321 unicode_value, self.name)2409 unicode_value, self.name)
2322 elif self.invalid == 'error':2410 elif self.invalid == 'error':
2323 raise errors.ConfigOptionValueError(self.name, unicode_value)2411 raise ConfigOptionValueError(self.name, unicode_value)
2324 return converted2412 return converted
23252413
2326 def get_override(self):2414 def get_override(self):
@@ -2520,7 +2608,7 @@
2520 :param option_name: The name to validate.2608 :param option_name: The name to validate.
2521 """2609 """
2522 if _option_ref_re.match('{%s}' % option_name) is None:2610 if _option_ref_re.match('{%s}' % option_name) is None:
2523 raise errors.IllegalOptionName(option_name)2611 raise IllegalOptionName(option_name)
25242612
2525 def register(self, option):2613 def register(self, option):
2526 """Register a new option to its name.2614 """Register a new option to its name.
@@ -3153,9 +3241,9 @@
3153 list_values=False)3241 list_values=False)
3154 except configobj.ConfigObjError as e:3242 except configobj.ConfigObjError as e:
3155 self._config_obj = None3243 self._config_obj = None
3156 raise errors.ParseConfigError(e.errors, self.external_url())3244 raise ParseConfigError(e.errors, self.external_url())
3157 except UnicodeDecodeError:3245 except UnicodeDecodeError:
3158 raise errors.ConfigContentError(self.external_url())3246 raise ConfigContentError(self.external_url())
31593247
3160 def save_changes(self):3248 def save_changes(self):
3161 if not self.is_loaded():3249 if not self.is_loaded():
@@ -3717,11 +3805,11 @@
3717 expanded = True3805 expanded = True
3718 name = chunk[1:-1]3806 name = chunk[1:-1]
3719 if name in _refs:3807 if name in _refs:
3720 raise errors.OptionExpansionLoop(string, _refs)3808 raise OptionExpansionLoop(string, _refs)
3721 _refs.append(name)3809 _refs.append(name)
3722 value = self._expand_option(name, env, _refs)3810 value = self._expand_option(name, env, _refs)
3723 if value is None:3811 if value is None:
3724 raise errors.ExpandingUnknownOption(name, string)3812 raise ExpandingUnknownOption(name, string)
3725 chunks.append(value)3813 chunks.append(value)
3726 _refs.pop()3814 _refs.pop()
3727 result = ''.join(chunks)3815 result = ''.join(chunks)
@@ -4112,7 +4200,7 @@
4112 if write_access:4200 if write_access:
4113 self.add_cleanup(br.lock_write().unlock)4201 self.add_cleanup(br.lock_write().unlock)
4114 return br.get_config_stack()4202 return br.get_config_stack()
4115 raise errors.NoSuchConfig(scope)4203 raise NoSuchConfig(scope)
4116 else:4204 else:
4117 try:4205 try:
4118 (_, br, _) = (4206 (_, br, _) = (
@@ -4137,7 +4225,7 @@
4137 value = self._quote_multiline(value)4225 value = self._quote_multiline(value)
4138 self.outf.write('%s\n' % (value,))4226 self.outf.write('%s\n' % (value,))
4139 else:4227 else:
4140 raise errors.NoSuchConfigOption(name)4228 raise NoSuchConfigOption(name)
41414229
4142 def _show_matching_options(self, name, directory, scope):4230 def _show_matching_options(self, name, directory, scope):
4143 name = lazy_regex.lazy_compile(name)4231 name = lazy_regex.lazy_compile(name)
@@ -4182,7 +4270,7 @@
4182 # Explicitly save the changes4270 # Explicitly save the changes
4183 conf.store.save_changes()4271 conf.store.save_changes()
4184 except KeyError:4272 except KeyError:
4185 raise errors.NoSuchConfigOption(name)4273 raise NoSuchConfigOption(name)
41864274
41874275
4188# Test registries4276# Test registries
41894277
=== modified file 'breezy/errors.py'
--- breezy/errors.py 2017-07-15 15:59:40 +0000
+++ breezy/errors.py 2017-07-15 16:04:48 +0000
@@ -1639,43 +1639,6 @@
1639 _fmt = "Working tree has conflicts."1639 _fmt = "Working tree has conflicts."
16401640
16411641
1642class ConfigContentError(BzrError):
1643
1644 _fmt = "Config file %(filename)s is not UTF-8 encoded\n"
1645
1646 def __init__(self, filename):
1647 BzrError.__init__(self)
1648 self.filename = filename
1649
1650
1651class ParseConfigError(BzrError):
1652
1653 _fmt = "Error(s) parsing config file %(filename)s:\n%(errors)s"
1654
1655 def __init__(self, errors, filename):
1656 BzrError.__init__(self)
1657 self.filename = filename
1658 self.errors = '\n'.join(e.msg for e in errors)
1659
1660
1661class ConfigOptionValueError(BzrError):
1662
1663 _fmt = ('Bad value "%(value)s" for option "%(name)s".\n'
1664 'See ``brz help %(name)s``')
1665
1666 def __init__(self, name, value):
1667 BzrError.__init__(self, name=name, value=value)
1668
1669
1670class NoEmailInUsername(BzrError):
1671
1672 _fmt = "%(username)r does not seem to contain a reasonable email address"
1673
1674 def __init__(self, username):
1675 BzrError.__init__(self)
1676 self.username = username
1677
1678
1679class DependencyNotPresent(BzrError):1642class DependencyNotPresent(BzrError):
16801643
1681 _fmt = 'Unable to import library "%(library)s": %(error)s'1644 _fmt = 'Unable to import library "%(library)s": %(error)s'
@@ -2808,22 +2771,6 @@
2808 self.user_encoding = get_user_encoding()2771 self.user_encoding = get_user_encoding()
28092772
28102773
2811class NoSuchConfig(BzrError):
2812
2813 _fmt = ('The "%(config_id)s" configuration does not exist.')
2814
2815 def __init__(self, config_id):
2816 BzrError.__init__(self, config_id=config_id)
2817
2818
2819class NoSuchConfigOption(BzrError):
2820
2821 _fmt = ('The "%(option_name)s" configuration option does not exist.')
2822
2823 def __init__(self, option_name):
2824 BzrError.__init__(self, option_name=option_name)
2825
2826
2827class NoSuchAlias(BzrError):2774class NoSuchAlias(BzrError):
28282775
2829 _fmt = ('The alias "%(alias_name)s" does not exist.')2776 _fmt = ('The alias "%(alias_name)s" does not exist.')
@@ -3023,13 +2970,6 @@
3023 self.controldir = controldir2970 self.controldir = controldir
30242971
30252972
3026class NoWhoami(BzrError):
3027
3028 _fmt = ('Unable to determine your name.\n'
3029 "Please, set your name with the 'whoami' command.\n"
3030 'E.g. brz whoami "Your Name <name@example.com>"')
3031
3032
3033class RecursiveBind(BzrError):2973class RecursiveBind(BzrError):
30342974
3035 _fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '2975 _fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
@@ -3039,34 +2979,6 @@
3039 self.branch_url = branch_url2979 self.branch_url = branch_url
30402980
30412981
3042# FIXME: I would prefer to define the config related exception classes in
3043# config.py but the lazy import mechanism proscribes this -- vila 20101222
3044class OptionExpansionLoop(BzrError):
3045
3046 _fmt = 'Loop involving %(refs)r while expanding "%(string)s".'
3047
3048 def __init__(self, string, refs):
3049 self.string = string
3050 self.refs = '->'.join(refs)
3051
3052
3053class ExpandingUnknownOption(BzrError):
3054
3055 _fmt = 'Option "%(name)s" is not defined while expanding "%(string)s".'
3056
3057 def __init__(self, name, string):
3058 self.name = name
3059 self.string = string
3060
3061
3062class IllegalOptionName(BzrError):
3063
3064 _fmt = 'Option "%(name)s" is not allowed.'
3065
3066 def __init__(self, name):
3067 self.name = name
3068
3069
3070class HpssVfsRequestNotAllowed(BzrError):2982class HpssVfsRequestNotAllowed(BzrError):
30712983
3072 _fmt = ("VFS requests over the smart server are not allowed. Encountered: "2984 _fmt = ("VFS requests over the smart server are not allowed. Encountered: "
30732985
=== modified file 'breezy/tests/test_config.py'
--- breezy/tests/test_config.py 2017-07-04 20:03:11 +0000
+++ breezy/tests/test_config.py 2017-07-15 16:04:48 +0000
@@ -654,7 +654,7 @@
654654
655 def test_unknown_ref(self):655 def test_unknown_ref(self):
656 c = self.get_config('')656 c = self.get_config('')
657 self.assertRaises(errors.ExpandingUnknownOption,657 self.assertRaises(config.ExpandingUnknownOption,
658 c.expand_options, '{foo}')658 c.expand_options, '{foo}')
659659
660 def test_indirect_ref(self):660 def test_indirect_ref(self):
@@ -673,14 +673,15 @@
673673
674 def test_simple_loop(self):674 def test_simple_loop(self):
675 c = self.get_config('foo={foo}')675 c = self.get_config('foo={foo}')
676 self.assertRaises(errors.OptionExpansionLoop, c.expand_options, '{foo}')676 self.assertRaises(config.OptionExpansionLoop, c.expand_options,
677 '{foo}')
677678
678 def test_indirect_loop(self):679 def test_indirect_loop(self):
679 c = self.get_config('''680 c = self.get_config('''
680foo={bar}681foo={bar}
681bar={baz}682bar={baz}
682baz={foo}''')683baz={foo}''')
683 e = self.assertRaises(errors.OptionExpansionLoop,684 e = self.assertRaises(config.OptionExpansionLoop,
684 c.expand_options, '{foo}')685 c.expand_options, '{foo}')
685 self.assertEqual('foo->bar->baz', e.refs)686 self.assertEqual('foo->bar->baz', e.refs)
686 self.assertEqual('{foo}', e.string)687 self.assertEqual('{foo}', e.string)
@@ -739,7 +740,7 @@
739[/another/branch/path]740[/another/branch/path]
740bar = {foo}/2741bar = {foo}/2
741''')742''')
742 self.assertRaises(errors.ExpandingUnknownOption,743 self.assertRaises(config.ExpandingUnknownOption,
743 c.get_user_option, 'bar', expand=True)744 c.get_user_option, 'bar', expand=True)
744745
745 def test_cross_related_sections(self):746 def test_cross_related_sections(self):
@@ -1534,7 +1535,7 @@
1534 def test_extract_email_address(self):1535 def test_extract_email_address(self):
1535 self.assertEqual('jane@test.com',1536 self.assertEqual('jane@test.com',
1536 config.extract_email_address('Jane <jane@test.com>'))1537 config.extract_email_address('Jane <jane@test.com>'))
1537 self.assertRaises(errors.NoEmailInUsername,1538 self.assertRaises(config.NoEmailInUsername,
1538 config.extract_email_address, 'Jane Tester')1539 config.extract_email_address, 'Jane Tester')
15391540
1540 def test_parse_username(self):1541 def test_parse_username(self):
@@ -1595,14 +1596,14 @@
1595 t = self.get_transport()1596 t = self.get_transport()
1596 t.put_bytes('foo.conf', 'user=foo\n#\xff\n')1597 t.put_bytes('foo.conf', 'user=foo\n#\xff\n')
1597 conf = config.TransportConfig(t, 'foo.conf')1598 conf = config.TransportConfig(t, 'foo.conf')
1598 self.assertRaises(errors.ConfigContentError, conf._get_configobj)1599 self.assertRaises(config.ConfigContentError, conf._get_configobj)
15991600
1600 def test_load_erroneous_content(self):1601 def test_load_erroneous_content(self):
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."""
1602 t = self.get_transport()1603 t = self.get_transport()
1603 t.put_bytes('foo.conf', '[open_section\n')1604 t.put_bytes('foo.conf', '[open_section\n')
1604 conf = config.TransportConfig(t, 'foo.conf')1605 conf = config.TransportConfig(t, 'foo.conf')
1605 self.assertRaises(errors.ParseConfigError, conf._get_configobj)1606 self.assertRaises(config.ParseConfigError, conf._get_configobj)
16061607
1607 def test_load_permission_denied(self):1608 def test_load_permission_denied(self):
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."""
@@ -2012,7 +2013,7 @@
2012 warnings[0])2013 warnings[0])
20132014
2014 def assertCallsError(self, opt, value):2015 def assertCallsError(self, opt, value):
2015 self.assertRaises(errors.ConfigOptionValueError,2016 self.assertRaises(config.ConfigOptionValueError,
2016 opt.convert_from_unicode, None, value)2017 opt.convert_from_unicode, None, value)
20172018
2018 def assertConvertInvalid(self, opt, invalid_value):2019 def assertConvertInvalid(self, opt, invalid_value):
@@ -2179,9 +2180,9 @@
2179 self.assertEqual('A simple option', self.registry.get_help('foo'))2180 self.assertEqual('A simple option', self.registry.get_help('foo'))
21802181
2181 def test_dont_register_illegal_name(self):2182 def test_dont_register_illegal_name(self):
2182 self.assertRaises(errors.IllegalOptionName,2183 self.assertRaises(config.IllegalOptionName,
2183 self.registry.register, config.Option(' foo'))2184 self.registry.register, config.Option(' foo'))
2184 self.assertRaises(errors.IllegalOptionName,2185 self.assertRaises(config.IllegalOptionName,
2185 self.registry.register, config.Option('bar,'))2186 self.registry.register, config.Option('bar,'))
21862187
2187 lazy_option = config.Option('lazy_foo', help='Lazy help')2188 lazy_option = config.Option('lazy_foo', help='Lazy help')
@@ -2202,10 +2203,10 @@
2202 # the option name which indirectly requires that the option name is a2203 # the option name which indirectly requires that the option name is a
2203 # valid python identifier. We violate that rule here (using a key that2204 # valid python identifier. We violate that rule here (using a key that
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.
2205 self.assertRaises(errors.IllegalOptionName,2206 self.assertRaises(config.IllegalOptionName,
2206 self.registry.register_lazy, ' foo', self.__module__,2207 self.registry.register_lazy, ' foo', self.__module__,
2207 'TestOptionRegistry.lazy_option')2208 'TestOptionRegistry.lazy_option')
2208 self.assertRaises(errors.IllegalOptionName,2209 self.assertRaises(config.IllegalOptionName,
2209 self.registry.register_lazy, '1,2', self.__module__,2210 self.registry.register_lazy, '1,2', self.__module__,
2210 'TestOptionRegistry.lazy_option')2211 'TestOptionRegistry.lazy_option')
22112212
@@ -2519,14 +2520,14 @@
2519 t = self.get_transport()2520 t = self.get_transport()
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,))
2521 store = config.TransportIniFileStore(t, 'foo.conf')2522 store = config.TransportIniFileStore(t, 'foo.conf')
2522 self.assertRaises(errors.ConfigContentError, store.load)2523 self.assertRaises(config.ConfigContentError, store.load)
25232524
2524 def test_load_erroneous_content(self):2525 def test_load_erroneous_content(self):
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."""
2526 t = self.get_transport()2527 t = self.get_transport()
2527 t.put_bytes('foo.conf', '[open_section\n')2528 t.put_bytes('foo.conf', '[open_section\n')
2528 store = config.TransportIniFileStore(t, 'foo.conf')2529 store = config.TransportIniFileStore(t, 'foo.conf')
2529 self.assertRaises(errors.ParseConfigError, store.load)2530 self.assertRaises(config.ParseConfigError, store.load)
25302531
2531 def test_load_permission_denied(self):2532 def test_load_permission_denied(self):
2532 """Ensure we get warned when trying to load an inaccessible file."""2533 """Ensure we get warned when trying to load an inaccessible file."""
@@ -2576,14 +2577,14 @@
2576 with open('foo.conf', 'wb') as f:2577 with open('foo.conf', 'wb') as f:
2577 f.write('user=foo\n#%s\n' % (self.invalid_utf8_char,))2578 f.write('user=foo\n#%s\n' % (self.invalid_utf8_char,))
2578 conf = config.IniBasedConfig(file_name='foo.conf')2579 conf = config.IniBasedConfig(file_name='foo.conf')
2579 self.assertRaises(errors.ConfigContentError, conf._get_parser)2580 self.assertRaises(config.ConfigContentError, conf._get_parser)
25802581
2581 def test_load_erroneous_content(self):2582 def test_load_erroneous_content(self):
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."""
2583 with open('foo.conf', 'wb') as f:2584 with open('foo.conf', 'wb') as f:
2584 f.write('[open_section\n')2585 f.write('[open_section\n')
2585 conf = config.IniBasedConfig(file_name='foo.conf')2586 conf = config.IniBasedConfig(file_name='foo.conf')
2586 self.assertRaises(errors.ParseConfigError, conf._get_parser)2587 self.assertRaises(config.ParseConfigError, conf._get_parser)
25872588
25882589
2589class TestMutableStore(TestStore):2590class TestMutableStore(TestStore):
@@ -2868,7 +2869,7 @@
2868 store = config.TransportIniFileStore(self.get_transport(), 'foo.conf')2869 store = config.TransportIniFileStore(self.get_transport(), 'foo.conf')
2869 self.assertEqual(False, store.is_loaded())2870 self.assertEqual(False, store.is_loaded())
2870 exc = self.assertRaises(2871 exc = self.assertRaises(
2871 errors.ParseConfigError, store._load_from_string,2872 config.ParseConfigError, store._load_from_string,
2872 'this is invalid !')2873 'this is invalid !')
2873 self.assertEndsWith(exc.filename, 'foo.conf')2874 self.assertEndsWith(exc.filename, 'foo.conf')
2874 # And the load failed2875 # And the load failed
@@ -3668,7 +3669,7 @@
3668 self.assertExpansion('xxx', '{foo}')3669 self.assertExpansion('xxx', '{foo}')
36693670
3670 def test_unknown_ref(self):3671 def test_unknown_ref(self):
3671 self.assertRaises(errors.ExpandingUnknownOption,3672 self.assertRaises(config.ExpandingUnknownOption,
3672 self.conf.expand_options, '{foo}')3673 self.conf.expand_options, '{foo}')
36733674
3674 def test_illegal_def_is_ignored(self):3675 def test_illegal_def_is_ignored(self):
@@ -3692,7 +3693,7 @@
36923693
3693 def test_simple_loop(self):3694 def test_simple_loop(self):
3694 self.conf.store._load_from_string('foo={foo}')3695 self.conf.store._load_from_string('foo={foo}')
3695 self.assertRaises(errors.OptionExpansionLoop,3696 self.assertRaises(config.OptionExpansionLoop,
3696 self.conf.expand_options, '{foo}')3697 self.conf.expand_options, '{foo}')
36973698
3698 def test_indirect_loop(self):3699 def test_indirect_loop(self):
@@ -3700,7 +3701,7 @@
3700foo={bar}3701foo={bar}
3701bar={baz}3702bar={baz}
3702baz={foo}''')3703baz={foo}''')
3703 e = self.assertRaises(errors.OptionExpansionLoop,3704 e = self.assertRaises(config.OptionExpansionLoop,
3704 self.conf.expand_options, '{foo}')3705 self.conf.expand_options, '{foo}')
3705 self.assertEqual('foo->bar->baz', e.refs)3706 self.assertEqual('foo->bar->baz', e.refs)
3706 self.assertEqual('{foo}', e.string)3707 self.assertEqual('{foo}', e.string)
@@ -3771,7 +3772,7 @@
3771[/another/branch/path]3772[/another/branch/path]
3772bar = {foo}/23773bar = {foo}/2
3773''')3774''')
3774 self.assertRaises(errors.ExpandingUnknownOption,3775 self.assertRaises(config.ExpandingUnknownOption,
3775 c.get, 'bar', expand=True)3776 c.get, 'bar', expand=True)
37763777
3777 def test_cross_related_sections(self):3778 def test_cross_related_sections(self):
@@ -3859,7 +3860,7 @@
3859''')3860''')
3860 g_store.save()3861 g_store.save()
3861 stack = config.LocationStack('/home/user/project/branch')3862 stack = config.LocationStack('/home/user/project/branch')
3862 self.assertRaises(errors.ExpandingUnknownOption,3863 self.assertRaises(config.ExpandingUnknownOption,
3863 stack.get, 'gfoo', expand=True)3864 stack.get, 'gfoo', expand=True)
38643865
3865 def test_expand_local_option_locally(self):3866 def test_expand_local_option_locally(self):
@@ -4166,7 +4167,7 @@
41664167
4167 def test_non_utf8_config(self):4168 def test_non_utf8_config(self):
4168 conf = config.AuthenticationConfig(_file=BytesIO(b'foo = bar\xff'))4169 conf = config.AuthenticationConfig(_file=BytesIO(b'foo = bar\xff'))
4169 self.assertRaises(errors.ConfigContentError, conf._get_config)4170 self.assertRaises(config.ConfigContentError, conf._get_config)
41704171
4171 def test_missing_auth_section_header(self):4172 def test_missing_auth_section_header(self):
4172 conf = config.AuthenticationConfig(_file=BytesIO(b'foo = bar'))4173 conf = config.AuthenticationConfig(_file=BytesIO(b'foo = bar'))
@@ -4174,7 +4175,7 @@
41744175
4175 def test_auth_section_header_not_closed(self):4176 def test_auth_section_header_not_closed(self):
4176 conf = config.AuthenticationConfig(_file=BytesIO(b'[DEF'))4177 conf = config.AuthenticationConfig(_file=BytesIO(b'[DEF'))
4177 self.assertRaises(errors.ParseConfigError, conf._get_config)4178 self.assertRaises(config.ParseConfigError, conf._get_config)
41784179
4179 def test_auth_value_not_boolean(self):4180 def test_auth_value_not_boolean(self):
4180 conf = config.AuthenticationConfig(_file=BytesIO(b"""\4181 conf = config.AuthenticationConfig(_file=BytesIO(b"""\
@@ -4765,5 +4766,5 @@
47654766
4766 def test_unknown(self):4767 def test_unknown(self):
4767 conf = config.MemoryStack('mail_client=firebird')4768 conf = config.MemoryStack('mail_client=firebird')
4768 self.assertRaises(errors.ConfigOptionValueError, conf.get,4769 self.assertRaises(config.ConfigOptionValueError, conf.get,
4769 'mail_client')4770 'mail_client')

Subscribers

People subscribed via source and target branches