1
# Copyright (C) 2010 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 bzr config."""
24
from bzrlib.tests import (
26
test_config as _t_config,
28
from bzrlib.tests.matchers import ContainsNoVfsCalls
31
class TestWithoutConfig(tests.TestCaseWithTransport):
33
def test_config_all(self):
34
out, err = self.run_bzr(['config'])
35
self.assertEquals('', out)
36
self.assertEquals('', 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'])
70
class TestConfigDisplay(tests.TestCaseWithTransport):
73
super(TestConfigDisplay, self).setUp()
74
_t_config.create_configs(self)
76
def test_multiline_all_values(self):
77
self.bazaar_config.set_user_option('multiline', '1\n2\n')
78
# Fallout from bug 710410, the triple quotes have been toggled
79
script.run_script(self, '''\
88
def test_multiline_value_only(self):
89
self.bazaar_config.set_user_option('multiline', '1\n2\n')
90
# Fallout from bug 710410, the triple quotes have been toggled
91
script.run_script(self, '''\
92
$ bzr config -d tree multiline
98
def test_list_value_all(self):
99
config.option_registry.register(config.ListOption('list'))
100
self.addCleanup(config.option_registry.remove, 'list')
101
self.bazaar_config.set_user_option('list', [1, 'a', 'with, a comma'])
102
script.run_script(self, '''\
106
list = 1, a, "with, a comma"
109
def test_list_value_one(self):
110
config.option_registry.register(config.ListOption('list'))
111
self.addCleanup(config.option_registry.remove, 'list')
112
self.bazaar_config.set_user_option('list', [1, 'a', 'with, a comma'])
113
script.run_script(self, '''\
114
$ bzr config -d tree list
115
1, a, "with, a comma"
118
def test_registry_value_all(self):
119
self.bazaar_config.set_user_option('bzr.transform.orphan_policy',
121
script.run_script(self, '''\
125
bzr.transform.orphan_policy = move
128
def test_registry_value_one(self):
129
self.bazaar_config.set_user_option('bzr.transform.orphan_policy',
131
script.run_script(self, '''\
132
$ bzr config -d tree bzr.transform.orphan_policy
136
def test_bazaar_config(self):
137
self.bazaar_config.set_user_option('hello', 'world')
138
script.run_script(self, '''\
145
def test_locations_config_for_branch(self):
146
self.locations_config.set_user_option('hello', 'world')
147
self.branch_config.set_user_option('hello', 'you')
148
script.run_script(self, '''\
157
def test_locations_config_outside_branch(self):
158
self.bazaar_config.set_user_option('hello', 'world')
159
self.locations_config.set_user_option('hello', 'world')
160
script.run_script(self, '''\
167
def test_cmd_line(self):
168
self.bazaar_config.set_user_option('hello', 'world')
169
script.run_script(self, '''\
170
$ bzr config -Ohello=bzr
179
class TestConfigDisplayWithPolicy(tests.TestCaseWithTransport):
181
def test_location_with_policy(self):
182
# LocationConfig is the only one dealing with policies so far.
183
self.make_branch_and_tree('tree')
187
url:policy = appendpath
190
""" % {'dir': self.test_dir}
191
# We don't use the config directly so we save it to disk
192
config.LocationConfig.from_string(config_text, 'tree', save=True)
193
# policies are displayed with their options since they are part of
194
# their definition, likewise the path is not appended, we are just
195
# presenting the relevant portions of the config files
196
script.run_script(self, '''\
197
$ bzr config -d tree --all url
203
url:policy = appendpath
207
class TestConfigActive(tests.TestCaseWithTransport):
210
super(TestConfigActive, self).setUp()
211
_t_config.create_configs_with_file_option(self)
213
def test_active_in_locations(self):
214
script.run_script(self, '''\
215
$ bzr config -d tree file
219
def test_active_in_bazaar(self):
220
script.run_script(self, '''\
221
$ bzr config -d tree --scope bazaar file
225
def test_active_in_branch(self):
226
# We need to delete the locations definition that overrides the branch
228
script.run_script(self, '''\
229
$ bzr config -d tree --scope locations --remove file
230
$ bzr config -d tree file
235
class TestConfigSetOption(tests.TestCaseWithTransport):
238
super(TestConfigSetOption, self).setUp()
239
_t_config.create_configs(self)
241
def test_unknown_config(self):
242
self.run_bzr_error(['The "moon" configuration does not exist'],
243
['config', '--scope', 'moon', 'hello=world'])
245
def test_bazaar_config_outside_branch(self):
246
script.run_script(self, '''\
247
$ bzr config --scope bazaar hello=world
248
$ bzr config -d tree --all hello
254
def test_bazaar_config_inside_branch(self):
255
script.run_script(self, '''\
256
$ bzr config -d tree --scope bazaar hello=world
257
$ bzr config -d tree --all hello
263
def test_locations_config_inside_branch(self):
264
script.run_script(self, '''\
265
$ bzr config -d tree --scope locations hello=world
266
$ bzr config -d tree --all hello
272
def test_branch_config_default(self):
273
script.run_script(self, '''\
274
$ bzr config -d tree hello=world
275
$ bzr config -d tree --all hello
280
def test_branch_config_forcing_branch(self):
281
script.run_script(self, '''\
282
$ bzr config -d tree --scope branch hello=world
283
$ bzr config -d tree --all hello
289
class TestConfigRemoveOption(tests.TestCaseWithTransport):
292
super(TestConfigRemoveOption, self).setUp()
293
_t_config.create_configs_with_file_option(self)
295
def test_unknown_config(self):
296
self.run_bzr_error(['The "moon" configuration does not exist'],
297
['config', '--scope', 'moon', '--remove', 'file'])
299
def test_bazaar_config_outside_branch(self):
300
script.run_script(self, '''\
301
$ bzr config --scope bazaar --remove file
302
$ bzr config -d tree --all file
310
def test_bazaar_config_inside_branch(self):
311
script.run_script(self, '''\
312
$ bzr config -d tree --scope bazaar --remove file
313
$ bzr config -d tree --all file
321
def test_locations_config_inside_branch(self):
322
script.run_script(self, '''\
323
$ bzr config -d tree --scope locations --remove file
324
$ bzr config -d tree --all file
332
def test_branch_config_default(self):
333
script.run_script(self, '''\
334
$ bzr config -d tree --scope locations --remove file
335
$ bzr config -d tree --all file
342
script.run_script(self, '''\
343
$ bzr config -d tree --remove file
344
$ bzr config -d tree --all file
350
def test_branch_config_forcing_branch(self):
351
script.run_script(self, '''\
352
$ bzr config -d tree --scope branch --remove file
353
$ bzr config -d tree --all file
361
script.run_script(self, '''\
362
$ bzr config -d tree --scope locations --remove file
363
$ bzr config -d tree --all file
370
class TestSmartServerConfig(tests.TestCaseWithTransport):
372
def test_simple_branch_config(self):
373
self.setup_smart_server_with_call_log()
374
t = self.make_branch_and_tree('branch')
375
self.reset_smart_call_log()
376
out, err = self.run_bzr(['config', '-d', self.get_url('branch')])
377
# This figure represent the amount of work to perform this use case. It
378
# is entirely ok to reduce this number if a test fails due to rpc_count
379
# being too low. If rpc_count increases, more network roundtrips have
380
# become necessary for this use case. Please do not adjust this number
381
# upwards without agreement from bzr's network support maintainers.
382
self.assertLength(5, self.hpss_calls)
383
self.assertLength(1, self.hpss_connections)
384
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
387
class TestConfigDirectory(tests.TestCaseWithTransport):
389
def test_parent_alias(self):
390
t = self.make_branch_and_tree('base')
391
t.branch.get_config_stack().set('test', 'base')
392
clone = t.branch.bzrdir.sprout('clone').open_branch()
393
clone.get_config_stack().set('test', 'clone')
394
out, err = self.run_bzr(['config', '-d', ':parent', 'test'],
396
self.assertEquals('base\n', out)