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
self.bazaar_config.set_user_option('list', [1, 'a', 'with, a comma'])
100
script.run_script(self, '''\
103
list = 1, a, "with, a comma"
106
def test_list_value_only(self):
107
self.bazaar_config.set_user_option('list', [1, 'a', 'with, a comma'])
108
script.run_script(self, '''\
109
$ bzr config -d tree list
110
1, a, "with, a comma"
113
def test_bazaar_config(self):
114
self.bazaar_config.set_user_option('hello', 'world')
115
script.run_script(self, '''\
121
def test_locations_config_for_branch(self):
122
self.locations_config.set_user_option('hello', 'world')
123
self.branch_config.set_user_option('hello', 'you')
124
script.run_script(self, '''\
133
def test_locations_config_outside_branch(self):
134
self.bazaar_config.set_user_option('hello', 'world')
135
self.locations_config.set_user_option('hello', 'world')
136
script.run_script(self, '''\
142
class TestConfigDisplayWithPolicy(tests.TestCaseWithTransport):
144
def test_location_with_policy(self):
145
# LocationConfig is the only one dealing with policies so far.
146
self.make_branch_and_tree('tree')
150
url:policy = appendpath
153
""" % {'dir': self.test_dir}
154
# We don't use the config directly so we save it to disk
155
config.LocationConfig.from_string(config_text, 'tree', save=True)
156
# policies are displayed with their options since they are part of
157
# their definition, likewise the path is not appended, we are just
158
# presenting the relevant portions of the config files
159
script.run_script(self, '''\
160
$ bzr config -d tree --all url
166
url:policy = appendpath
170
class TestConfigActive(tests.TestCaseWithTransport):
173
super(TestConfigActive, self).setUp()
174
_t_config.create_configs_with_file_option(self)
176
def test_active_in_locations(self):
177
script.run_script(self, '''\
178
$ bzr config -d tree file
182
def test_active_in_bazaar(self):
183
script.run_script(self, '''\
184
$ bzr config -d tree --scope bazaar file
188
def test_active_in_branch(self):
189
# We need to delete the locations definition that overrides the branch
191
script.run_script(self, '''\
192
$ bzr config -d tree --remove file
193
$ bzr config -d tree file
198
class TestConfigSetOption(tests.TestCaseWithTransport):
201
super(TestConfigSetOption, self).setUp()
202
_t_config.create_configs(self)
204
def test_unknown_config(self):
205
self.run_bzr_error(['The "moon" configuration does not exist'],
206
['config', '--scope', 'moon', 'hello=world'])
208
def test_bazaar_config_outside_branch(self):
209
script.run_script(self, '''\
210
$ bzr config --scope bazaar hello=world
211
$ bzr config -d tree --all hello
216
def test_bazaar_config_inside_branch(self):
217
script.run_script(self, '''\
218
$ bzr config -d tree --scope bazaar hello=world
219
$ bzr config -d tree --all hello
224
def test_locations_config_inside_branch(self):
225
script.run_script(self, '''\
226
$ bzr config -d tree --scope locations hello=world
227
$ bzr config -d tree --all hello
233
def test_branch_config_default(self):
234
script.run_script(self, '''\
235
$ bzr config -d tree hello=world
236
$ bzr config -d tree --all hello
241
def test_branch_config_forcing_branch(self):
242
script.run_script(self, '''\
243
$ bzr config -d tree --scope branch hello=world
244
$ bzr config -d tree --all hello
250
class TestConfigRemoveOption(tests.TestCaseWithTransport):
253
super(TestConfigRemoveOption, self).setUp()
254
_t_config.create_configs_with_file_option(self)
256
def test_unknown_config(self):
257
self.run_bzr_error(['The "moon" configuration does not exist'],
258
['config', '--scope', 'moon', '--remove', 'file'])
260
def test_bazaar_config_outside_branch(self):
261
script.run_script(self, '''\
262
$ bzr config --scope bazaar --remove file
263
$ bzr config -d tree --all file
271
def test_bazaar_config_inside_branch(self):
272
script.run_script(self, '''\
273
$ bzr config -d tree --scope bazaar --remove file
274
$ bzr config -d tree --all file
282
def test_locations_config_inside_branch(self):
283
script.run_script(self, '''\
284
$ bzr config -d tree --scope locations --remove file
285
$ bzr config -d tree --all file
292
def test_branch_config_default(self):
293
script.run_script(self, '''\
294
$ bzr config -d tree --remove file
295
$ bzr config -d tree --all file
301
script.run_script(self, '''\
302
$ bzr config -d tree --remove file
303
$ bzr config -d tree --all file
308
def test_branch_config_forcing_branch(self):
309
script.run_script(self, '''\
310
$ bzr config -d tree --scope branch --remove file
311
$ bzr config -d tree --all file
318
script.run_script(self, '''\
319
$ bzr config -d tree --remove file
320
$ bzr config -d tree --all file