~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Merge bzr.dev, update to use new hooks.

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
from bzrlib import (
 
21
    config,
 
22
    tests,
 
23
    )
 
24
from bzrlib.tests import (
 
25
    script,
 
26
    test_config as _t_config,
 
27
    )
 
28
from bzrlib.tests.matchers import ContainsNoVfsCalls
 
29
 
 
30
 
 
31
class TestWithoutConfig(tests.TestCaseWithTransport):
 
32
 
 
33
    def test_config_all(self):
 
34
        out, err = self.run_bzr(['config'])
 
35
        self.assertEquals('', out)
 
36
        self.assertEquals('', err)
 
37
 
 
38
    def test_remove_unknown_option(self):
 
39
        self.run_bzr_error(['The "file" configuration option does not exist',],
 
40
                           ['config', '--remove', 'file'])
 
41
 
 
42
    def test_all_remove_exclusive(self):
 
43
        self.run_bzr_error(['--all and --remove are mutually exclusive.',],
 
44
                           ['config', '--remove', '--all'])
 
45
 
 
46
    def test_all_set_exclusive(self):
 
47
        self.run_bzr_error(['Only one option can be set.',],
 
48
                           ['config', '--all', 'hello=world'])
 
49
 
 
50
    def test_remove_no_option(self):
 
51
        self.run_bzr_error(['--remove expects an option to remove.',],
 
52
                           ['config', '--remove'])
 
53
 
 
54
    def test_unknown_option(self):
 
55
        self.run_bzr_error(['The "file" configuration option does not exist',],
 
56
                           ['config', 'file'])
 
57
 
 
58
    def test_unexpected_regexp(self):
 
59
        self.run_bzr_error(
 
60
            ['The "\*file" configuration option does not exist',],
 
61
            ['config', '*file'])
 
62
 
 
63
    def test_wrong_regexp(self):
 
64
        self.run_bzr_error(
 
65
            ['Invalid pattern\(s\) found. "\*file" nothing to repeat',],
 
66
            ['config', '--all', '*file'])
 
67
 
 
68
 
 
69
 
 
70
class TestConfigDisplay(tests.TestCaseWithTransport):
 
71
 
 
72
    def setUp(self):
 
73
        super(TestConfigDisplay, self).setUp()
 
74
        _t_config.create_configs(self)
 
75
 
 
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, '''\
 
80
            $ bzr config -d tree
 
81
            bazaar:
 
82
              multiline = """1
 
83
            2
 
84
            """
 
85
            ''')
 
86
 
 
87
    def test_multiline_value_only(self):
 
88
        self.bazaar_config.set_user_option('multiline', '1\n2\n')
 
89
        # Fallout from bug 710410, the triple quotes have been toggled
 
90
        script.run_script(self, '''\
 
91
            $ bzr config -d tree multiline
 
92
            """1
 
93
            2
 
94
            """
 
95
            ''')
 
96
 
 
97
    def test_list_all_values(self):
 
98
        # FIXME: we should register the option as a list or it's displayed as
 
99
        # astring and as such, quoted.
 
100
        self.bazaar_config.set_user_option('list', [1, 'a', 'with, a comma'])
 
101
        script.run_script(self, '''\
 
102
            $ bzr config -d tree
 
103
            bazaar:
 
104
              list = '1, a, "with, a comma"'
 
105
            ''')
 
106
 
 
107
    def test_list_value_only(self):
 
108
        # FIXME: we should register the option as a list or it's displayed as
 
109
        # astring and as such, quoted.
 
110
        self.bazaar_config.set_user_option('list', [1, 'a', 'with, a comma'])
 
111
        script.run_script(self, '''\
 
112
            $ bzr config -d tree list
 
113
            '1, a, "with, a comma"'
 
114
            ''')
 
115
 
 
116
    def test_bazaar_config(self):
 
117
        self.bazaar_config.set_user_option('hello', 'world')
 
118
        script.run_script(self, '''\
 
119
            $ bzr config -d tree
 
120
            bazaar:
 
121
              hello = world
 
122
            ''')
 
123
 
 
124
    def test_locations_config_for_branch(self):
 
125
        self.locations_config.set_user_option('hello', 'world')
 
