/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 breezy/tests/blackbox/test_config.py

  • Committer: Robert Collins
  • Date: 2005-10-19 10:11:57 UTC
  • mfrom: (1185.16.78)
  • mto: This revision was merged to the branch mainline in revision 1470.
  • Revision ID: robertc@robertcollins.net-20051019101157-17438d311e746b4f
mergeĀ fromĀ upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2010, 2011, 2012, 2016 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 brz config."""
19
 
 
20
 
from ... import (
21
 
    config,
22
 
    tests,
23
 
    )
24
 
from .. import (
25
 
    script,
26
 
    test_config as _t_config,
27
 
    )
28
 
from ..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.assertEqual('', out)
36
 
        self.assertEqual('', 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
 
class TestConfigDisplay(tests.TestCaseWithTransport):
70
 
 
71
 
    def setUp(self):
72
 
        super(TestConfigDisplay, self).setUp()
73
 
        _t_config.create_configs(self)
74
 
 
75
 
    def test_multiline_all_values(self):
76
 
        self.breezy_config.set_user_option('multiline', '1\n2\n')
77
 
        # Fallout from bug 710410, the triple quotes have been toggled
78
 
        script.run_script(self, '''\
79
 
            $ brz config -d tree
80
 
            breezy:
81
 
              [DEFAULT]
82
 
              multiline = """1
83
 
            2
84
 
            """
85
 
            ''')
86
 
 
87
 
    def test_multiline_value_only(self):
88
 
        self.breezy_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
 
            $ brz config -d tree multiline
92
 
            """1
93
 
            2
94
 
            """
95
 
            ''')
96
 
 
97
 
    def test_list_value_all(self):
98
 
        config.option_registry.register(config.ListOption('list'))
99
 
        self.addCleanup(config.option_registry.remove, 'list')
100
 
        self.breezy_config.set_user_option('list', [1, 'a', 'with, a comma'])
101
 
        script.run_script(self, '''\
102
 
            $ brz config -d tree
103
 
            breezy:
104
 
              [DEFAULT]
105
 
              list = 1, a, "with, a comma"
106
 
            ''')
107
 
 
108
 
    def test_list_value_one(self):
109
 
        config.option_registry.register(config.ListOption('list'))
110
 
        self.addCleanup(config.option_registry.remove, 'list')
111
 
        self.breezy_config.set_user_option('list', [1, 'a', 'with, a comma'])
112
 
        script.run_script(self, '''\
113
 
            $ brz config -d tree list
114
 
            1, a, "with, a comma"
115
 
            ''')
116
 
 
117
 
    def test_registry_value_all(self):
118
 
        self.breezy_config.set_user_option('transform.orphan_policy',
119
 
                                           u'move')
120
 
        script.run_script(self, '''\
121
 
            $ brz config -d tree
122
 
            breezy:
123
 
              [DEFAULT]
124
 
              transform.orphan_policy = move
125
 
            ''')
126
 
 
127
 
    def test_registry_value_one(self):
128
 
        self.breezy_config.set_user_option('transform.orphan_policy',
129
 
                                           u'move')
130
 
        script.run_script(self, '''\
131
 
            $ brz config -d tree transform.orphan_policy
132
 
            move
133
 
            ''')
134
 
 
135
 
    def test_breezy_config(self):
136
 
        self.breezy_config.set_user_option('hello', 'world')
137
 
        script.run_script(self, '''\
138
 
            $ brz config -d tree
139
 
            breezy:
140
 
              [DEFAULT]
141
 
              hello = world
142
 
            ''')
143
 
 
144
 
    def test_locations_config_for_branch(self):
145
 
        self.locations_config.set_user_option('hello', 'world')
146
 
        self.branch_config.set_user_option('hello', 'you')
147
 
        script.run_script(self, '''\
148
 
            $ brz config -d tree
149
 
            locations:
150
 
              [.../tree]
151
 
              hello = world
152
 
            branch:
153
 
              hello = you
154
 
            ''')
155
 
 
156
 
    def test_locations_config_outside_branch(self):
157
 
        self.breezy_config.set_user_option('hello', 'world')
158
 
        self.locations_config.set_user_option('hello', 'world')
159
 
        script.run_script(self, '''\
160
 
            $ brz config
161
 
            breezy:
162
 
              [DEFAULT]
163
 
              hello = world
164
 
            ''')
165
 
 
166
 
    def test_cmd_line(self):
167
 
        self.breezy_config.set_user_option('hello', 'world')
168
 
        script.run_script(self, '''\
169
 
            $ brz config -Ohello=bzr
170
 
            cmdline:
171
 
              hello = bzr
172
 
            breezy:
173
 
              [DEFAULT]
174
 
              hello = world
175
 
            ''')
176
 
 
177
 
 
178
 
class TestConfigDisplayWithPolicy(tests.TestCaseWithTransport):
179
 
 
180
 
    def test_location_with_policy(self):
181
 
        # LocationConfig is the only one dealing with policies so far.
182
 
        self.make_branch_and_tree('tree')
183
 
        config_text = """\
