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,
29
class TestWithoutConfig(tests.TestCaseWithTransport):
31
def test_config_all(self):
32
out, err = self.run_bzr(['config'])
33
self.assertEquals('', out)
34
self.assertEquals('', err)
36
def test_remove_unknown_option(self):
37
self.run_bzr_error(['The "file" configuration option does not exist',],
38
['config', '--remove', 'file'])
40
def test_all_remove_exclusive(self):
41
self.run_bzr_error(['--all and --remove are mutually exclusive.',],
42
['config', '--remove', '--all'])
44
def test_all_set_exclusive(self):
45
self.run_bzr_error(['Only one option can be set.',],
46
['config', '--all', 'hello=world'])
48
def test_remove_no_option(self):
49
self.run_bzr_error(['--remove expects an option to remove.',],
50
['config', '--remove'])
52
def test_unknown_option(self):
53
self.run_bzr_error(['The "file" configuration option does not exist',],
56
def test_unexpected_regexp(self):
58
['The "\*file" configuration option does not exist',],
61
def test_wrong_regexp(self):
63
['Invalid pattern\(s\) found. "\*file" nothing to repeat',],
64
['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.bazaar_config.set_user_option('multiline', '1\n2\n')
76
# Fallout from bug 710410, the triple quotes have been toggled
77
script.run_script(self, '''\
85
def test_multiline_value_only(self):
86
self.bazaar_config.set_user_option('multiline', '1\n2\n')
87
# Fallout from bug 710410, the triple quotes have been toggled
88
script.run_script(self, '''\
89
$ bzr config -d tree multiline
95
def test_list_all_values(self):
96
# FIXME: we should register the option as a list or it's displayed as
97
# astring and as such, quoted.
98
self.bazaar_config.set_user_option('list', [1, 'a', 'with, a comma'])
99
script.run_script(self, '''\
102
list = '1, a, "with, a comma"'
105
def test_list_value_only(self):
106
# FIXME: we should register the option as a list or it's displayed as
107
# astring and as such, quoted.
108
self.bazaar_config.set_user_option('list', [1, 'a', 'with, a comma'])
109
script.run_script(self, '''\
110
$ bzr config -d tree list
111
'1, a, "with, a comma"'
114
def test_bazaar_config(self):
115
self.bazaar_config.set_user_option('hello', 'world')
116
script.run_script(self, '''\
122
def test_locations_config_for_branch(self):
123
self.locations_config.set_user_option('hello', 'world')
124
self.branch_config.set_user_option('hello', 'you')
125
script.run_script(self, '''\
134
def test_locations_config_outside_branch(self):
135
self.bazaar_config.set_user_option('hello', 'world')
136
self.locations_config.set_user_option('hello', 'world')
137
script.run_script(self, '''\
143
class TestConfigDisplayWithPolicy(tests.TestCaseWithTransport):
145
def test_location_with_policy(self):
146
# LocationConfig is the only one dealing with policies so far.
147
self.make_branch_and_tree('tree')
151
url:policy = appendpath
154
""" % {'dir': self.test_dir}
155
# We don't use the config directly so we save it to disk
156
config.LocationConfig.from_string(config_text, 'tree', save=True)
157
# policies are displayed with their options since they are part of
158
# their definition, likewise the path is not appended, we are just
159
# presenting the relevant portions of the config files
160
script.run_script(self, '''\
161
$ bzr config -d tree --all url
167
url:policy = appendpath
171
class TestConfigActive(tests.TestCaseWithTransport):
174
super(TestConfigActive, self).setUp()
175
_t_config.create_configs_with_file_option(self)
177
def test_active_in_locations(self):
178
script.run_script(self, '''\
179
$ bzr config -d tree file
183
def test_active_in_bazaar(self):
184
script.run_script(self, '''\
185
$ bzr config -d tree --scope bazaar file
189
def test_active_in_branch(self):
190
# We need to delete the locations definition that overrides the branch
192
script.run_script(self, '''\
193
$ bzr config -d tree --scope locations --remove file
194
$ bzr config -d tree file
199
class TestConfigSetOption(tests.TestCaseWithTransport):
202
super(TestConfigSetOption, self).setUp()
203
_t_config.create_configs(self)
205
def test_unknown_config(self):
206
self.run_bzr_error(['The "moon" configuration does not exist'],
207
['config', '--scope', 'moon', 'hello=world'])
209
def test_bazaar_config_outside_branch(self):
210
script.run_script(self, '''\
211
$ bzr config --scope bazaar hello=world
212
$ bzr config -d tree --all hello
217
def test_bazaar_config_inside_branch(self):
218
script.run_script(self, '''\
219
$ bzr config -d tree --scope bazaar hello=world
220
$ bzr config -d tree --all hello
225
def test_locations_config_inside_branch(self):
226
script.run_script(self, '''\
227
$ bzr config -d tree --scope locations hello=world
228
$ bzr config -d tree --all hello
234
def test_branch_config_default(self):
235
script.run_script(self, '''\
236
$ bzr config -d tree hello=world
237
$ bzr config -d tree --all hello
242
def test_branch_config_forcing_branch(self):
243
script.run_script(self, '''\
244
$ bzr config -d tree --scope branch hello=world
245
$ bzr config -d tree --all hello
251
class TestConfigRemoveOption(tests.TestCaseWithTransport):
254
super(TestConfigRemoveOption, self).setUp()
255
_t_config.create_configs_with_file_option(self)
257
def test_unknown_config(self):
258
self.run_bzr_error(['The "moon" configuration does not exist'],
259
['config', '--scope', 'moon', '--remove', 'file'])
261
def test_bazaar_config_outside_branch(self):
262
script.run_script(self, '''\
263
$ bzr config --scope bazaar --remove file
264
$ bzr config -d tree --all file
272
def test_bazaar_config_inside_branch(self):
273
script.run_script(self, '''\
274
$ bzr config -d tree --scope bazaar --remove file
275
$ bzr config -d tree --all file
283
def test_locations_config_inside_branch(self):
284
script.run_script(self, '''\
285
$ bzr config -d tree --scope locations --remove file
286
$ bzr config -d tree --all file
293
def test_branch_config_default(self):
294
script.run_script(self, '''\
295
$ bzr config -d tree --scope locations --remove file
296
$ bzr config -d tree --all file
302
script.run_script(self, '''\
303
$ bzr config -d tree --remove file
304
$ bzr config -d tree --all file
309
def test_branch_config_forcing_branch(self):
310
script.run_script(self, '''\
311
$ bzr config -d tree --scope branch --remove file
312
$ bzr config -d tree --all file
319
script.run_script(self, '''\
320
$ bzr config -d tree --scope locations --remove file
321
$ bzr config -d tree --all file
327
class TestSmartServerConfig(tests.TestCaseWithTransport):
329
def test_simple_branch_config(self):
330
self.setup_smart_server_with_call_log()
331
t = self.make_branch_and_tree('branch')
332
self.reset_smart_call_log()
333
out, err = self.run_bzr(['config', '-d', self.get_url('branch')])
334
# This figure represent the amount of work to perform this use case. It
335
# is entirely ok to reduce this number if a test fails due to rpc_count
336
# being too low. If rpc_count increases, more network roundtrips have
337
# become necessary for this use case. Please do not adjust this number
338
# upwards without agreement from bzr's network support maintainers.
339
self.assertLength(5, self.hpss_calls)