~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2012-01-18 14:09:19 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120118140919-rlvdrhpc0nq1lbwi
Change set/remove to require a lock for the branch config files.

This means that tests (or any plugin for that matter) do not requires an
explicit lock on the branch anymore to change a single option. This also
means the optimisation becomes "opt-in" and as such won't be as
spectacular as it may be and/or harder to get right (nothing fails
anymore).

This reduces the diff by ~300 lines.

Code/tests that were updating more than one config option is still taking
a lock to at least avoid some IOs and demonstrate the benefits through
the decreased number of hpss calls.

The duplication between BranchStack and BranchOnlyStack will be removed
once the same sharing is in place for local config files, at which point
the Stack class itself may be able to host the changes.

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
    def test_cmd_line(self):
 
150
        self.bazaar_config.set_user_option('hello', 'world')
 
151
        script.run_script(self, '''\
 
152
            $ bzr config -Ohello=bzr
 
153
            cmdline:
 
154
              hello = bzr
 
155
            bazaar:
 
156
              [DEFAULT]
 
157
              hello = world
 
158
            ''')
 
159
 
 
160
 
 
161
class TestConfigDisplayWithPolicy(tests.TestCaseWithTransport):
 
162
 
 
163
    def test_location_with_policy(self):
 
164
        # LocationConfig is the only one dealing with policies so far.
 
165
        self.make_branch_and_tree('tree')
 
166
        config_text = """\
 
167
[%(dir)s]
 
168
url = dir
 
169
url:policy = appendpath
 
170
[%(dir)s/tree]
 
171
url = tree
 
172
""" % {'dir': self.test_dir}
 
173
        # We don't use the config directly so we save it to disk
 
174
        config.LocationConfig.from_string(config_text, 'tree', save=True)
 
175
        # policies are displayed with their options since they are part of
 
176
        # their definition, likewise the path is not appended, we are just
 
177
        # presenting the relevant portions of the config files
 
178
        script.run_script(self, '''\
 
179
            $ bzr config -d tree --all url
 
180
            locations:
 
181
              [.../work/tree]
 
182
              url = tree
 
183
              [.../work]
 
184
              url = dir
 
185
              url:policy = appendpath
 
186
            ''')
 
187
 
 
188
 
 
189
class TestConfigActive(tests.TestCaseWithTransport):
 
190
 
 
191
    def setUp(self):
 
192
        super(TestConfigActive, self).setUp()
 
193
        _t_config.create_configs_with_file_option(self)
 
194
 
 
195
    def test_active_in_locations(self):
 
196
        script.run_script(self, '''\
 
197
            $ bzr config -d tree file
 
198
            locations
 
199
            ''')
 
200
 
 
201
    def test_active_in_bazaar(self):
 
202
        script.run_script(self, '''\
 
203
            $ bzr config -d tree --scope bazaar file
 
204
            bazaar
 
205
            ''')
 
206
 
 
207
    def test_active_in_branch(self):
 
208
        # We need to delete the locations definition that overrides the branch
 
209
        # one
 
210
        script.run_script(self, '''\
 
211
            $ bzr config -d tree --scope locations --remove file
 
212
            $ bzr config -d tree file
 
213
            branch
 
214
            ''')
 
215
 
 
216
 
 
217
class TestConfigSetOption(tests.TestCaseWithTransport):
 
218
 
 
219
    def setUp(self):
 
220
        super(TestConfigSetOption, self).setUp()
 
221
        _t_config.create_configs(self)
 
222
 
 
223
    def test_unknown_config(self):
 
224
        self.run_bzr_error(['The "moon" configuration does not exist'],
 
225
                           ['config', '--scope', 'moon', 'hello=world'])
 
226
 
 
227
    def test_bazaar_config_outside_branch(self):
 
228
        script.run_script(self, '''\
 
229
            $ bzr config --scope bazaar hello=world
 
230
            $ bzr config -d tree --all hello
 
231
            bazaar:
 
232
              [DEFAULT]
 
233
              hello = world
 
234
            ''')
 
235
 
 
236
    def test_bazaar_config_inside_branch(self):
 
237
        script.run_script(self, '''\
 
238
            $ bzr config -d tree --scope bazaar hello=world
 
239
            $ bzr config -d tree --all hello
 
240
            bazaar:
 
241
              [DEFAULT]
 
242
              hello = world
 
243
            ''')
 
