/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: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-08-23 01:15:41 UTC
  • mfrom: (7520.1.4 merge-3.1)
  • Revision ID: breezy.the.bot@gmail.com-20200823011541-nv0oh7nzaganx2qy
Merge lp:brz/3.1.

Merged from https://code.launchpad.net/~jelmer/brz/merge-3.1/+merge/389690

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
 
 
29
 
 
30
class TestWithoutConfig(tests.TestCaseWithTransport):
 
31
 
 
32
    def test_config_all(self):
 
33
        out, err = self.run_bzr(['config'])
 
34
        self.assertEqual('', out)
 
35
        self.assertEqual('', err)
 
36
 
 
37
    def test_remove_unknown_option(self):
 
38
        self.run_bzr_error(['The "file" configuration option does not exist', ],
 
39
                           ['config', '--remove', 'file'])
 
40
 
 
41
    def test_all_remove_exclusive(self):
 
42
        self.run_bzr_error(['--all and --remove are mutually exclusive.', ],
 
43
                           ['config', '--remove', '--all'])
 
44
 
 
45
    def test_all_set_exclusive(self):
 
46
        self.run_bzr_error(['Only one option can be set.', ],
 
47
                           ['config', '--all', 'hello=world'])
 
48
 
 
49
    def test_remove_no_option(self):
 
50
        self.run_bzr_error(['--remove expects an option to remove.', ],
 
51
                           ['config', '--remove'])
 
52
 
 
53
    def test_unknown_option(self):
 
54
        self.run_bzr_error(['The "file" configuration option does not exist', ],
 
55
                           ['config', 'file'])
 
56
 
 
57
    def test_unexpected_regexp(self):
 
58
        self.run_bzr_error(
 
59
            ['The "\\*file" configuration option does not exist', ],
 
60
            ['config', '*file'])
 
61
 
 
62
    def test_wrong_regexp(self):
 
63
        self.run_bzr_error(
 
64
            ['Invalid pattern\\(s\\) found. "\\*file" nothing to repeat', ],
 
65
            ['config', '--all', '*file'])
 
66
 
 
67
 
 
68
class TestConfigDisplay(tests.TestCaseWithTransport):
 
69
 
 
70
    def setUp(self):
 
71
        super(TestConfigDisplay, self).setUp()
 
72
        _t_config.create_configs(self)
 
73
 
 
74
    def test_multiline_all_values(self):
 
75
        self.breezy_config.set_user_option('multiline', '1\n2\n')
 
76
        # Fallout from bug 710410, the triple quotes have been toggled
 
77
        script.run_script(self, '''\
 
78
            $ brz config -d tree
 
79
            breezy:
 
80
              [DEFAULT]
 
81
              multiline = """1
 
82
            2
 
83
            """
 
84
            ''')
 
85
 
 
86
    def test_multiline_value_only(self):
 
87
        self.breezy_config.set_user_option('multiline', '1\n2\n')
 
88
        # Fallout from bug 710410, the triple quotes have been toggled
 
89
        script.run_script(self, '''\
 
90
            $ brz config -d tree multiline
 
91
            """1
 
92
            2
 
93
            """
 
94
            ''')
 
95
 
 
96
    def test_list_value_all(self):
 
97
        config.option_registry.register(config.ListOption('list'))
 
98
        self.addCleanup(config.option_registry.remove, 'list')
 
99
        self.breezy_config.set_user_option('list', [1, 'a', 'with, a comma'])
 
100
        script.run_script(self, '''\
 
101
            $ brz config -d tree
 
102
            breezy:
 
103
              [DEFAULT]
 
104
              list = 1, a, "with, a comma"
 
105
            ''')
 
106
 
 
107
    def test_list_value_one(self):
 
108
        config.option_registry.register(config.ListOption('list'))
 
109
        self.addCleanup(config.option_registry.remove, 'list')
 
110
        self.breezy_config.set_user_option('list', [1, 'a', 'with, a comma'])
 
111
        script.run_script(self, '''\
 
112
            $ brz config -d tree list
 
113
            1, a, "with, a comma"
 
114
            ''')
 
115
 
 
116
    def test_registry_value_all(self):
 
117
        self.breezy_config.set_user_option('transform.orphan_policy',
 
118
                                           u'move')
 
119
        script.run_script(self, '''\
 
120
            $ brz config -d tree
 
121
            breezy:
 
122
              [DEFAULT]
 
123
              transform.orphan_policy = move
 
124
            ''')
 
125
 
 
126
    def test_registry_value_one(self):
 
127
        self.breezy_config.set_user_option('transform.orphan_policy',
 
128
                                           u'move')
 
