~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2010 Canonical Ltd
 
1
# Copyright (C) 2010, 2011, 2012, 2016 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
17
17
 
18
18
"""Black-box tests for bzr config."""
19
19
 
20
 
import os
21
 
 
22
20
from bzrlib import (
23
21
    config,
24
 
    errors,
25
22
    tests,
26
23
    )
27
24
from bzrlib.tests import (
28
25
    script,
29
26
    test_config as _t_config,
30
27
    )
 
28
from bzrlib.tests.matchers import ContainsNoVfsCalls
 
29
 
31
30
 
32
31
class TestWithoutConfig(tests.TestCaseWithTransport):
33
32
 
34
33
    def test_config_all(self):
35
34
        out, err = self.run_bzr(['config'])
36
 
        self.assertEquals('', out)
37
 
        self.assertEquals('', err)
 
35
        self.assertEqual('', out)
 
36
        self.assertEqual('', err)
38
37
 
39
38
    def test_remove_unknown_option(self):
40
39
        self.run_bzr_error(['The "file" configuration option does not exist',],
80
79
        script.run_script(self, '''\
81
80
            $ bzr config -d tree
82
81
            bazaar:
 
82
              [DEFAULT]
83
83
              multiline = """1
84
84
            2
85
85
            """
95
95
            """
96
96
            ''')
97
97
 
98
 
    def test_list_all_values(self):
 
98
    def test_list_value_all(self):
 
99
        config.option_registry.register(config.ListOption('list'))
 
100
        self.addCleanup(config.option_registry.remove, 'list')
99
101
        self.bazaar_config.set_user_option('list', [1, 'a', 'with, a comma'])
100
102
        script.run_script(self, '''\
101
103
            $ bzr config -d tree
102
104
            bazaar:
 
105
              [DEFAULT]
103
106
              list = 1, a, "with, a comma"
104
107
            ''')
105
108
 
106
 
    def test_list_value_only(self):
 
109
    def test_list_value_one(self):
 
110
        config.option_registry.register(config.ListOption('list'))
 
111
        self.addCleanup(config.option_registry.remove, 'list')
107
112
        self.bazaar_config.set_user_option('list', [1, 'a', 'with, a comma'])
108
113
        script.run_script(self, '''\
109
114
            $ bzr config -d tree list
110
115
            1, a, "with, a comma"
111
116
            ''')
112
117
 
 
118
    def test_registry_value_all(self):
 
119
        self.bazaar_config.set_user_option('bzr.transform.orphan_policy',
 
120
                                           u'move')
 
121
        script.run_script(self, '''\
 
122
            $ bzr config -d tree
 
123
            bazaar:
 
124
              [DEFAULT]
 
125
              bzr.transform.orphan_policy = move
 
126
            ''')
 
127
 
 
128
    def test_registry_value_one(self):
 
129
        self.bazaar_config.set_user_option('bzr.transform.orphan_policy',
 
130
                                           u'move')
 
131
        script.run_script(self, '''\
 
132
            $ bzr config -d tree bzr.transform.orphan_policy
 
133
            move
 
134
            ''')
 
135
 
113
136
    def test_bazaar_config(self):
114
137
        self.bazaar_config.set_user_option('hello', 'world')
115
138
        script.run_script(self, '''\
116
139
            $ bzr config -d tree
117
140
            bazaar:
 
141
              [DEFAULT]
118
142
              hello = world
119
143
            ''')
120
144
 
136
160
        script.run_script(self, '''\
137
161
            $ bzr config
138
162
            bazaar:
139
 
              hello = world
140
 
            ''')
 
163
              [DEFAULT]
 
164
              hello = world
 
165
            ''')
 
166
 
 
167
    def test_cmd_line(self):
 
168
        self.bazaar_config.set_user_option('hello', 'world')
 
169
        script.run_script(self, '''\
 
170
            $ bzr config -Ohello=bzr
 
171
            cmdline:
 
172
              hello = bzr
 
173
            bazaar:
 
174
              [DEFAULT]
 
175
              hello = world
 
176
            ''')
 
177
 
141
178
 
142
179
class TestConfigDisplayWithPolicy(tests.TestCaseWithTransport):
143
180
 
189
226
        # We need to delete the locations definition that overrides the branch
190
227
        # one
191
228
        script.run_script(self, '''\
192
 
            $ bzr config -d tree --remove file
 
229
            $ bzr config -d tree --scope locations --remove file
193
230
            $ bzr config -d tree file
194
231
            branch
195
232
            ''')
210
247
            $ bzr config --scope bazaar hello=world
211
248
            $ bzr config -d tree --all hello
212
249
            bazaar:
 
250
              [DEFAULT]
213
251
              hello = world
214
252
            ''')