244
 
 
245
    def test_locations_config_inside_branch(self):
 
246
        script.run_script(self, '''\
 
247
            $ bzr config -d tree --scope locations hello=world
 
248
            $ bzr config -d tree --all hello
 
249
            locations:
 
250
              [.../work/tree]
 
251
              hello = world
 
252
            ''')
 
253
 
 
254
    def test_branch_config_default(self):
 
255
        script.run_script(self, '''\
 
256
            $ bzr config -d tree hello=world
 
257
            $ bzr config -d tree --all hello
 
258
            branch:
 
259
              hello = world
 
260
            ''')
 
261
 
 
262
    def test_branch_config_forcing_branch(self):
 
263
        script.run_script(self, '''\
 
264
            $ bzr config -d tree --scope branch hello=world
 
265
            $ bzr config -d tree --all hello
 
266
            branch:
 
267
              hello = world
 
268
            ''')
 
269
 
 
270
 
 
271
class TestConfigRemoveOption(tests.TestCaseWithTransport):
 
272
 
 
273
    def setUp(self):
 
274
        super(TestConfigRemoveOption, self).setUp()
 
275
        _t_config.create_configs_with_file_option(self)
 
276
 
 
277
    def test_unknown_config(self):
 
278
        self.run_bzr_error(['The "moon" configuration does not exist'],
 
279
                           ['config', '--scope', 'moon', '--remove', 'file'])
 
280
 
 
281
    def test_bazaar_config_outside_branch(self):
 
282
        script.run_script(self, '''\
 
283
            $ bzr config --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_bazaar_config_inside_branch(self):
 
293
        script.run_script(self, '''\
 
294
            $ bzr config -d tree --scope bazaar --remove file
 
295
            $ bzr config -d tree --all file
 
296
            locations:
 
297
              [.../work/tree]
 
298
              file = locations
 
299
            branch:
 
300
              file = branch
 
301
            ''')
 
302
 
 
303
    def test_locations_config_inside_branch(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
 
 
314
    def test_branch_config_default(self):
 
315
        script.run_script(self, '''\
 
316
            $ bzr config -d tree --scope locations --remove file
 
317
            $ bzr config -d tree --all file
 
318
            branch:
 
319
              file = branch
 
320
            bazaar:
 
321
              [DEFAULT]
 
322
              file = bazaar
 
323
            ''')
 
324
        script.run_script(self, '''\
 
325
            $ bzr config -d tree --remove file
 
326
            $ bzr config -d tree --all file
 
327
            bazaar:
 
328
              [DEFAULT]
 
329
              file = bazaar
 
330
            ''')
 
331
 
 
332
    def test_branch_config_forcing_branch(self):
 
333
        script.run_script(self, '''\
 
334
            $ bzr config -d tree --scope branch --remove file
 
335
            $ bzr config -d tree --all file
 
336
            locations:
 
337
              [.../work/tree]
 
338
              file = locations
 
339
            bazaar:
 
340
              [DEFAULT]
 
341
              file = bazaar
 
342
            ''')
 
343
        script.run_script(self, '''\
 
344
            $ bzr config -d tree --scope locations --remove file
 
345
            $ bzr config -d tree --all file
 
346
            bazaar:
 
347
              [DEFAULT]
 
348
              file = bazaar
 
349
            ''')
 
350
 
 
351
 
 
352
class TestSmartServerConfig(tests.TestCaseWithTransport):
 
353
 
 
354
    def test_simple_branch_config(self):
 
355
        self.setup_smart_server_with_call_log()
 
356
        t = self.make_branch_and_tree('branch')
 
357
        self.reset_smart_call_log()
 
358
        out, err = self.run_bzr(['config', '-d', self.get_url('branch')])
 
359
        # This figure represent the amount of work to perform this use case. It
 
360
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
361
        # being too low. If rpc_count increases, more network roundtrips have
 
362
        # become necessary for this use case. Please do not adjust this number
 
363
        # upwards without agreement from bzr's network support maintainers.
 
364
        self.assertLength(5, self.hpss_calls)
 
365
        self.assertLength(1, self.hpss_connections)
 
366
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)