129
        script.run_script(self, '''\
 
130
            $ brz config -d tree transform.orphan_policy
 
131
            move
 
132
            ''')
 
133
 
 
134
    def test_breezy_config(self):
 
135
        self.breezy_config.set_user_option('hello', 'world')
 
136
        script.run_script(self, '''\
 
137
            $ brz config -d tree
 
138
            breezy:
 
139
              [DEFAULT]
 
140
              hello = world
 
141
            ''')
 
142
 
 
143
    def test_locations_config_for_branch(self):
 
144
        self.locations_config.set_user_option('hello', 'world')
 
145
        self.branch_config.set_user_option('hello', 'you')
 
146
        script.run_script(self, '''\
 
147
            $ brz config -d tree
 
148
            locations:
 
149
              [.../tree]
 
150
              hello = world
 
151
            branch:
 
152
              hello = you
 
153
            ''')
 
154
 
 
155
    def test_locations_config_outside_branch(self):
 
156
        self.breezy_config.set_user_option('hello', 'world')
 
157
        self.locations_config.set_user_option('hello', 'world')
 
158
        script.run_script(self, '''\
 
159
            $ brz config
 
160
            breezy:
 
161
              [DEFAULT]
 
162
              hello = world
 
163
            ''')
 
164
 
 
165
    def test_cmd_line(self):
 
166
        self.breezy_config.set_user_option('hello', 'world')
 
167
        script.run_script(self, '''\
 
168
            $ brz config -Ohello=bzr
 
169
            cmdline:
 
170
              hello = bzr
 
171
            breezy:
 
172
              [DEFAULT]
 
173
              hello = world
 
174
            ''')
 
175
 
 
176
 
 
177
class TestConfigDisplayWithPolicy(tests.TestCaseWithTransport):
 
178
 
 
179
    def test_location_with_policy(self):
 
180
        # LocationConfig is the only one dealing with policies so far.
 
181
        self.make_branch_and_tree('tree')
 
182
        config_text = """\
 
183
[%(dir)s]
 
184
url = dir
 
185
url:policy = appendpath
 
186
[%(dir)s/tree]
 
187
url = tree
 
188
""" % {'dir': self.test_dir}
 
189
        # We don't use the config directly so we save it to disk
 
190
        config.LocationConfig.from_string(config_text, 'tree', save=True)
 
191
        # policies are displayed with their options since they are part of
 
192
        # their definition, likewise the path is not appended, we are just
 
193
        # presenting the relevant portions of the config files
 
194
        script.run_script(self, '''\
 
195
            $ brz config -d tree --all url
 
196
            locations:
 
197
              [.../work/tree]
 
198
              url = tree
 
199
              [.../work]
 
200
              url = dir
 
201
              url:policy = appendpath
 
202
            ''')
 
203
 
 
204
 
 
205
class TestConfigActive(tests.TestCaseWithTransport):
 
206
 
 
207
    def setUp(self):
 
208
        super(TestConfigActive, self).setUp()
 
209
        _t_config.create_configs_with_file_option(self)
 
210
 
 
211
    def test_active_in_locations(self):
 
212
        script.run_script(self, '''\
 
213
            $ brz config -d tree file
 
214
            locations
 
215
            ''')
 
216
 
 
217
    def test_active_in_breezy(self):
 
218
        script.run_script(self, '''\
 
219
            $ brz config -d tree --scope breezy file
 
220
            breezy
 
221
            ''')
 
222
 
 
223
    def test_active_in_branch(self):
 
224
        # We need to delete the locations definition that overrides the branch
 
225
        # one
 
226
        script.run_script(self, '''\
 
227
            $ brz config -d tree --scope locations --remove file
 
228
            $ brz config -d tree file
 
229
            branch
 
230
            ''')
 
231
 
 
232
 
 
233
class TestConfigSetOption(tests.TestCaseWithTransport):
 
234
 
 
235
    def setUp(self):
 
236
        super(TestConfigSetOption, self).setUp()
 
237
        _t_config.create_configs(self)
 
238
 
 
239
    def test_unknown_config(self):
 
240
        self.run_bzr_error(['The "moon" configuration does not exist'],
 
241
                           ['config', '--scope', 'moon', 'hello=world'])
 
242
 
 
243
    def test_breezy_config_outside_branch(self):
 
244
        script.run_script(self, '''\
 
245
            $ brz config --scope breezy hello=world
 
246
            $ brz config -d tree --all hello
 
247
            breezy:
 
248
              [DEFAULT]
 
249
              hello = world
 
250
            ''')
 
251
 
 
252
    def test_breezy_config_inside_branch(self):
 
