/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_config.py

(jelmer) Make sure that a branch user URL uniquely identifies that branch,
 and can be used to open it. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2010 Canonical Ltd
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
16
 
 
17
 
 
18
"""Black-box tests for bzr config."""
 
19
 
 
20
import os
 
21
 
 
22
from bzrlib import (
 
23
    config,
 
24
    errors,
 
25
    tests,
 
26
    )
 
27
from bzrlib.tests import (
 
28
    script,
 
29
    test_config as _t_config,
 
30
    )
 
31
 
 
32
class TestWithoutConfig(tests.TestCaseWithTransport):
 
33
 
 
34
    def test_config_all(self):
 
35
        out, err = self.run_bzr(['config'])
 
36
        self.assertEquals('', out)
 
37
        self.assertEquals('', err)
 
38
 
 
39
    def test_remove_unknown_option(self):
 
40
        self.run_bzr_error(['The "file" configuration option does not exist',],
 
41
                           ['config', '--remove', 'file'])
 
42
 
 
43
    def test_all_remove_exclusive(self):
 
44
        self.run_bzr_error(['--all and --remove are mutually exclusive.',],
 
45
                           ['config', '--remove', '--all'])
 
46
 
 
47
    def test_all_set_exclusive(self):
 
48
        self.run_bzr_error(['Only one option can be set.',],
 
49
                           ['config', '--all', 'hello=world'])
 
50
 
 
51
    def test_remove_no_option(self):
 
52
        self.run_bzr_error(['--remove expects an option to remove.',],
 
53
                           ['config', '--remove'])
 
54
 
 
55
    def test_unknown_option(self):
 
56
        self.run_bzr_error(['The "file" configuration option does not exist',],
 
57
                           ['config', 'file'])
 
58
 
 
59
    def test_unexpected_regexp(self):
 
60
        self.run_bzr_error(
 
61
            ['The "\*file" configuration option does not exist',],
 
62
            ['config', '*file'])
 
63
 
 
64
    def test_wrong_regexp(self):
 
65
        self.run_bzr_error(
 
66
            ['Invalid pattern\(s\) found. "\*file" nothing to repeat',],
 
67
            ['config', '--all', '*file'])
 
68
 
 
69
 
 
70
 
 
71
class TestConfigDisplay(tests.TestCaseWithTransport):
 
72
 
 
73
    def setUp(self):
 
74
        super(TestConfigDisplay, self).setUp()
 
75
        _t_config.create_configs(self)
 
76
 
 
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, '''\
 
81
            $ bzr config -d tree
 
82
            bazaar:
 
83
              multiline = """1
 
84
            2
 
85
            """
 
86
            ''')
 
87
 
 
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
 
93
            """1
 
94
            2
 
95
            """
 
96
            ''')
 
97
 
 
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, '''\
 
103
            $ bzr config -d tree
 
104
            bazaar:
 
105
              list = '1, a, "with, a comma"'
 
106
            ''')
 
107
 
 
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"'
 
115
            ''')
 
116
 
 
117
    def test_bazaar_config(self):
 
118
        self.bazaar_config.set_user_option('hello', 'world')
 
119
        script.run_script(self, '''\
 
120
            $ bzr config -d tree
 
121
            bazaar:
 
122
              hello = world
 
123
            ''')
 
124
 
 
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, '''\
 
129
            $ bzr config -d tree
 
130
            locations:
 
131
              [.../tree]
 
132
              hello = world
 
133
            branch:
 
134
              hello = you
 
135
            ''')
 
136
 
 
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, '''\
 
141
            $ bzr config
 
142
            bazaar:
 
143
              hello = world
 
144
            ''')
 
145
 
 
146
class TestConfigDisplayWithPolicy(tests.TestCaseWithTransport):
 
147
 
 
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')
 