126
        self.branch_config.set_user_option('hello', 'you')
 
127
        script.run_script(self, '''\
 
128
            $ bzr config -d tree
 
129
            locations:
 
130
              [.../tree]
 
131
              hello = world
 
132
            branch:
 
133
              hello = you
 
134
            ''')
 
135
 
 
136
    def test_locations_config_outside_branch(self):
 
137
        self.bazaar_config.set_user_option('hello', 'world')
 
138
        self.locations_config.set_user_option('hello', 'world')
 
139
        script.run_script(self, '''\
 
140
            $ bzr config
 
141
            bazaar:
 
142
              hello = world
 
143
            ''')
 
144
 
 
145
class TestConfigDisplayWithPolicy(tests.TestCaseWithTransport):
 
146
 
 
147
    def test_location_with_policy(self):
 
148
        # LocationConfig is the only one dealing with policies so far.
 
149
        self.make_branch_and_tree('tree')
 
150
        config_text = """\
 
151
[%(dir)s]
 
152
url = dir
 
153
url:policy = appendpath
 
154
[%(dir)s/tree]
 
155
url = tree
 
156
""" % {'dir': self.test_dir}
 
157
        # We don't use the config directly so we save it to disk
 
158
        config.LocationConfig.from_string(config_text, 'tree', save=True)
 
159
        # policies are displayed with their options since they are part of
 
160
        # their definition, likewise the path is not appended, we are just
 
161
        # presenting the relevant portions of the config files
 
162
        script.run_script(self, '''\
 
163
            $ bzr config -d tree --all url
 
164
            locations:
 
165
              [.../work/tree]
 
166
              url = tree
 
167
              [.../work]
 
168
              url = dir
 
169
              url:policy = appendpath
 
170
            ''')
 
171
 
 
172
 
 
173
class TestConfigActive(tests.TestCaseWithTransport):
 
174
 
 
175
    def setUp(self):
 
176
        super(TestConfigActive, self).setUp()
 
177
        _t_config.create_configs_with_file_option(self)
 
178
 
 
179
    def test_active_in_locations(self):
 
180
        script.run_script(self, '''\
 
181
            $ bzr config -d tree file
 
182
            locations
 
183
            ''')
 
184
 
 
185
    def test_active_in_bazaar(self):
 
186
        script.run_script(self, '''\
 
187
            $ bzr config -d tree --scope bazaar file
 
188
            bazaar
 
189
            ''')
 
190
 
 
191
    def test_active_in_branch(self):
 
192
        # We need to delete the locations definition that overrides the branch
 
193
        # one
 
194
        script.run_script(self, '''\
 
195
            $ bzr config -d tree --scope locations --remove file
 
196
            $ bzr config -d tree file
 
197
            branch
 
198
            ''')
 
199
 
 
200
 
 
201
class TestConfigSetOption(tests.TestCaseWithTransport):
 
202
 
 
203
    def setUp(self):
 
204
        super(TestConfigSetOption, self).setUp()
 
205
        _t_config.create_configs(self)
 
206
 
 
207
    def test_unknown_config(self):
 
208
        self.run_bzr_error(['The "moon" configuration does not exist'],
 
209
                           ['config', '--scope', 'moon', 'hello=world'])
 
210
 
 
211
    def test_bazaar_config_outside_branch(self):
 
212
        script.run_script(self, '''\
 
213
            $ bzr config --scope bazaar hello=world
 
214
            $ bzr config -d tree --all hello
 
215
            bazaar:
 
216
              hello = world
 
217
            ''')
 
218
 
 
219
    def test_bazaar_config_inside_branch(self):
 
220
        script.run_script(self, '''\
 
221
            $ bzr config -d tree --scope bazaar hello=world
 
222
            $ bzr config -d tree --all hello
 
223
            bazaar:
 
224
              hello = world
 
225
            ''')
 
226
 
 
227
    def test_locations_config_inside_branch(self):
 
228
        script.run_script(self, '''\
 
229
            $ bzr config -d tree --scope locations hello=world
 
230
            $ bzr config -d tree --all hello
 
231
            locations:
 
232
              [.../work/tree]
 
233
              hello = world
 
234
            ''')
 
