~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2010-12-20 11:57:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5577.
  • Revision ID: jelmer@samba.org-20101220115714-2ru3hfappjweeg7q
Don't use no-plugins.

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
import os
 
21
 
 
22
from bzrlib import (
 
23
    config,
 
24
    errors,
 
25
    tests,
 
26
    )
 
27
from bzrlib.tests import (
 
28
    script,
 
29
    test_config as _t_config,
 
30
    )
 
31
 
 
32
class TestWithoutConfig(tests.TestCaseWithTransport):
 
33
 
 
34
    def test_config_all(self):
 
35
        out, err = self.run_bzr(['config'])
 
36
        self.assertEquals('', out)
 
37
        self.assertEquals('', err)
 
38
 
 
39
    def test_remove_unknown_option(self):
 
40
        self.run_bzr_error(['The "file" configuration option does not exist',],
 
41
                           ['config', '--remove', 'file'])
 
42
 
 
43
    def test_all_remove_exclusive(self):
 
44
        self.run_bzr_error(['--all and --remove are mutually exclusive.',],
 
45
                           ['config', '--remove', '--all'])
 
46
 
 
47
    def test_all_set_exclusive(self):
 
48
        self.run_bzr_error(['Only one option can be set.',],
 
49
                           ['config', '--all', 'hello=world'])
 
50
 
 
51
    def test_remove_no_option(self):
 
52
        self.run_bzr_error(['--remove expects an option to remove.',],
 
53
                           ['config', '--remove'])
 
54
 
 
55
    def test_unknown_option(self):
 
56
        self.run_bzr_error(['The "file" configuration option does not exist',],
 
57
                           ['config', 'file'])
 
58
 
 
59
    def test_unexpected_regexp(self):
 
60
        self.run_bzr_error(
 
61
            ['The "\*file" configuration option does not exist',],
 
62
            ['config', '*file'])
 
63
 
 
64
    def test_wrong_regexp(self):
 
65
        self.run_bzr_error(
 
66
            ['Invalid pattern\(s\) found. "\*file" nothing to repeat',],
 
67
            ['config', '--all', '*file'])
 
68
 
 
69
 
 
70
 
 
71
class TestConfigDisplay(tests.TestCaseWithTransport):
 
72
 
 
73
    def setUp(self):
 
74
        super(TestConfigDisplay, self).setUp()
 
75
        _t_config.create_configs(self)
 
76
 
 
77
    def test_multiline_all_values(self):
 
78
        self.bazaar_config.set_user_option('multiline', '1\n2\n')
 
79
        script.run_script(self, """\
 
80
            $ bzr config -d tree
 
81
            bazaar:
 
82
              multiline = '''1
 
83
            2
 
84
            '''
 
85
            """)
 
86
 
 
87
    def test_multiline_value_only(self):
 
88
        self.bazaar_config.set_user_option('multiline', '1\n2\n')
 
89
        script.run_script(self, """\
 
90
            $ bzr config -d tree multiline
 
91
            '''1
 
92
            2
 
93
            '''
 
94
            """)
 
95
 
 
96
    def test_list_all_values(self):
 
97
        self.bazaar_config.set_user_option('list', [1, 'a', 'with, a comma'])
 
98
        script.run_script(self, '''\
 
99
            $ bzr config -d tree
 
100
            bazaar:
 
101
              list = 1, a, "with, a comma"
 
102
            ''')
 
103
 
 
104
    def test_list_value_only(self):
 
105
        self.bazaar_config.set_user_option('list', [1, 'a', 'with, a comma'])
 
106
        script.run_script(self, '''\
 
107
            $ bzr config -d tree list
 
108
            1, a, "with, a comma"
 
109
            ''')
 
110
 
 
111
    def test_bazaar_config(self):
 
112
        self.bazaar_config.set_user_option('hello', 'world')
 