151
        config_text = """\
 
152
[%(dir)s]
 
153
url = dir
 
154
url:policy = appendpath
 
155
[%(dir)s/tree]
 
156
url = tree
 
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
 
165
            locations:
 
166
              [.../work/tree]
 
167
              url = tree
 
168
              [.../work]
 
169
              url = dir
 
170
              url:policy = appendpath
 
171
            ''')
 
172
 
 
173
 
 
174
class TestConfigActive(tests.TestCaseWithTransport):
 
175
 
 
176
    def setUp(self):
 
177
        super(TestConfigActive, self).setUp()
 
178
        _t_config.create_configs_with_file_option(self)
 
179
 
 
180
    def test_active_in_locations(self):
 
181
        script.run_script(self, '''\
 
182
            $ bzr config -d tree file
 
183
            locations
 
184
            ''')
 
185
 
 
186
    def test_active_in_bazaar(self):
 
187
        script.run_script(self, '''\
 
188
            $ bzr config -d tree --scope bazaar file
 
189
            bazaar
 
190
            ''')
 
191
 
 
192
    def test_active_in_branch(self):
 
193
        # We need to delete the locations definition that overrides the branch
 
194
        # one
 
195
        script.run_script(self, '''\
 
196
            $ bzr config -d tree --scope locations --remove file
 
197
            $ bzr config -d tree file
 
198
            branch
 
199
            ''')
 
200
 
 
201
 
 
202
class TestConfigSetOption(tests.TestCaseWithTransport):
 
203
 
 
204
    def setUp(self):
 
205
        super(TestConfigSetOption, self).setUp()
 
206
        _t_config.create_configs(self)
 
207
 
 
208
    def test_unknown_config(self):
 
209
        self.run_bzr_error(['The "moon" configuration does not exist'],
 
210
                           ['config', '--scope', 'moon', 'hello=world'])
 
211
 
 
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
 
216
            bazaar:
 
217
              hello = world
 
218
            ''')
 
219
 
 
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
 
224
            bazaar:
 
225
              hello = world
 
226
            ''')
 
227
 
 
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
 
232
            locations:
 
233
              [.../work/tree]
 
234
              hello = world
 
235
            ''')
 
236
 
 
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
 
241
            branch:
 
242
              hello = world
 
243
            ''')
 
244
 
 
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
 
249
            branch:
 
250
              hello = world
 
251
            ''')
 
252
 
 
253
 
 
254
class TestConfigRemoveOption(tests.TestCaseWithTransport):
 
255
 
 
256
    def setUp(self):
 
257
        super(TestConfigRemoveOption, self).setUp()
 
258
        _t_config.create_configs_with_file_option(self)
 
259
 
 
260
    def test_unknown_config(self):
 
261
        self.run_bzr_error(['The "moon" configuration does not exist'],
 
262
                           ['config', '--scope', 'moon', '--remove', 'file'])
 
263
 
 
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
 
268
            locations:
 
269
              [.../work/tree]
 
270
              file = locations
 
271
            branch:
 
272
              file = branch
 
273
            ''')
 
274
 
 
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
 
279
            locations:
 
280
              [.../work/tree]
 
281
              file = locations
 
282
            branch:
 
283
              file = branch
 
284
            ''')
 
285
 
 
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
 
290
            branch:
 
291
              file = branch
 
292
            bazaar:
 
293
              file = bazaar
 
294
            ''')
 
295
 
 
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
 
300
            branch:
 
301
              file = branch
 
302
            bazaar:
 
303
              file = bazaar
 
304
            ''')
 
305
        script.run_script(self, '''\
 
306
            $ bzr config -d tree --remove file
 
307
            $ bzr config -d tree --all file
 
308
            bazaar:
 
309
              file = bazaar
 
310
            ''')
 
311
 
 
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
 
316
            locations:
 
317
              [.../work/tree]
 
318
              file = locations
 
319
            bazaar:
 
320
              file = bazaar
 
321
            ''')
 
322
        script.run_script(self, '''\
 
323
            $ bzr config -d tree --scope locations --remove file
 
324
            $ bzr config -d tree --all file
 
325
            bazaar:
 
326
              file = bazaar
 
327
            ''')