~bzr-pqm/bzr/bzr.dev

5447.4.2 by Vincent Ladeuil
Implement the 'brz config' command. Read-only.
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,
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
24
    errors,
5447.4.2 by Vincent Ladeuil
Implement the 'brz config' command. Read-only.
25
    tests,
26
    )
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
27
from bzrlib.tests import (
28
    script,
29
    test_config as _t_config,
30
    )
5447.4.2 by Vincent Ladeuil
Implement the 'brz config' command. Read-only.
31
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
32
class TestWithoutConfig(tests.TestCaseWithTransport):
5447.4.2 by Vincent Ladeuil
Implement the 'brz config' command. Read-only.
33
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
34
    def test_config_all(self):
5447.4.2 by Vincent Ladeuil
Implement the 'brz config' command. Read-only.
35
        out, err = self.run_bzr(['config'])
36
        self.assertEquals('', out)
37
        self.assertEquals('', err)
38
5506.2.2 by Vincent Ladeuil
Raise an error if the option doesn't exist and --active is used.
39
    def test_remove_unknown_option(self):
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
40
        self.run_bzr_error(['The "file" configuration option does not exist',],
41
                           ['config', '--remove', 'file'])
5447.4.2 by Vincent Ladeuil
Implement the 'brz config' command. Read-only.
42
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
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'])
5506.2.1 by Vincent Ladeuil
Implements ``bzr config --active option`` displaying only the value.
50
5506.2.2 by Vincent Ladeuil
Raise an error if the option doesn't exist and --active is used.
51
    def test_remove_no_option(self):
5506.2.1 by Vincent Ladeuil
Implements ``bzr config --active option`` displaying only the value.
52
        self.run_bzr_error(['--remove expects an option to remove.',],
53
                           ['config', '--remove'])
54
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
55
    def test_unknown_option(self):
5506.2.2 by Vincent Ladeuil
Raise an error if the option doesn't exist and --active is used.
56
        self.run_bzr_error(['The "file" configuration option does not exist',],
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
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
5506.2.2 by Vincent Ladeuil
Raise an error if the option doesn't exist and --active is used.
69
5506.2.1 by Vincent Ladeuil
Implements ``bzr config --active option`` displaying only the value.
70
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
71
class TestConfigDisplay(tests.TestCaseWithTransport):
72
73
    def setUp(self):
74
        super(TestConfigDisplay, self).setUp()
75
        _t_config.create_configs(self)
76
5533.2.1 by Vincent Ladeuil
``bzr config`` properly displays list values
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
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
111
    def test_bazaar_config(self):
112
        self.bazaar_config.set_user_option('hello', 'world')
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
113
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
114
            $ bzr config -d tree
115
            bazaar:
116
              hello = world
117
            ''')
5447.4.2 by Vincent Ladeuil
Implement the 'brz config' command. Read-only.
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')
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
122
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
123
            $ bzr config -d tree
124
            locations:
5533.1.1 by Vincent Ladeuil
Fix ``bzr config`` to respect policies when displaying values and also display sections when appropriate.
125
              [.../tree]
5447.4.20 by Vincent Ladeuil
Indent inplace files.
126
              hello = world
127
            branch:
128
              hello = you
129
            ''')
5447.4.2 by Vincent Ladeuil
Implement the 'brz config' command. Read-only.
130
131
    def test_locations_config_outside_branch(self):
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
132
        self.bazaar_config.set_user_option('hello', 'world')
5447.4.2 by Vincent Ladeuil
Implement the 'brz config' command. Read-only.
133
        self.locations_config.set_user_option('hello', 'world')
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
134
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
135
            $ bzr config
136
            bazaar:
137
              hello = world
138
            ''')
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
139
5533.1.1 by Vincent Ladeuil
Fix ``bzr config`` to respect policies when displaying values and also display sections when appropriate.
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
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
167
5506.2.1 by Vincent Ladeuil
Implements ``bzr config --active option`` displaying only the value.
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, '''\
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
176
            $ bzr config -d tree file
5506.2.1 by Vincent Ladeuil
Implements ``bzr config --active option`` displaying only the value.
177
            locations
178
            ''')
179
180
    def test_active_in_bazaar(self):
181
        script.run_script(self, '''\
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
182
            $ bzr config -d tree --scope bazaar file
5506.2.1 by Vincent Ladeuil
Implements ``bzr config --active option`` displaying only the value.
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
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
191
            $ bzr config -d tree file
5506.2.1 by Vincent Ladeuil
Implements ``bzr config --active option`` displaying only the value.
192
            branch
