~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')
5609.20.3 by Vincent Ladeuil
Fix pqm failures.
79
        # Fallout from bug 710410, the triple quotes have been toggled
80
        script.run_script(self, '''\
5533.2.1 by Vincent Ladeuil
``bzr config`` properly displays list values
81
            $ bzr config -d tree
82
            bazaar:
5609.20.3 by Vincent Ladeuil
Fix pqm failures.
83
              multiline = """1
5533.2.1 by Vincent Ladeuil
``bzr config`` properly displays list values
84
            2
5609.20.3 by Vincent Ladeuil
Fix pqm failures.
85
            """
86
            ''')
5533.2.1 by Vincent Ladeuil
``bzr config`` properly displays list values
87
88
    def test_multiline_value_only(self):
89
        self.bazaar_config.set_user_option('multiline', '1\n2\n')
5609.20.3 by Vincent Ladeuil
Fix pqm failures.
90
        # Fallout from bug 710410, the triple quotes have been toggled
91
        script.run_script(self, '''\
5533.2.1 by Vincent Ladeuil
``bzr config`` properly displays list values
92
            $ bzr config -d tree multiline
5609.20.3 by Vincent Ladeuil
Fix pqm failures.
93
            """1
5533.2.1 by Vincent Ladeuil
``bzr config`` properly displays list values
94
            2
5609.20.3 by Vincent Ladeuil
Fix pqm failures.
95
            """
96
            ''')
5533.2.1 by Vincent Ladeuil
``bzr config`` properly displays list values
97
98
    def test_list_all_values(self):
99
        self.bazaar_config.set_user_option('list', [1, 'a', 'with, a comma'])
100
        script.run_script(self, '''\
101
            $ bzr config -d tree
102
            bazaar:
103
              list = 1, a, "with, a comma"
104
            ''')
105
106
    def test_list_value_only(self):
107
        self.bazaar_config.set_user_option('list', [1, 'a', 'with, a comma'])
108
        script.run_script(self, '''\
109
            $ bzr config -d tree list
110
            1, a, "with, a comma"
111
            ''')
112
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
113
    def test_bazaar_config(self):
114
        self.bazaar_config.set_user_option('hello', 'world')
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
115
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
116
            $ bzr config -d tree
117
            bazaar:
118
              hello = world
119
            ''')
5447.4.2 by Vincent Ladeuil
Implement the 'brz config' command. Read-only.
120
121
    def test_locations_config_for_branch(self):
122
        self.locations_config.set_user_option('hello', 'world')
123
        self.branch_config.set_user_option('hello', 'you')
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
124
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
125
            $ bzr config -d tree
126
            locations:
5533.1.1 by Vincent Ladeuil
Fix ``bzr config`` to respect policies when displaying values and also display sections when appropriate.
127
              [.../tree]
5447.4.20 by Vincent Ladeuil
Indent inplace files.
128
              hello = world
129
            branch:
130
              hello = you
131
            ''')
5447.4.2 by Vincent Ladeuil
Implement the 'brz config' command. Read-only.
132
133
    def test_locations_config_outside_branch(self):
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
134
        self.bazaar_config.set_user_option('hello', 'world')
5447.4.2 by Vincent Ladeuil
Implement the 'brz config' command. Read-only.
135
        self.locations_config.set_user_option('hello', 'world')
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
136
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
137
            $ bzr config
138
            bazaar:
139
              hello = world
140
            ''')
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
141
5533.1.1 by Vincent Ladeuil
Fix ``bzr config`` to respect policies when displaying values and also display sections when appropriate.
142
class TestConfigDisplayWithPolicy(tests.TestCaseWithTransport):
143
144
    def test_location_with_policy(self):
145
        # LocationConfig is the only one dealing with policies so far.
146
        self.make_branch_and_tree('tree')
147
        config_text = """\
148
[%(dir)s]
149
url = dir
150
url:policy = appendpath
151
[%(dir)s/tree]
152
url = tree
153
""" % {'dir': self.test_dir}
154
        # We don't use the config directly so we save it to disk
155
        config.LocationConfig.from_string(config_text, 'tree', save=True)
156
        # policies are displayed with their options since they are part of
157
        # their definition, likewise the path is not appended, we are just
158
        # presenting the relevant portions of the config files
159
        script.run_script(self, '''\
160
            $ bzr config -d tree --all url
161
            locations:
162
              [.../work/tree]
163
              url = tree
164
              [.../work]
165
              url = dir
166
              url:policy = appendpath
167
            ''')
168
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
169
5506.2.1 by Vincent Ladeuil
Implements ``bzr config --active option`` displaying only the value.
170
class TestConfigActive(tests.TestCaseWithTransport):
171
172
    def setUp(self):
173
        super(TestConfigActive, self).setUp()
174
        _t_config.create_configs_with_file_option(self)
175
176
    def test_active_in_locations(self):
177
        script.run_script(self, '''\
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
178
            $ bzr config -d tree file
5506.2.1 by Vincent Ladeuil
Implements ``bzr config --active option`` displaying only the value.
179
            locations
180
            ''')
181
182
    def test_active_in_bazaar(self):
183
        script.run_script(self, '''\
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
184
            $ bzr config -d tree --scope bazaar file
5506.2.1 by Vincent Ladeuil
Implements ``bzr config --active option`` displaying only the value.
185
            bazaar
186
            ''')
187
188
    def test_active_in_branch(self):
189
        # We need to delete the locations definition that overrides the branch
190
        # one
191
        script.run_script(self, '''\
192
            $ bzr config -d tree --remove file
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
193
            $ bzr config -d tree file