113
        script.run_script(self, '''\
 
114
            $ bzr config -d tree
 
115
            bazaar:
 
116
              hello = world
 
117
            ''')
 
118
 
 
119
    def test_locations_config_for_branch(self):
 
120
        self.locations_config.set_user_option('hello', 'world')
 
121
        self.branch_config.set_user_option('hello', 'you')
 
122
        script.run_script(self, '''\
 
123
            $ bzr config -d tree
 
124
            locations:
 
125
              [.../tree]
 
126
              hello = world
 
127
            branch:
 
128
              hello = you
 
129
            ''')
 
130
 
 
131
    def test_locations_config_outside_branch(self):
 
132
        self.bazaar_config.set_user_option('hello', 'world')
 
133
        self.locations_config.set_user_option('hello', 'world')
 
134
        script.run_script(self, '''\
 
135
            $ bzr config
 
136
            bazaar:
 
137
              hello = world
 
138
            ''')
 
139
 
 
140
class TestConfigDisplayWithPolicy(tests.TestCaseWithTransport):
 
141
 
 
142
    def test_location_with_policy(self):
 
143
        # LocationConfig is the only one dealing with policies so far.
 
144
        self.make_branch_and_tree('tree')
 
145
        config_text = """\
 
146
[%(dir)s]
 
147
url = dir
 
148
url:policy = appendpath
 
149
[%(dir)s/tree]
 
150
url = tree
 
151
""" % {'dir': self.test_dir}
 
152
        # We don't use the config directly so we save it to disk
 
153
        config.LocationConfig.from_string(config_text, 'tree', save=True)
 
154
        # policies are displayed with their options since they are part of
 
155
        # their definition, likewise the path is not appended, we are just
 
156
        # presenting the relevant portions of the config files
 
157
        script.run_script(self, '''\
 
158
            $ bzr config -d tree --all url
 
159
            locations:
 
160
              [.../work/tree]
 
161
              url = tree
 
162
              [.../work]
 
163
              url = dir
 
164
              url:policy = appendpath
 
165
            ''')
 
166
 
 
167
 
 
168
class TestConfigActive(tests.TestCaseWithTransport):
 
169
 
 
170
    def setUp(self):
 
171
        super(TestConfigActive, self).setUp()
 
172
        _t_config.create_configs_with_file_option(self)
 
173
 
 
174
    def test_active_in_locations(self):
 
175
        script.run_script(self, '''\
 
176
            $ bzr config -d tree file
 
177
            locations
 
178
            ''')
 
179
 
 
180
    def test_active_in_bazaar(self):
 
181
        script.run_script(self, '''\
 
182
            $ bzr config -d tree --scope bazaar file
 
183
            bazaar
 
184
            ''')
 
185
 
 
186
    def test_active_in_branch(self):
 
187
        # We need to delete the locations definition that overrides the branch
 
188
        # one
 
189
        script.run_script(self, '''\
 
190
            $ bzr config -d tree --remove file
 
191
            $ bzr config -d tree file
 
192
            branch
 
193
            ''')
 
194
 
 
195
 
 
196
class TestConfigSetOption(tests.TestCaseWithTransport):
 
197
 
 
198
    def setUp(self):
 
199
        super(TestConfigSetOption, self).setUp()
 
200
        _t_config.create_configs(self)
 
201
 
 
202
    def test_unknown_config(self):
 
203
        self.run_bzr_error(['The "moon" configuration does not exist'],
 
204
                           ['config', '--scope', 'moon', 'hello=world'])
 
205
 
 
206
    def test_bazaar_config_outside_branch(self):
 
207
        script.run_script(self, '''\
 
208
            $ bzr config --scope bazaar hello=world
 
209
            $ bzr config -d tree --all hello
 
210
            bazaar:
 
211
              hello = world
 
212
            ''')
 
213
 
 
214
    def test_bazaar_config_inside_branch(self):
 
