1
# Copyright (C) 2010, 2011, 2012, 2016 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
"""Black-box tests for brz config."""
26
test_config as _t_config,
30
class TestWithoutConfig(tests.TestCaseWithTransport):
32
def test_config_all(self):
33
out, err = self.run_bzr(['config'])
34
self.assertEqual('', out)
35
self.assertEqual('', err)
37
def test_remove_unknown_option(self):
38
self.run_bzr_error(['The "file" configuration option does not exist', ],
39
['config', '--remove', 'file'])
41
def test_all_remove_exclusive(self):
42
self.run_bzr_error(['--all and --remove are mutually exclusive.', ],
43
['config', '--remove', '--all'])
45
def test_all_set_exclusive(self):
46
self.run_bzr_error(['Only one option can be set.', ],
47
['config', '--all', 'hello=world'])
49
def test_remove_no_option(self):
50
self.run_bzr_error(['--remove expects an option to remove.', ],
51
['config', '--remove'])
53
def test_unknown_option(self):
54
self.run_bzr_error(['The "file" configuration option does not exist', ],
57
def test_unexpected_regexp(self):
59
['The "\\*file" configuration option does not exist', ],
62
def test_wrong_regexp(self):
64
['Invalid pattern\\(s\\) found. "\\*file" nothing to repeat', ],
65
['config', '--all', '*file'])
68
class TestConfigDisplay(tests.TestCaseWithTransport):
71
super(TestConfigDisplay, self).setUp()
72
_t_config.create_configs(self)
74
def test_multiline_all_values(self):
75
self.breezy_config.set_user_option('multiline', '1\n2\n')
76
# Fallout from bug 710410, the triple quotes have been toggled
77
script.run_script(self, '''\
86
def test_multiline_value_only(self):
87
self.breezy_config.set_user_option('multiline', '1\n2\n')
88
# Fallout from bug 710410, the triple quotes have been toggled
89
script.run_script(self, '''\
90
$ brz config -d tree multiline
96
def test_list_value_all(self):
97
config.option_registry.register(config.ListOption('list'))
98
self.addCleanup(config.option_registry.remove, 'list')
99
self.breezy_config.set_user_option('list', [1, 'a', 'with, a comma'])
100
script.run_script(self, '''\
104
list = 1, a, "with, a comma"
107
def test_list_value_one(self):
108
config.option_registry.register(config.ListOption('list'))
109
self.addCleanup(config.option_registry.remove, 'list')
110
self.breezy_config.set_user_option('list', [1, 'a', 'with, a comma'])
111
script.run_script(self, '''\
112
$ brz config -d tree list
113
1, a, "with, a comma"
116
def test_registry_value_all(self):
117
self.breezy_config.set_user_option('transform.orphan_policy',
119
script.run_script(self, '''\
123
transform.orphan_policy = move
126
def test_registry_value_one(self):
127
self.breezy_config.set_user_option('transform.orphan_policy',
129
script.run_script(self, '''\
130
$ brz config -d tree transform.orphan_policy
134
def test_breezy_config(self):
135
self.breezy_config.set_user_option('hello', 'world')
136
script.run_script(self, '''\
143
def test_locations_config_for_branch(self):
144
self.locations_config.set_user_option('hello', 'world')
145
self.branch_config.set_user_option('hello', 'you')
146
script.run_script(self, '''\
155
def test_locations_config_outside_branch(self):
156
self.breezy_config.set_user_option('hello', 'world')
157
self.locations_config.set_user_option('hello', 'world')
158
script.run_script(self, '''\
165
def test_cmd_line(self):
166
self.breezy_config.set_user_option('hello', 'world')
167
script.run_script(self, '''\
168
$ brz config -Ohello=bzr
177
class TestConfigDisplayWithPolicy(tests.TestCaseWithTransport):
179
def test_location_with_policy(self):
180
# LocationConfig is the only one dealing with policies so far.
181
self.make_branch_and_tree('tree')
185
url:policy = appendpath
188
""" % {'dir': self.test_dir}
189
# We don't use the config directly so we save it to disk
190
config.LocationConfig.from_string(config_text, 'tree', save=True)
191
# policies are displayed with their options since they are part of
192
# their definition, likewise the path is not appended, we are just
193
# presenting the relevant portions of the config files
194
script.run_script(self, '''\
195
$ brz config -d tree --all url
201
url:policy = appendpath
205
class TestConfigActive(tests.TestCaseWithTransport):
208
super(TestConfigActive, self).setUp()
209
_t_config.create_configs_with_file_option(self)
211
def test_active_in_locations(self):
212
script.run_script(self, '''\
213
$ brz config -d tree file
217
def test_active_in_breezy(self):
218
script.run_script(self, '''\
219
$ brz config -d tree --scope breezy file
223
def test_active_in_branch(self):
224
# We need to delete the locations definition that overrides the branch
226
script.run_script(self, '''\
227
$ brz config -d tree --scope locations --remove file
228
$ brz config -d tree file
233
class TestConfigSetOption(tests.TestCaseWithTransport):
236
super(TestConfigSetOption, self).setUp()
237
_t_config.create_configs(self)
239
def test_unknown_config(self):
240
self.run_bzr_error(['The "moon" configuration does not exist'],
241
['config', '--scope', 'moon', 'hello=world'])
243
def test_breezy_config_outside_branch(self):
244
script.run_script(self, '''\
245
$ brz config --scope breezy hello=world
246
$ brz config -d tree --all hello
252
def test_breezy_config_inside_branch(self):
253
script.run_script(self, '''\
254
$ brz config -d tree --scope breezy hello=world
255
$ brz config -d tree --all hello
261
def test_locations_config_inside_branch(self):
262
script.run_script(self, '''\
263
$ brz config -d tree --scope locations hello=world
264
$ brz config -d tree --all hello
270
def test_branch_config_default(self):
271
script.run_script(self, '''\
272
$ brz config -d tree hello=world
273
$ brz config -d tree --all hello
278
def test_branch_config_forcing_branch(self):
279
script.run_script(self, '''\
280
$ brz config -d tree --scope branch hello=world
281
$ brz config -d tree --all hello
287
class TestConfigRemoveOption(tests.TestCaseWithTransport):
290
super(TestConfigRemoveOption, self).setUp()
291
_t_config.create_configs_with_file_option(self)
293
def test_unknown_config(self):
294
self.run_bzr_error(['The "moon" configuration does not exist'],
295
['config', '--scope', 'moon', '--remove', 'file'])
297
def test_breezy_config_outside_branch(self):
298
script.run_script(self, '''\
299
$ brz config --scope breezy --remove file
300
$ brz config -d tree --all file
308
def test_breezy_config_inside_branch(self):
309
script.run_script(self, '''\
310
$ brz config -d tree --scope breezy --remove file
311
$ brz config -d tree --all file
319
def test_locations_config_inside_branch(self):
320
script.run_script(self, '''\
321
$ brz config -d tree --scope locations --remove file
322
$ brz config -d tree --all file
330
def test_branch_config_default(self):
331
script.run_script(self, '''\
332
$ brz config -d tree --scope locations --remove file
333
$ brz config -d tree --all file
340
script.run_script(self, '''\
341
$ brz config -d tree --remove file
342
$ brz config -d tree --all file
348
def test_branch_config_forcing_branch(self):
349
script.run_script(self, '''\
350
$ brz config -d tree --scope branch --remove file
351
$ brz config -d tree --all file
359
script.run_script(self, '''\
360
$ brz config -d tree --scope locations --remove file
361
$ brz config -d tree --all file
368
class TestConfigDirectory(tests.TestCaseWithTransport):
370
def test_parent_alias(self):
371
t = self.make_branch_and_tree('base')
372
t.branch.get_config_stack().set('test', 'base')
373
clone = t.branch.controldir.sprout('clone').open_branch()
374
clone.get_config_stack().set('test', 'clone')
375
out, err = self.run_bzr(['config', '-d', ':parent', 'test'],
377
self.assertEqual('base\n', out)