215
253
 
218
256
            $ bzr config -d tree --scope bazaar hello=world
219
257
            $ bzr config -d tree --all hello
220
258
            bazaar:
 
259
              [DEFAULT]
221
260
              hello = world
222
261
            ''')
223
262
 
286
325
            branch:
287
326
              file = branch
288
327
            bazaar:
 
328
              [DEFAULT]
289
329
              file = bazaar
290
330
            ''')
291
331
 
292
332
    def test_branch_config_default(self):
293
333
        script.run_script(self, '''\
294
 
            $ bzr config -d tree --remove file
 
334
            $ bzr config -d tree --scope locations --remove file
295
335
            $ bzr config -d tree --all file
296
336
            branch:
297
337
              file = branch
298
338
            bazaar:
 
339
              [DEFAULT]
299
340
              file = bazaar
300
341
            ''')
301
342
        script.run_script(self, '''\
302
343
            $ bzr config -d tree --remove file
303
344
            $ bzr config -d tree --all file
304
345
            bazaar:
 
346
              [DEFAULT]
305
347
              file = bazaar
306
348
            ''')
307
349
 
313
355
              [.../work/tree]
314
356
              file = locations
315
357
            bazaar:
 
358
              [DEFAULT]
316
359
              file = bazaar
317
360
            ''')
318
361
        script.run_script(self, '''\
319
 
            $ bzr config -d tree --remove file
 
362
            $ bzr config -d tree --scope locations --remove file
320
363
            $ bzr config -d tree --all file
321
364
            bazaar:
 
365
              [DEFAULT]
322
366
              file = bazaar
323
367
            ''')
 
368
 
 
369
 
 
370
class TestSmartServerConfig(tests.TestCaseWithTransport):
 
371
 
 
372
    def test_simple_branch_config(self):
 
373
        self.setup_smart_server_with_call_log()
 
374
        t = self.make_branch_and_tree('branch')
 
375
        self.reset_smart_call_log()
 
376
        out, err = self.run_bzr(['config', '-d', self.get_url('branch')])
 
377
        # This figure represent the amount of work to perform this use case. It
 
378
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
379
        # being too low. If rpc_count increases, more network roundtrips have
 
380
        # become necessary for this use case. Please do not adjust this number
 
381
        # upwards without agreement from bzr's network support maintainers.
 
382
        self.assertLength(5, self.hpss_calls)
 
383
        self.assertLength(1, self.hpss_connections)
 
384
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
385
 
 
386
 
 
387
class TestConfigDirectory(tests.TestCaseWithTransport):
 
388
 
 
389
    def test_parent_alias(self):
 
390
        t = self.make_branch_and_tree('base')
 
391
        t.branch.get_config_stack().set('test', 'base')
 
392
        clone = t.branch.bzrdir.sprout('clone').open_branch()
 
393
        clone.get_config_stack().set('test', 'clone')
 
394
        out, err = self.run_bzr(['config', '-d', ':parent', 'test'],
 
395
                                working_dir='clone')
 
396
        self.assertEqual('base\n', out)