5506.2.1 by Vincent Ladeuil
Implements ``bzr config --active option`` displaying only the value.
194
            branch
195
            ''')
196
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
197
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
198
class TestConfigSetOption(tests.TestCaseWithTransport):
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
199
200
    def setUp(self):
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
201
        super(TestConfigSetOption, self).setUp()
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
202
        _t_config.create_configs(self)
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
203
204
    def test_unknown_config(self):
5447.4.10 by Vincent Ladeuil
Using dedicated exceptions feels cleaner.
205
        self.run_bzr_error(['The "moon" configuration does not exist'],
5447.4.17 by Vincent Ladeuil
Rename config --force to config --scope.
206
                           ['config', '--scope', 'moon', 'hello=world'])
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
207
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
208
    def test_bazaar_config_outside_branch(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
209
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
210
            $ bzr config --scope bazaar hello=world
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
211
            $ bzr config -d tree --all hello
5447.4.20 by Vincent Ladeuil
Indent inplace files.
212
            bazaar:
213
              hello = world
214
            ''')
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
215
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
216
    def test_bazaar_config_inside_branch(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
217
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
218
            $ 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
219
            $ bzr config -d tree --all hello
5447.4.20 by Vincent Ladeuil
Indent inplace files.
220
            bazaar:
221
              hello = world
222
            ''')
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
223
224
    def test_locations_config_inside_branch(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
225
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
226
            $ 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
227
            $ bzr config -d tree --all hello
5447.4.20 by Vincent Ladeuil
Indent inplace files.
228
            locations:
5533.1.1 by Vincent Ladeuil
Fix ``bzr config`` to respect policies when displaying values and also display sections when appropriate.
229
              [.../work/tree]
5447.4.20 by Vincent Ladeuil
Indent inplace files.
230
              hello = world
231
            ''')
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
232
233
    def test_branch_config_default(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
234
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
235
            $ bzr config -d tree hello=world
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
236
            $ bzr config -d tree --all hello
5447.4.20 by Vincent Ladeuil
Indent inplace files.
237
            branch:
238
              hello = world
239
            ''')
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
240
241
    def test_branch_config_forcing_branch(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
242
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
243
            $ 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
244
            $ bzr config -d tree --all hello
5447.4.20 by Vincent Ladeuil
Indent inplace files.
245
            branch:
246
              hello = world
247
            ''')
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
248
249
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
250
class TestConfigRemoveOption(tests.TestCaseWithTransport):
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
251
252
    def setUp(self):
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
253
        super(TestConfigRemoveOption, self).setUp()
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
254
        _t_config.create_configs_with_file_option(self)
255
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
256
    def test_unknown_config(self):
257
        self.run_bzr_error(['The "moon" configuration does not exist'],
5447.4.17 by Vincent Ladeuil
Rename config --force to config --scope.
258
                           ['config', '--scope', 'moon', '--remove', 'file'])
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
259
260
    def test_bazaar_config_outside_branch(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
261
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
262
            $ bzr config --scope bazaar --remove file
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
263
            $ bzr config -d tree --all file
5447.4.20 by Vincent Ladeuil
Indent inplace files.
264
            locations:
5533.1.1 by Vincent Ladeuil
Fix ``bzr config`` to respect policies when displaying values and also display sections when appropriate.
265
              [.../work/tree]
5447.4.20 by Vincent Ladeuil
Indent inplace files.
266
              file = locations
267
            branch:
268
              file = branch
269
            ''')
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
270
271
    def test_bazaar_config_inside_branch(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
272
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
273
            $ 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
274
            $ bzr config -d tree --all file
5447.4.20 by Vincent Ladeuil
Indent inplace files.
275
            locations:
5533.1.1 by Vincent Ladeuil
Fix ``bzr config`` to respect policies when displaying values and also display sections when appropriate.
276
              [.../work/tree]
5447.4.20 by Vincent Ladeuil
Indent inplace files.
277
              file = locations
278
            branch:
279
              file = branch
280
            ''')
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
281
282
    def test_locations_config_inside_branch(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
283
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
284
            $ 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
285
            $ bzr config -d tree --all file
5447.4.20 by Vincent Ladeuil
Indent inplace files.
286
            branch:
287
              file = branch
288
            bazaar:
289
              file = bazaar
290
            ''')
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
291
292
    def test_branch_config_default(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
293
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
294
            $ bzr config -d tree --remove file
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
295
            $ bzr config -d tree --all file
5447.4.20 by Vincent Ladeuil
Indent inplace files.
296
            branch:
297
              file = branch
298
            bazaar:
299
              file = bazaar
300
            ''')
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
301
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
302
            $ bzr config -d tree --remove file
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
303
            $ bzr config -d tree --all file
5447.4.20 by Vincent Ladeuil
Indent inplace files.
304
            bazaar:
305
              file = bazaar
306
            ''')
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
307
308
    def test_branch_config_forcing_branch(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
309
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
310
            $ 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
311
            $ bzr config -d tree --all file
5447.4.20 by Vincent Ladeuil
Indent inplace files.
312
            locations:
5533.1.1 by Vincent Ladeuil
Fix ``bzr config`` to respect policies when displaying values and also display sections when appropriate.
313
              [.../work/tree]
5447.4.20 by Vincent Ladeuil
Indent inplace files.
314
              file = locations
315
            bazaar:
316
              file = bazaar
317
            ''')
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
318
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
319
            $ bzr config -d tree --remove file
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
320
            $ bzr config -d tree --all file
5447.4.20 by Vincent Ladeuil
Indent inplace files.
321
            bazaar:
322
              file = bazaar
323
            ''')