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."""
27
from bzrlib.tests import (
29
test_config as _t_config,
32
class TestWithoutConfig(tests.TestCaseWithTransport):
34
def test_config_all(self):
35
out, err = self.run_bzr(['config'])
36
self.assertEquals('', out)
37
self.assertEquals('', err)
39
def test_remove_unknown_option(self):
40
self.run_bzr_error(['The "file" configuration option does not exist',],
41
['config', '--remove', 'file'])
43
def test_all_remove_exclusive(self):
44
self.run_bzr_error(['--all and --remove are mutually exclusive.',],
45
['config', '--remove', '--all'])
47
def test_all_set_exclusive(self):
48
self.run_bzr_error(['Only one option can be set.',],
49
['config', '--all', 'hello=world'])
51
def test_remove_no_option(self):
52
self.run_bzr_error(['--remove expects an option to remove.',],
53
['config', '--remove'])
55
def test_unknown_option(self):
56
self.run_bzr_error(['The "file" configuration option does not exist',],
59
def test_unexpected_regexp(self):
61
['The "\*file" configuration option does not exist',],
64
def test_wrong_regexp(self):
66
['Invalid pattern\(s\) found. "\*file" nothing to repeat',],
67
['config', '--all', '*file'])
71
class TestConfigDisplay(tests.TestCaseWithTransport):
74
super(TestConfigDisplay, self).setUp()
75
_t_config.create_configs(self)
77
def test_multiline_all_values(self):
78
self.bazaar_config.set_user_option('multiline', '1\n2\n')
79
# Fallout from bug 710410, the triple quotes have been toggled
80
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_all_values(self):
99
# FIXME: we should register the option as a list or it's displayed as
100
# astring and as such, quoted.
101
self.bazaar_config.set_user_option('list', [1, 'a', 'with, a comma'])
102
script.run_script(self, '''\
105
list = '1, a, "with, a comma"'
108
def test_list_value_only(self):
109
# FIXME: we should register the option as a list or it's displayed as
110
# astring and as such, quoted.
111
self.bazaar_config.set_user_option('list', [1, 'a', 'with, a comma'])
112
script.run_script(self, '''\
113
$ bzr config -d tree list
114
'1, a, "with, a comma"'
117
def test_bazaar_config(self):
118
self.bazaar_config.set_user_option('hello', 'world')
119
script.run_script(self, '''\
125
def test_locations_config_for_branch(self):
126
self.locations_config.set_user_option('hello', 'world')
127
self.branch_config.set_user_option('hello', 'you')
128
script.run_script(self, '''\
137
def test_locations_config_outside_branch(self):
138
self.bazaar_config.set_user_option('hello', 'world')
139
self.locations_config.set_user_option('hello', 'world')
140
script.run_script(self, '''\
146
class TestConfigDisplayWithPolicy(tests.TestCaseWithTransport):
148
def test_location_with_policy(self):
149
# LocationConfig is the only one dealing with policies so far.
150
self.make_branch_and_tree('tree')
154
url:policy = appendpath
157
""" % {'dir': self.test_dir}
158
# We don't use the config directly so we save it to disk
159
config.LocationConfig.from_string(config_text, 'tree', save=True)
160
# policies are displayed with their options since they are part of
161
# their definition, likewise the path is not appended, we are just
162
# presenting the relevant portions of the config files
163
script.run_script(self, '''\
164
$ bzr config -d tree --all url
170
url:policy = appendpath
174
class TestConfigActive(tests.TestCaseWithTransport):
177
super(TestConfigActive, self).setUp()
178
_t_config.create_configs_with_file_option(self)
180
def test_active_in_locations(self):
181
script.run_script(self, '''\
182
$ bzr config -d tree file
186
def test_active_in_bazaar(self):
187
script.run_script(self, '''\
188
$ bzr config -d tree --scope bazaar file
192
def test_active_in_branch(self):
193
# We need to delete the locations definition that overrides the branch
195
script.run_script(self, '''\
196
$ bzr config -d tree --scope locations --remove file
197
$ bzr config -d tree file
202
class TestConfigSetOption(tests.TestCaseWithTransport):
205
super(TestConfigSetOption, self).setUp()
206
_t_config.create_configs(self)
208
def test_unknown_config(self):
209
self.run_bzr_error(['The "moon" configuration does not exist'],
210
['config', '--scope', 'moon', 'hello=world'])
212
def test_bazaar_config_outside_branch(self):
213
script.run_script(self, '''\
214
$ bzr config --scope bazaar hello=world
215
$ bzr config -d tree --all hello
220
def test_bazaar_config_inside_branch(self):
221
script.run_script(self, '''\
222
$ bzr config -d tree --scope bazaar hello=world
223
$ bzr config -d tree --all hello
228
def test_locations_config_inside_branch(self):
229
script.run_script(self, '''\
230
$ bzr config -d tree --scope locations hello=world
231
$ bzr config -d tree --all hello
237
def test_branch_config_default(self):
238
script.run_script(self, '''\
239
$ bzr config -d tree hello=world
240
$ bzr config -d tree --all hello
245
def test_branch_config_forcing_branch(self):
246
script.run_script(self, '''\
247
$ bzr config -d tree --scope branch hello=world
248
$ bzr config -d tree --all hello
254
class TestConfigRemoveOption(tests.TestCaseWithTransport):
257
super(TestConfigRemoveOption, self).setUp()
258
_t_config.create_configs_with_file_option(self)
260
def test_unknown_config(self):
261
self.run_bzr_error(['The "moon" configuration does not exist'],
262
['config', '--scope', 'moon', '--remove', 'file'])
264
def test_bazaar_config_outside_branch(self):
265
script.run_script(self, '''\
266
$ bzr config --scope bazaar --remove file
267
$ bzr config -d tree --all file
275
def test_bazaar_config_inside_branch(self):
276
script.run_script(self, '''\
277
$ bzr config -d tree --scope bazaar --remove file
278
$ bzr config -d tree --all file
286
def test_locations_config_inside_branch(self):
287
script.run_script(self, '''\
288
$ bzr config -d tree --scope locations --remove file
289
$ bzr config -d tree --all file
296
def test_branch_config_default(self):
297
script.run_script(self, '''\
298
$ bzr config -d tree --scope locations --remove file
299
$ bzr config -d tree --all file
305
script.run_script(self, '''\
306
$ bzr config -d tree --remove file
307
$ bzr config -d tree --all file
312
def test_branch_config_forcing_branch(self):
313
script.run_script(self, '''\
314
$ bzr config -d tree --scope branch --remove file
315
$ bzr config -d tree --all file
322
script.run_script(self, '''\
323
$ bzr config -d tree --scope locations --remove file
324
$ bzr config -d tree --all file