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,
28
from ..matchers import ContainsNoVfsCalls
31
class TestWithoutConfig(tests.TestCaseWithTransport):
33
def test_config_all(self):
34
out, err = self.run_bzr(['config'])
35
self.assertEqual('', out)
36
self.assertEqual('', err)
38
def test_remove_unknown_option(self):
39
self.run_bzr_error(['The "file" configuration option does not exist', ],
40
['config', '--remove', 'file'])
42
def test_all_remove_exclusive(self):
43
self.run_bzr_error(['--all and --remove are mutually exclusive.', ],
44
['config', '--remove', '--all'])
46
def test_all_set_exclusive(self):
47
self.run_bzr_error(['Only one option can be set.', ],
48
['config', '--all', 'hello=world'])
50
def test_remove_no_option(self):
51
self.run_bzr_error(['--remove expects an option to remove.', ],
52
['config', '--remove'])
54
def test_unknown_option(self):
55
self.run_bzr_error(['The "file" configuration option does not exist', ],
58
def test_unexpected_regexp(self):
60
['The "\\*file" configuration option does not exist', ],
63
def test_wrong_regexp(self):
65
['Invalid pattern\\(s\\) found. "\\*file" nothing to repeat', ],
66
['config', '--all', '*file'])
69
class TestConfigDisplay(tests.TestCaseWithTransport):
72
super(TestConfigDisplay, self).setUp()
73
_t_config.create_configs(self)
75
def test_multiline_all_values(self):
76
self.breezy_config.set_user_option('multiline', '1\n2\n')
77
# Fallout from bug 710410, the triple quotes have been toggled
78
script.run_script(self, '''\
87
def test_multiline_value_only(self):
88
self.breezy_config.set_user_option('multiline', '1\n2\n')
89
# Fallout from bug 710410, the triple quotes have been toggled
90
script.run_script(self, '''\
91
$ brz config -d tree multiline
97
def test_list_value_all(self):
98
config.option_registry.register(config.ListOption('list'))
99
self.addCleanup(config.option_registry.remove, 'list')
100
self.breezy_config.set_user_option('list', [1, 'a', 'with, a comma'])
101
script.run_script(self, '''\
105
list = 1, a, "with, a comma"
108
def test_list_value_one(self):
109
config.option_registry.register(config.ListOption('list'))
110
self.addCleanup(config.option_registry.remove, 'list')
111
self.breezy_config.set_user_option('list', [1, 'a', 'with, a comma'])
112
script.run_script(self, '''\
113
$ brz config -d tree list
114
1, a, "with, a comma"
117
def test_registry_value_all(self):
118
self.breezy_config.set_user_option('transform.orphan_policy',
120
script.run_script(self, '''\
124
transform.orphan_policy = move
127
def test_registry_value_one(self):
128
self.breezy_config.set_user_option('transform.orphan_policy',
130
script.run_script(self, '''\
131
$ brz config -d tree transform.orphan_policy
135
def test_breezy_config(self):
136
self.breezy_config.set_user_option('hello', 'world')
137
script.run_script(self, '''\
144
def test_locations_config_for_branch(self):
145
self.locations_config.set_user_option('hello', 'world')
146
self.branch_config.set_user_option('hello', 'you')
147
script.run_script(self, '''\
156
def test_locations_config_outside_branch(self):
157
self.breezy_config.set_user_option('hello', 'world')
158
self.locations_config.set_user_option('hello', 'world')
159
script.run_script(self, '''\
166
def test_cmd_line(self):
167
self.breezy_config.set_user_option('hello', 'world')
168
script.run_script(self, '''\
169
$ brz config -Ohello=bzr
178
class TestConfigDisplayWithPolicy(tests.TestCaseWithTransport):
180
def test_location_with_policy(self):
181
# LocationConfig is the only one dealing with policies so far.
182
self.make_branch_and_tree('tree')
186
url:policy = appendpath
189
""" % {'dir': self.test_dir}
190
# We don't use the config directly so we save it to disk
191
config.LocationConfig.from_string(config_text, 'tree', save=True)
192
# policies are displayed with their options since they are part of
193
# their definition, likewise the path is not appended, we are just
194
# presenting the relevant portions of the config files
195
script.run_script(self, '''\
196
$ brz config -d tree --all url
202
url:policy = appendpath
206
class TestConfigActive(tests.TestCaseWithTransport):
209
super(TestConfigActive, self).setUp()
210
_t_config.create_configs_with_file_option(self)
212
def test_active_in_locations(self):
213
script.run_script(self, '''\
214
$ brz config -d tree file
218
def test_active_in_breezy(self):
219
script.run_script(self, '''\
220
$ brz config -d tree --scope breezy file
224
def test_active_in_branch(self):
225
# We need to delete the locations definition that overrides the branch
227
script.run_script(self, '''\
228
$ brz config -d tree --scope locations --remove file
229
$ brz config -d tree file
234
class TestConfigSetOption(tests.TestCaseWithTransport):
237
super(TestConfigSetOption, self).setUp()
238
_t_config.create_configs(self)
240
def test_unknown_config(self):
241
self.run_bzr_error(['The "moon" configuration does not exist'],
242
['config', '--scope', 'moon', 'hello=world'])
244
def test_breezy_config_outside_branch(self):
245
script.run_script(self, '''\
246
$ brz config --scope breezy hello=world
247
$ brz config -d tree --all hello
253
def test_breezy_config_inside_branch(self):
254
script.run_script(self, '''\
255
$ brz config -d tree --scope breezy hello=world
256
$ brz config -d tree --all hello
262
def test_locations_config_inside_branch(self):
263
script.run_script(self, '''\
264
$ brz config -d tree --scope locations hello=world
265
$ brz config -d tree --all hello
271
def test_branch_config_default(self):
272
script.run_script(self, '''\
273
$ brz config -d tree hello=world
274
$ brz config -d tree --all hello
279
def test_branch_config_forcing_branch(self):
280
script.run_script(self, '''\
281
$ brz config -d tree --scope branch hello=world
282
$ brz config -d tree --all hello
288
class TestConfigRemoveOption(tests.TestCaseWithTransport):
291
super(TestConfigRemoveOption, self).setUp()
292
_t_config.create_configs_with_file_option(self)
294
def test_unknown_config(self):
295
self.run_bzr_error(['The "moon" configuration does not exist'],
296
['config', '--scope', 'moon', '--remove', 'file'])
298
def test_breezy_config_outside_branch(self):
299
script.run_script(self, '''\
300
$ brz config --scope breezy --remove file
301
$ brz config -d tree --all file
309
def test_breezy_config_inside_branch(self):
310
script.run_script(self, '''\
311
$ brz config -d tree --scope breezy --remove file
312
$ brz config -d tree --all file
320
def test_locations_config_inside_branch(self):
321
script.run_script(self, '''\
322
$ brz config -d tree --scope locations --remove file
323
$ brz config -d tree --all file
331
def test_branch_config_default(self):
332
script.run_script(self, '''\
333
$ brz config -d tree --scope locations --remove file
334
$ brz config -d tree --all file
341
script.run_script(self, '''\
342
$ brz config -d tree --remove file
343
$ brz config -d tree --all file
349
def test_branch_config_forcing_branch(self):
350
script.run_script(self, '''\
351
$ brz config -d tree --scope branch --remove file
352
$ brz config -d tree --all file
360
script.run_script(self, '''\
361
$ brz config -d tree --scope locations --remove file
362
$ brz config -d tree --all file
369
class TestSmartServerConfig(tests.TestCaseWithTransport):
371
def test_simple_branch_config(self):
372
self.setup_smart_server_with_call_log()
373
t = self.make_branch_and_tree('branch')
374
self.reset_smart_call_log()
375
out, err = self.run_bzr(['config', '-d', self.get_url('branch')])
376
# This figure represent the amount of work to perform this use case. It
377
# is entirely ok to reduce this number if a test fails due to rpc_count
378
# being too low. If rpc_count increases, more network roundtrips have
379
# become necessary for this use case. Please do not adjust this number
380
# upwards without agreement from bzr's network support maintainers.
381
self.assertLength(5, self.hpss_calls)
382
self.assertLength(1, self.hpss_connections)
383
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
386
class TestConfigDirectory(tests.TestCaseWithTransport):
388
def test_parent_alias(self):
389
t = self.make_branch_and_tree('base')
390
t.branch.get_config_stack().set('test', 'base')
391
clone = t.branch.controldir.sprout('clone').open_branch()
392
clone.get_config_stack().set('test', 'clone')
393
out, err = self.run_bzr(['config', '-d', ':parent', 'test'],
395
self.assertEqual('base\n', out)