215
        script.run_script(self, '''\
 
216
            $ bzr config -d tree --scope bazaar hello=world
 
217
            $ bzr config -d tree --all hello
 
218
            bazaar:
 
219
              hello = world
 
220
            ''')
 
221
 
 
222
    def test_locations_config_inside_branch(self):
 
223
        script.run_script(self, '''\
 
224
            $ bzr config -d tree --scope locations hello=world
 
225
            $ bzr config -d tree --all hello
 
226
            locations:
 
227
              [.../work/tree]
 
228
              hello = world
 
229
            ''')
 
230
 
 
231
    def test_branch_config_default(self):
 
232
        script.run_script(self, '''\
 
233
            $ bzr config -d tree hello=world
 
234
            $ bzr config -d tree --all hello
 
235
            branch:
 
236
              hello = world
 
237
            ''')
 
238
 
 
239
    def test_branch_config_forcing_branch(self):
 
240
        script.run_script(self, '''\
 
241
            $ bzr config -d tree --scope branch hello=world
 
242
            $ bzr config -d tree --all hello
 
243
            branch:
 
244
              hello = world
 
245
            ''')
 
246
 
 
247
 
 
248
class TestConfigRemoveOption(tests.TestCaseWithTransport):
 
249
 
 
250
    def setUp(self):
 
251
        super(TestConfigRemoveOption, self).setUp()
 
252
        _t_config.create_configs_with_file_option(self)
 
253
 
 
254
    def test_unknown_config(self):
 
255
        self.run_bzr_error(['The "moon" configuration does not exist'],
 
256
                           ['config', '--scope', 'moon', '--remove', 'file'])
 
257
 
 
258
    def test_bazaar_config_outside_branch(self):
 
259
        script.run_script(self, '''\
 
260
            $ bzr config --scope bazaar --remove file
 
261
            $ bzr config -d tree --all file
 
262
            locations:
 
263
              [.../work/tree]
 
264
              file = locations
 
265
            branch:
 
266
              file = branch
 
267
            ''')
 
268
 
 
269
    def test_bazaar_config_inside_branch(self):
 
270
        script.run_script(self, '''\
 
271
            $ bzr config -d tree --scope bazaar --remove file
 
272
            $ bzr config -d tree --all file
 
273
            locations:
 
274
              [.../work/tree]
 
275
              file = locations
 
276
            branch:
 
277
              file = branch
 
278
            ''')
 
279
 
 
280
    def test_locations_config_inside_branch(self):
 
281
        script.run_script(self, '''\
 
282
            $ bzr config -d tree --scope locations --remove file
 
283
            $ bzr config -d tree --all file
 
284
            branch:
 
285
              file = branch
 
286
            bazaar:
 
287
              file = bazaar
 
288
            ''')
 
289
 
 
290
    def test_branch_config_default(self):
 
291
        script.run_script(self, '''\
 
292
            $ bzr config -d tree --remove file
 
293
            $ bzr config -d tree --all file
 
294
            branch:
 
295
              file = branch
 
296
            bazaar:
 
297
              file = bazaar
 
298
            ''')
 
299
        script.run_script(self, '''\
 
300
            $ bzr config -d tree --remove file
 
301
            $ bzr config -d tree --all file
 
302
            bazaar:
 
303
              file = bazaar
 
304
            ''')
 
305
 
 
306
    def test_branch_config_forcing_branch(self):
 
307
        script.run_script(self, '''\
 
308
            $ bzr config -d tree --scope branch --remove file
 
309
            $ bzr config -d tree --all file
 
310
            locations:
 
311
              [.../work/tree]
 
312
              file = locations
 
313
            bazaar:
 
314
              file = bazaar
 
315
            ''')
 
316
        script.run_script(self, '''\
 
317
            $ bzr config -d tree --remove file
 
318
            $ bzr config -d tree --all file
 
319
            bazaar:
 
320
              file = bazaar
 
321
            ''')