235
 
 
236
    def test_branch_config_default(self):
 
237
        script.run_script(self, '''\
 
238
            $ bzr config -d tree hello=world
 
239
            $ bzr config -d tree --all hello
 
240
            branch:
 
241
              hello = world
 
242
            ''')
 
243
 
 
244
    def test_branch_config_forcing_branch(self):
 
245
        script.run_script(self, '''\
 
246
            $ bzr config -d tree --scope branch hello=world
 
247
            $ bzr config -d tree --all hello
 
248
            branch:
 
249
              hello = world
 
250
            ''')
 
251
 
 
252
 
 
253
class TestConfigRemoveOption(tests.TestCaseWithTransport):
 
254
 
 
255
    def setUp(self):
 
256
        super(TestConfigRemoveOption, self).setUp()
 
257
        _t_config.create_configs_with_file_option(self)
 
258
 
 
259
    def test_unknown_config(self):
 
260
        self.run_bzr_error(['The "moon" configuration does not exist'],
 
261
                           ['config', '--scope', 'moon', '--remove', 'file'])
 
262
 
 
263
    def test_bazaar_config_outside_branch(self):
 
264
        script.run_script(self, '''\
 
265
            $ bzr config --scope bazaar --remove file
 
266
            $ bzr config -d tree --all file
 
267
            locations:
 
268
              [.../work/tree]
 
269
              file = locations
 
270
            branch:
 
271
              file = branch
 
272
            ''')
 
273
 
 
274
    def test_bazaar_config_inside_branch(self):
 
275
        script.run_script(self, '''\
 
276
            $ bzr config -d tree --scope bazaar --remove file
 
277
            $ bzr config -d tree --all file
 
278
            locations:
 
279
              [.../work/tree]
 
280
              file = locations
 
281
            branch:
 
282
              file = branch
 
283
            ''')
 
284
 
 
285
    def test_locations_config_inside_branch(self):
 
286
        script.run_script(self, '''\
 
287
            $ bzr config -d tree --scope locations --remove file
 
288
            $ bzr config -d tree --all file
 
289
            branch:
 
290
              file = branch
 
291
            bazaar:
 
292
              file = bazaar
 
293
            ''')
 
294
 
 
295
    def test_branch_config_default(self):
 
296
        script.run_script(self, '''\
 
297
            $ bzr config -d tree --scope locations --remove file
 
298
            $ bzr config -d tree --all file
 
299
            branch:
 
300
              file = branch
 
301
            bazaar:
 
302
              file = bazaar
 
303
            ''')
 
304
        script.run_script(self, '''\
 
305
            $ bzr config -d tree --remove file
 
306
            $ bzr config -d tree --all file
 
307
            bazaar:
 
308
              file = bazaar
 
309
            ''')
 
310
 
 
311
    def test_branch_config_forcing_branch(self):
 
312
        script.run_script(self, '''\
 
313
            $ bzr config -d tree --scope branch --remove file
 
314
            $ bzr config -d tree --all file
 
315
            locations:
 
316
              [.../work/tree]
 
317
              file = locations
 
318
            bazaar:
 
319
              file = bazaar
 
320
            ''')
 
321
        script.run_script(self, '''\
 
322
            $ bzr config -d tree --scope locations --remove file
 
323
            $ bzr config -d tree --all file
 
324
            bazaar:
 
325
              file = bazaar
 
326
            ''')
 
327
 
 
328
 
 
329
class TestSmartServerConfig(tests.TestCaseWithTransport):
 
330
 
 
331
    def test_simple_branch_config(self):
 
332
        self.setup_smart_server_with_call_log()
 
333
        t = self.make_branch_and_tree('branch')
 
334
        self.reset_smart_call_log()
 
335
        out, err = self.run_bzr(['config', '-d', self.get_url('branch')])
 
336
        # This figure represent the amount of work to perform this use case. It
 
337
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
338
        # being too low. If rpc_count increases, more network roundtrips have
 
339
        # become necessary for this use case. Please do not adjust this number
 
340
        # upwards without agreement from bzr's network support maintainers.
 
341
        self.assertLength(5, self.hpss_calls)
 
342
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)