184
 
[%(dir)s]
185
 
url = dir
186
 
url:policy = appendpath
187
 
[%(dir)s/tree]
188
 
url = tree
189
 
""" % {'dir': self.test_dir}
190
 
        # We don't use the config directly so we save it to disk
191
 
        config.LocationConfig.from_string(config_text, 'tree', save=True)
192
 
        # policies are displayed with their options since they are part of
193
 
        # their definition, likewise the path is not appended, we are just
194
 
        # presenting the relevant portions of the config files
195
 
        script.run_script(self, '''\
196
 
            $ brz config -d tree --all url
197
 
            locations:
198
 
              [.../work/tree]
199
 
              url = tree
200
 
              [.../work]
201
 
              url = dir
202
 
              url:policy = appendpath
203
 
            ''')
204
 
 
205
 
 
206
 
class TestConfigActive(tests.TestCaseWithTransport):
207
 
 
208
 
    def setUp(self):
209
 
        super(TestConfigActive, self).setUp()
210
 
        _t_config.create_configs_with_file_option(self)
211
 
 
212
 
    def test_active_in_locations(self):
213
 
        script.run_script(self, '''\
214
 
            $ brz config -d tree file
215
 
            locations
216
 
            ''')
217
 
 
218
 
    def test_active_in_breezy(self):
219
 
        script.run_script(self, '''\
220
 
            $ brz config -d tree --scope breezy file
221
 
            breezy
222
 
            ''')
223
 
 
224
 
    def test_active_in_branch(self):
225
 
        # We need to delete the locations definition that overrides the branch
226
 
        # one
227
 
        script.run_script(self, '''\
228
 
            $ brz config -d tree --scope locations --remove file
229
 
            $ brz config -d tree file
230
 
            branch
231
 
            ''')
232
 
 
233
 
 
234
 
class TestConfigSetOption(tests.TestCaseWithTransport):
235
 
 
236
 
    def setUp(self):
237
 
        super(TestConfigSetOption, self).setUp()
238
 
        _t_config.create_configs(self)
239
 
 
240
 
    def test_unknown_config(self):
241
 
        self.run_bzr_error(['The "moon" configuration does not exist'],
242
 
                           ['config', '--scope', 'moon', 'hello=world'])
243
 
 
244
 
    def test_breezy_config_outside_branch(self):
245
 
        script.run_script(self, '''\
246
 
            $ brz config --scope breezy hello=world
247
 
            $ brz config -d tree --all hello
248
 
            breezy:
249
 
              [DEFAULT]
250
 
              hello = world
251
 
            ''')
252
 
 
253
 
    def test_breezy_config_inside_branch(self):
254
 
        script.run_script(self, '''\
255
 
            $ brz config -d tree --scope breezy hello=world
256
 
            $ brz config -d tree --all hello
257
 
            breezy:
258
 
              [DEFAULT]
259
 
              hello = world
260
 
            ''')
261
 
 
262
 
    def test_locations_config_inside_branch(self):
263
 
        script.run_script(self, '''\
264
 
            $ brz config -d tree --scope locations hello=world
265
 
            $ brz config -d tree --all hello
266
 
            locations:
267
 
              [.../work/tree]
268
 
              hello = world
269
 
            ''')
270
 
 
271
 
    def test_branch_config_default(self):
272
 
        script.run_script(self, '''\
273
 
            $ brz config -d tree hello=world
274
 
            $ brz config -d tree --all hello
275
 
            branch:
276
 
              hello = world
277
 
            ''')
278
 
 
279
 
    def test_branch_config_forcing_branch(self):
280
 
        script.run_script(self, '''\
281
 
            $ brz config -d tree --scope branch hello=world
282
 
            $ brz config -d tree --all hello
283
 
            branch:
284
 
              hello = world
285
 
            ''')
286
 
 
287
 
 
288
 
class TestConfigRemoveOption(tests.TestCaseWithTransport):
289
 
 
290
 
    def setUp(self):
291
 
        super(TestConfigRemoveOption, self).setUp()
292
 
        _t_config.create_configs_with_file_option(self)
293
 
 
294
 
    def test_unknown_config(self):
295
 
        self.run_bzr_error(['The "moon" configuration does not exist'],
296
 
                           ['config', '--scope', 'moon', '--remove', 'file'])
297
 
 
298
 
    def test_breezy_config_outside_branch(self):
299
 
        script.run_script(self, '''\
300
 
            $ brz config --scope breezy --remove file
301
 
            $ brz config -d tree --all file
302
 
            locations:
303
 
              [.../work/tree]
304
 
              file = locations
305
 
            branch:
306
 
              file = branch
307
 
            ''')
308
 
 
309
 
    def test_breezy_config_inside_branch(self):
310
 
        script.run_script(self, '''\
311
 
            $ brz config -d tree --scope breezy --remove file
312
 
            $ brz config -d tree --all file
313
 
            locations:
314
 
              [.../work/tree]
315
 
              file = locations
316
 
            branch:
317
 
              file = branch
318
 
            ''')
319
 
 
320
 
    def test_locations_config_inside_branch(self):
321
 
        script.run_script(self, '''\
322
 
            $ brz config -d tree --scope locations --remove file
323
 
            $ brz config -d tree --all file
324
 
            branch:
325
 
              file = branch
326
 
            breezy:
327
 
              [DEFAULT]
328
 
              file = breezy
329
 
            ''')
330
 
 
331
 
    def test_branch_config_default(self):
332
 
        script.run_script(self, '''\
333
 
            $ brz config -d tree --scope locations --remove file
334
 
            $ brz config -d tree --all file
335
 
            branch:
336
 
              file = branch
337
 
            breezy:
338
 
              [DEFAULT]
339
 
              file = breezy
340
 
            ''')
341
 
        script.run_script(self, '''\
342
 
            $ brz config -d tree --remove file
343
 
            $ brz config -d tree --all file
344
 
            breezy:
345
 
              [DEFAULT]
346
 
              file = breezy
347
 
            ''')
348
 
 
349
 
    def test_branch_config_forcing_branch(self):
350
 
        script.run_script(self, '''\
351
 
            $ brz config -d tree --scope branch --remove file
352
 
            $ brz config -d tree --all file
353
 
            locations:
354
 
              [.../work/tree]
355
 
              file = locations
356
 
            breezy:
357
 
              [DEFAULT]
358
 
              file = breezy
359
 
            ''')
360
 
        script.run_script(self, '''\
361
 
            $ brz config -d tree --scope locations --remove file
362
 
            $ brz config -d tree --all file
363
 
            breezy:
364
 
              [DEFAULT]
365
 
              file = breezy
366
 
            ''')
367
 
 
368
 
 
369
 
class TestSmartServerConfig(tests.TestCaseWithTransport):
370
 
 
371
 
    def test_simple_branch_config(self):
372
 
        self.setup_smart_server_with_call_log()
373
 
        t = self.make_branch_and_tree('branch')
374
 
        self.reset_smart_call_log()
375
 
        out, err = self.run_bzr(['config', '-d', self.get_url('branch')])
376
 
        # This figure represent the amount of work to perform this use case. It
377
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
378
 
        # being too low. If rpc_count increases, more network roundtrips have
379
 
        # become necessary for this use case. Please do not adjust this number
380
 
        # upwards without agreement from bzr's network support maintainers.
381
 
        self.assertLength(5, self.hpss_calls)
382
 
        self.assertLength(1, self.hpss_connections)
383
 
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
384
 
 
385
 
 
386
 
class TestConfigDirectory(tests.TestCaseWithTransport):
387
 
 
388
 
    def test_parent_alias(self):
389
 
        t = self.make_branch_and_tree('base')
390
 
        t.branch.get_config_stack().set('test', 'base')
391
 
        clone = t.branch.controldir.sprout('clone').open_branch()
392
 
        clone.get_config_stack().set('test', 'clone')
393
 
        out, err = self.run_bzr(['config', '-d', ':parent', 'test'],
394
 
                                working_dir='clone')
395
 
        self.assertEqual('base\n', out)