253
        script.run_script(self, '''\
 
254
            $ brz config -d tree --scope breezy hello=world
 
255
            $ brz config -d tree --all hello
 
256
            breezy:
 
257
              [DEFAULT]
 
258
              hello = world
 
259
            ''')
 
260
 
 
261
    def test_locations_config_inside_branch(self):
 
262
        script.run_script(self, '''\
 
263
            $ brz config -d tree --scope locations hello=world
 
264
            $ brz config -d tree --all hello
 
265
            locations:
 
266
              [.../work/tree]
 
267
              hello = world
 
268
            ''')
 
269
 
 
270
    def test_branch_config_default(self):
 
271
        script.run_script(self, '''\
 
272
            $ brz config -d tree hello=world
 
273
            $ brz config -d tree --all hello
 
274
            branch:
 
275
              hello = world
 
276
            ''')
 
277
 
 
278
    def test_branch_config_forcing_branch(self):
 
279
        script.run_script(self, '''\
 
280
            $ brz config -d tree --scope branch hello=world
 
281
            $ brz config -d tree --all hello
 
282
            branch:
 
283
              hello = world
 
284
            ''')
 
285
 
 
286
 
 
287
class TestConfigRemoveOption(tests.TestCaseWithTransport):
 
288
 
 
289
    def setUp(self):
 
290
        super(TestConfigRemoveOption, self).setUp()
 
291
        _t_config.create_configs_with_file_option(self)
 
292
 
 
293
    def test_unknown_config(self):
 
294
        self.run_bzr_error(['The "moon" configuration does not exist'],
 
295
                           ['config', '--scope', 'moon', '--remove', 'file'])
 
296
 
 
297
    def test_breezy_config_outside_branch(self):
 
298
        script.run_script(self, '''\
 
299
            $ brz config --scope breezy --remove file
 
300
            $ brz config -d tree --all file
 
301
            locations:
 
302
              [.../work/tree]
 
303
              file = locations
 
304
            branch:
 
305
              file = branch
 
306
            ''')
 
307
 
 
308
    def test_breezy_config_inside_branch(self):
 
309
        script.run_script(self, '''\
 
310
            $ brz config -d tree --scope breezy --remove file
 
311
            $ brz config -d tree --all file
 
312
            locations:
 
313
              [.../work/tree]
 
314
              file = locations
 
315
            branch:
 
316
              file = branch
 
317
            ''')
 
318
 
 
319
    def test_locations_config_inside_branch(self):
 
320
        script.run_script(self, '''\
 
321
            $ brz config -d tree --scope locations --remove file
 
322
            $ brz config -d tree --all file
 
323
            branch:
 
324
              file = branch
 
325
            breezy:
 
326
              [DEFAULT]
 
327
              file = breezy
 
328
            ''')
 
329
 
 
330
    def test_branch_config_default(self):
 
331
        script.run_script(self, '''\
 
332
            $ brz config -d tree --scope locations --remove file
 
333
            $ brz config -d tree --all file
 
334
            branch:
 
335
              file = branch
 
336
            breezy:
 
337
              [DEFAULT]
 
338
              file = breezy
 
339
            ''')
 
340
        script.run_script(self, '''\
 
341
            $ brz config -d tree --remove file
 
342
            $ brz config -d tree --all file
 
343
            breezy:
 
344
              [DEFAULT]
 
345
              file = breezy
 
346
            ''')
 
347
 
 
348
    def test_branch_config_forcing_branch(self):
 
349
        script.run_script(self, '''\
 
350
            $ brz config -d tree --scope branch --remove file
 
351
            $ brz config -d tree --all file
 
352
            locations:
 
353
              [.../work/tree]
 
354
              file = locations
 
355
            breezy:
 
356
              [DEFAULT]
 
357
              file = breezy
 
358
            ''')
 
359
        script.run_script(self, '''\
 
360
            $ brz config -d tree --scope locations --remove file
 
361
            $ brz config -d tree --all file
 
362
            breezy:
 
363
              [DEFAULT]
 
364
              file = breezy
 
365
            ''')
 
366
 
 
367
 
 
368
class TestConfigDirectory(tests.TestCaseWithTransport):
 
369
 
 
370
    def test_parent_alias(self):
 
371
        t = self.make_branch_and_tree('base')
 
372
        t.branch.get_config_stack().set('test', 'base')
 
373
        clone = t.branch.controldir.sprout('clone').open_branch()
 
374
        clone.get_config_stack().set('test', 'clone')
 
375
        out, err = self.run_bzr(['config', '-d', ':parent', 'test'],
 
376
                                working_dir='clone')
 
377
        self.assertEqual('base\n', out)