/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

  • Committer: Patch Queue Manager
  • Date: 2011-12-30 15:51:59 UTC
  • mfrom: (6213.1.63 update-feature-flags)
  • Revision ID: pqm@pqm.ubuntu.com-20111230155159-qrgafyvytuitiq8u
(jelmer) Add {Repository, Branch, WorkingTree,
 BzrDir}.update_feature_flags methods. (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
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
              [DEFAULT]
 
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
        config.option_registry.register(config.ListOption('list'))
 
100
        self.addCleanup(config.option_registry.remove, 'list')
 
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
              [DEFAULT]
 
106
              list = 1, a, "with, a comma"
 
107
            ''')
 
108
 
 
109
    def test_list_value_only(self):
 
110
        config.option_registry.register(config.ListOption('list'))
 
111
        self.addCleanup(config.option_registry.remove, 'list')
 
112
        self.bazaar_config.set_user_option('list', [1, 'a', 'with, a comma'])
 
113
        script.run_script(self, '''\
 
114
            $ bzr config -d tree list
 
115
            1, a, "with, a comma"
 
116
            ''')
 
117
 
 
118
    def test_bazaar_config(self):
 
119
        self.bazaar_config.set_user_option('hello', 'world')
 
120
        script.run_script(self, '''\
 
121
            $ bzr config -d tree
 
122
            bazaar:
 
123
              [DEFAULT]
 
124
              hello = world
 
125
            ''')
 
126
 
 
127
    def test_locations_config_for_branch(self):
 
128
        self.locations_config.set_user_option('hello', 'world')
 
129
        self.branch_config.set_user_option('hello', 'you')
 
130
        script.run_script(self, '''\
 
131
            $ bzr config -d tree
 
132
            locations:
 
133
              [.../tree]
 
134
              hello = world
 
135
            branch:
 
136
              hello = you
 
137
            ''')
 
138
 
 
139
    def test_locations_config_outside_branch(self):
 
140
        self.bazaar_config.set_user_option('hello', 'world')
 
141
        self.locations_config.set_user_option('hello', 'world')
 
142
        script.run_script(self, '''\
 
143
            $ bzr config
 
144
            bazaar:
 
145
              [DEFAULT]
 
146
              hello = world
 
147
            ''')
 
148
 
 
149
 
 
150
class TestConfigDisplayWithPolicy(tests.TestCaseWithTransport):
 
151
 
 
152
    def test_location_with_policy(self):
 
153
        # LocationConfig is the only one dealing with policies so far.
 
154
        self.make_branch_and_tree('tree')
 
155
        config_text = """\
 
156
[%(dir)s]
 
157
url = dir
 
158
url:policy = appendpath
 
159
[%(dir)s/tree]
 
160
url = tree
 
161
""" % {'dir': self.test_dir}
 
162
        # We don't use the config directly so we save it to disk
 
163
        config.LocationConfig.from_string(config_text, 'tree', save=True)
 
164
        # policies are displayed with their options since they are part of
 
165
        # their definition, likewise the path is not appended, we are just
 
166
        # presenting the relevant portions of the config files
 
167
        script.run_script(self, '''\
 
168
            $ bzr config -d tree --all url
 
169
            locations:
 
170
              [.../work/tree]
 
171
              url = tree
 
172
              [.../work]
 
173
              url = dir
 
174
              url:policy = appendpath
 
175
            ''')
 
176
 
 
177
 
 
178
class TestConfigActive(tests.TestCaseWithTransport):
 
179
 
 
180
    def setUp(self):
 
181
        super(TestConfigActive, self).setUp()
 
182
        _t_config.create_configs_with_file_option(self)
 
183
 
 
184
    def test_active_in_locations(self):
 
185
        script.run_script(self, '''\
 
186
            $ bzr config -d tree file
 
187
            locations
 
188
            ''')
 
189
 
 
190
    def test_active_in_bazaar(self):
 
191
        script.run_script(self, '''\
 
192
            $ bzr config -d tree --scope bazaar file
 
193
            bazaar
 
194
            ''')
 
195
 
 
196
    def test_active_in_branch(self):
 
197
        # We need to delete the locations definition that overrides the branch
 
198
        # one
 
199
        script.run_script(self, '''\
 
200
            $ bzr config -d tree --scope locations --remove file
 
201
            $ bzr config -d tree file
 
202
            branch
 
203
            ''')
 
204
 
 
205
 
 
206
class TestConfigSetOption(tests.TestCaseWithTransport):
 
207
 
 
208
    def setUp(self):
 
209
        super(TestConfigSetOption, self).setUp()
 
210
        _t_config.create_configs(self)
 
211
 
 
212
    def test_unknown_config(self):
 
213
        self.run_bzr_error(['The "moon" configuration does not exist'],
 
214
                           ['config', '--scope', 'moon', 'hello=world'])
 
215
 
 
216
    def test_bazaar_config_outside_branch(self):
 
217
        script.run_script(self, '''\
 
218
            $ bzr config --scope bazaar hello=world
 
219
            $ bzr config -d tree --all hello
 
220
            bazaar:
 
221
              [DEFAULT]
 
222
              hello = world
 
223
            ''')
 
224
 
 
225
    def test_bazaar_config_inside_branch(self):
 
226
        script.run_script(self, '''\
 
227
            $ bzr config -d tree --scope bazaar hello=world
 
228
            $ bzr config -d tree --all hello
 
229
            bazaar:
 
230
              [DEFAULT]
 
231
              hello = world
 
232
            ''')
 
233
 
 
234
    def test_locations_config_inside_branch(self):
 
235
        script.run_script(self, '''\
 
236
            $ bzr config -d tree --scope locations hello=world
 
237
            $ bzr config -d tree --all hello
 
238
            locations:
 
239
              [.../work/tree]
 
240
              hello = world
 
241
            ''')
 
242
 
 
243
    def test_branch_config_default(self):
 
244
        script.run_script(self, '''\
 
245
            $ bzr config -d tree hello=world
 
246
            $ bzr config -d tree --all hello
 
247
            branch:
 
248
              hello = world
 
249
            ''')
 
250
 
 
251
    def test_branch_config_forcing_branch(self):
 
252
        script.run_script(self, '''\
 
253
            $ bzr config -d tree --scope branch hello=world
 
254
            $ bzr config -d tree --all hello
 
255
            branch:
 
256
              hello = world
 
257
            ''')
 
258
 
 
259
 
 
260
class TestConfigRemoveOption(tests.TestCaseWithTransport):
 
261
 
 
262
    def setUp(self):
 
263
        super(TestConfigRemoveOption, self).setUp()
 
264
        _t_config.create_configs_with_file_option(self)
 
265
 
 
266
    def test_unknown_config(self):
 
267
        self.run_bzr_error(['The "moon" configuration does not exist'],
 
268
                           ['config', '--scope', 'moon', '--remove', 'file'])
 
269
 
 
270
    def test_bazaar_config_outside_branch(self):
 
271
        script.run_script(self, '''\
 
272
            $ bzr config --scope bazaar --remove file
 
273
            $ bzr config -d tree --all file
 
274
            locations:
 
275
              [.../work/tree]
 
276
              file = locations
 
277
            branch:
 
278
              file = branch
 
279
            ''')
 
280
 
 
281
    def test_bazaar_config_inside_branch(self):
 
282
        script.run_script(self, '''\
 
283
            $ bzr config -d tree --scope bazaar --remove file
 
284
            $ bzr config -d tree --all file
 
285
            locations:
 
286
              [.../work/tree]
 
287
              file = locations
 
288
            branch:
 
289
              file = branch
 
290
            ''')
 
291
 
 
292
    def test_locations_config_inside_branch(self):
 
293
        script.run_script(self, '''\
 
294
            $ bzr config -d tree --scope locations --remove file
 
295
            $ bzr config -d tree --all file
 
296
            branch:
 
297
              file = branch
 
298
            bazaar:
 
299
              [DEFAULT]
 
300
              file = bazaar
 
301
            ''')
 
302
 
 
303
    def test_branch_config_default(self):
 
304
        script.run_script(self, '''\
 
305
            $ bzr config -d tree --scope locations --remove file
 
306
            $ bzr config -d tree --all file
 
307
            branch:
 
308
              file = branch
 
309
            bazaar:
 
310
              [DEFAULT]
 
311
              file = bazaar
 
312
            ''')
 
313
        script.run_script(self, '''\
 
314
            $ bzr config -d tree --remove file
 
315
            $ bzr config -d tree --all file
 
316
            bazaar:
 
317
              [DEFAULT]
 
318
              file = bazaar
 
319
            ''')
 
320
 
 
321
    def test_branch_config_forcing_branch(self):
 
322
        script.run_script(self, '''\
 
323
            $ bzr config -d tree --scope branch --remove file
 
324
            $ bzr config -d tree --all file
 
325
            locations:
 
326
              [.../work/tree]
 
327
              file = locations
 
328
            bazaar:
 
329
              [DEFAULT]
 
330
              file = bazaar
 
331
            ''')
 
332
        script.run_script(self, '''\
 
333
            $ bzr config -d tree --scope locations --remove file
 
334
            $ bzr config -d tree --all file
 
335
            bazaar:
 
336
              [DEFAULT]
 
337
              file = bazaar
 
338
            ''')
 
339
 
 
340
 
 
341
class TestSmartServerConfig(tests.TestCaseWithTransport):
 
342
 
 
343
    def test_simple_branch_config(self):
 
344
        self.setup_smart_server_with_call_log()
 
345
        t = self.make_branch_and_tree('branch')
 
346
        self.reset_smart_call_log()
 
347
        out, err = self.run_bzr(['config', '-d', self.get_url('branch')])
 
348
        # This figure represent the amount of work to perform this use case. It
 
349
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
350
        # being too low. If rpc_count increases, more network roundtrips have
 
351
        # become necessary for this use case. Please do not adjust this number
 
352
        # upwards without agreement from bzr's network support maintainers.
 
353
        self.assertLength(5, self.hpss_calls)
 
354
        self.assertLength(1, self.hpss_connections)
 
355
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)