193
            ''')
194
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
195
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
196
class TestConfigSetOption(tests.TestCaseWithTransport):
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
197
198
    def setUp(self):
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
199
        super(TestConfigSetOption, self).setUp()
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
200
        _t_config.create_configs(self)
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
201
202
    def test_unknown_config(self):
5447.4.10 by Vincent Ladeuil
Using dedicated exceptions feels cleaner.
203
        self.run_bzr_error(['The "moon" configuration does not exist'],
5447.4.17 by Vincent Ladeuil
Rename config --force to config --scope.
204
                           ['config', '--scope', 'moon', 'hello=world'])
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
205
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
206
    def test_bazaar_config_outside_branch(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
207
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
208
            $ bzr config --scope bazaar hello=world
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
209
            $ bzr config -d tree --all hello
5447.4.20 by Vincent Ladeuil
Indent inplace files.
210
            bazaar:
211
              hello = world
212
            ''')
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
213
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
214
    def test_bazaar_config_inside_branch(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
215
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
216
            $ bzr config -d tree --scope bazaar hello=world
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
217
            $ bzr config -d tree --all hello
5447.4.20 by Vincent Ladeuil
Indent inplace files.
218
            bazaar:
219
              hello = world
220
            ''')
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
221
222
    def test_locations_config_inside_branch(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
223
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
224
            $ bzr config -d tree --scope locations hello=world
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
225
            $ bzr config -d tree --all hello
5447.4.20 by Vincent Ladeuil
Indent inplace files.
226
            locations:
5533.1.1 by Vincent Ladeuil
Fix ``bzr config`` to respect policies when displaying values and also display sections when appropriate.
227
              [.../work/tree]
5447.4.20 by Vincent Ladeuil
Indent inplace files.
228
              hello = world
229
            ''')
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
230
231
    def test_branch_config_default(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
232
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
233
            $ bzr config -d tree hello=world
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
234
            $ bzr config -d tree --all hello
5447.4.20 by Vincent Ladeuil
Indent inplace files.
235
            branch:
236
              hello = world
237
            ''')
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
238
239
    def test_branch_config_forcing_branch(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
240
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
241
            $ bzr config -d tree --scope branch hello=world
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
242
            $ bzr config -d tree --all hello
5447.4.20 by Vincent Ladeuil
Indent inplace files.
243
            branch:
244
              hello = world
245
            ''')
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
246
247
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
248
class TestConfigRemoveOption(tests.TestCaseWithTransport):
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
249
250
    def setUp(self):
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
251
        super(TestConfigRemoveOption, self).setUp()
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
252
        _t_config.create_configs_with_file_option(self)
253
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
254
    def test_unknown_config(self):
255
        self.run_bzr_error(['The "moon" configuration does not exist'],
5447.4.17 by Vincent Ladeuil
Rename config --force to config --scope.
256
                           ['config', '--scope', 'moon', '--remove', 'file'])
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
257
258
    def test_bazaar_config_outside_branch(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
259
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
260
            $ bzr config --scope bazaar --remove file
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
261
            $ bzr config -d tree --all file
5447.4.20 by Vincent Ladeuil
Indent inplace files.
262
            locations:
5533.1.1 by Vincent Ladeuil
Fix ``bzr config`` to respect policies when displaying values and also display sections when appropriate.
263
              [.../work/tree]
5447.4.20 by Vincent Ladeuil
Indent inplace files.
264
              file = locations
265
            branch:
266
              file = branch
267
            ''')
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
268
269
    def test_bazaar_config_inside_branch(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
270
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
271
            $ bzr config -d tree --scope bazaar --remove file
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
272
            $ bzr config -d tree --all file
5447.4.20 by Vincent Ladeuil
Indent inplace files.
273
            locations:
5533.1.1 by Vincent Ladeuil
Fix ``bzr config`` to respect policies when displaying values and also display sections when appropriate.
274
              [.../work/tree]
5447.4.20 by Vincent Ladeuil
Indent inplace files.
275
              file = locations
276
            branch:
277
              file = branch
278
            ''')
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
279
280
    def test_locations_config_inside_branch(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
281
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
282
            $ bzr config -d tree --scope locations --remove file
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
283
            $ bzr config -d tree --all file
5447.4.20 by Vincent Ladeuil
Indent inplace files.
284
            branch:
285
              file = branch
286
            bazaar:
287
              file = bazaar
288
            ''')
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
289
290
    def test_branch_config_default(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
291
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
292
            $ bzr config -d tree --remove file
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
293
            $ bzr config -d tree --all file
5447.4.20 by Vincent Ladeuil
Indent inplace files.
294
            branch:
295
              file = branch
296
            bazaar:
297
              file = bazaar
298
            ''')
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
299
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
300
            $ bzr config -d tree --remove file
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
301
            $ bzr config -d tree --all file
5447.4.20 by Vincent Ladeuil
Indent inplace files.
302
            bazaar:
303
              file = bazaar
304
            ''')
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
305
306
    def test_branch_config_forcing_branch(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
307
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
308
            $ bzr config -d tree --scope branch --remove file
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
309
            $ bzr config -d tree --all file
5447.4.20 by Vincent Ladeuil
Indent inplace files.
310
            locations:
5533.1.1 by Vincent Ladeuil
Fix ``bzr config`` to respect policies when displaying values and also display sections when appropriate.
311
              [.../work/tree]
5447.4.20 by Vincent Ladeuil
Indent inplace files.
312
              file = locations
313
            bazaar:
314
              file = bazaar
315
            ''')
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
316
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
317
            $ bzr config -d tree --remove file
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
318
            $ bzr config -d tree --all file
5447.4.20 by Vincent Ladeuil
Indent inplace files.
319
            bazaar:
320
              file = bazaar
321
            ''')