~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
from bzrlib import (
21
    config,
22
    tests,
23
    )
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
24
from bzrlib.tests import (
25
    script,
26
    test_config as _t_config,
27
    )
5447.4.2 by Vincent Ladeuil
Implement the 'brz config' command. Read-only.
28
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
29
class TestWithoutConfig(tests.TestCaseWithTransport):
5447.4.2 by Vincent Ladeuil
Implement the 'brz config' command. Read-only.
30
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
31
    def test_config_all(self):
5447.4.2 by Vincent Ladeuil
Implement the 'brz config' command. Read-only.
32
        out, err = self.run_bzr(['config'])
33
        self.assertEquals('', out)
34
        self.assertEquals('', err)
35
5506.2.2 by Vincent Ladeuil
Raise an error if the option doesn't exist and --active is used.
36
    def test_remove_unknown_option(self):
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
37
        self.run_bzr_error(['The "file" configuration option does not exist',],
38
                           ['config', '--remove', 'file'])
5447.4.2 by Vincent Ladeuil
Implement the 'brz config' command. Read-only.
39
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
40
    def test_all_remove_exclusive(self):
41
        self.run_bzr_error(['--all and --remove are mutually exclusive.',],
42
                           ['config', '--remove', '--all'])
43
44
    def test_all_set_exclusive(self):
45
        self.run_bzr_error(['Only one option can be set.',],
46
                           ['config', '--all', 'hello=world'])
5506.2.1 by Vincent Ladeuil
Implements ``bzr config --active option`` displaying only the value.
47
5506.2.2 by Vincent Ladeuil
Raise an error if the option doesn't exist and --active is used.
48
    def test_remove_no_option(self):
5506.2.1 by Vincent Ladeuil
Implements ``bzr config --active option`` displaying only the value.
49
        self.run_bzr_error(['--remove expects an option to remove.',],
50
                           ['config', '--remove'])
51
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
52
    def test_unknown_option(self):
5506.2.2 by Vincent Ladeuil
Raise an error if the option doesn't exist and --active is used.
53
        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
54
                           ['config', 'file'])
55
56
    def test_unexpected_regexp(self):
57
        self.run_bzr_error(
58
            ['The "\*file" configuration option does not exist',],
59
            ['config', '*file'])
60
61
    def test_wrong_regexp(self):
62
        self.run_bzr_error(
63
            ['Invalid pattern\(s\) found. "\*file" nothing to repeat',],
64
            ['config', '--all', '*file'])
65
5506.2.2 by Vincent Ladeuil
Raise an error if the option doesn't exist and --active is used.
66
5506.2.1 by Vincent Ladeuil
Implements ``bzr config --active option`` displaying only the value.
67
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
68
class TestConfigDisplay(tests.TestCaseWithTransport):
69
70
    def setUp(self):
71
        super(TestConfigDisplay, self).setUp()
72
        _t_config.create_configs(self)
73
5533.2.1 by Vincent Ladeuil
``bzr config`` properly displays list values
74
    def test_multiline_all_values(self):
75
        self.bazaar_config.set_user_option('multiline', '1\n2\n')
5609.20.3 by Vincent Ladeuil
Fix pqm failures.
76
        # Fallout from bug 710410, the triple quotes have been toggled
77
        script.run_script(self, '''\
5533.2.1 by Vincent Ladeuil
``bzr config`` properly displays list values
78
            $ bzr config -d tree
79
            bazaar:
5609.20.3 by Vincent Ladeuil
Fix pqm failures.
80
              multiline = """1
5533.2.1 by Vincent Ladeuil
``bzr config`` properly displays list values
81
            2
5609.20.3 by Vincent Ladeuil
Fix pqm failures.
82
            """
83
            ''')
5533.2.1 by Vincent Ladeuil
``bzr config`` properly displays list values
84
85
    def test_multiline_value_only(self):
86
        self.bazaar_config.set_user_option('multiline', '1\n2\n')
5609.20.3 by Vincent Ladeuil
Fix pqm failures.
87
        # Fallout from bug 710410, the triple quotes have been toggled
88
        script.run_script(self, '''\
5533.2.1 by Vincent Ladeuil
``bzr config`` properly displays list values
89
            $ bzr config -d tree multiline
5609.20.3 by Vincent Ladeuil
Fix pqm failures.
90
            """1
5533.2.1 by Vincent Ladeuil
``bzr config`` properly displays list values
91
            2
5609.20.3 by Vincent Ladeuil
Fix pqm failures.
92
            """
93
            ''')
5533.2.1 by Vincent Ladeuil
``bzr config`` properly displays list values
94
95
    def test_list_all_values(self):
6260.3.1 by Vincent Ladeuil
Switch ``bzr config`` to the new config implementation
96
        # FIXME: we should register the option as a list or it's displayed as
97
        # astring and as such, quoted.
5533.2.1 by Vincent Ladeuil
``bzr config`` properly displays list values
98
        self.bazaar_config.set_user_option('list', [1, 'a', 'with, a comma'])
99
        script.run_script(self, '''\
100
            $ bzr config -d tree
101
            bazaar:
6260.3.1 by Vincent Ladeuil
Switch ``bzr config`` to the new config implementation
102
              list = '1, a, "with, a comma"'
5533.2.1 by Vincent Ladeuil
``bzr config`` properly displays list values
103
            ''')
104
105
    def test_list_value_only(self):
6260.3.1 by Vincent Ladeuil
Switch ``bzr config`` to the new config implementation
106
        # FIXME: we should register the option as a list or it's displayed as
107
        # astring and as such, quoted.
5533.2.1 by Vincent Ladeuil
``bzr config`` properly displays list values
108
        self.bazaar_config.set_user_option('list', [1, 'a', 'with, a comma'])
109
        script.run_script(self, '''\
110
            $ bzr config -d tree list
6260.3.1 by Vincent Ladeuil
Switch ``bzr config`` to the new config implementation
111
            '1, a, "with, a comma"'
5533.2.1 by Vincent Ladeuil
``bzr config`` properly displays list values
112
            ''')
113
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
114
    def test_bazaar_config(self):
115
        self.bazaar_config.set_user_option('hello', 'world')
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
116
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
117
            $ bzr config -d tree
118
            bazaar:
119
              hello = world
120
            ''')
5447.4.2 by Vincent Ladeuil
Implement the 'brz config' command. Read-only.
121
122
    def test_locations_config_for_branch(self):
123
        self.locations_config.set_user_option('hello', 'world')
124
        self.branch_config.set_user_option('hello', 'you')
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
125
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
126
            $ bzr config -d tree
127
            locations:
5533.1.1 by Vincent Ladeuil
Fix ``bzr config`` to respect policies when displaying values and also display sections when appropriate.
128
              [.../tree]
5447.4.20 by Vincent Ladeuil
Indent inplace files.
129
              hello = world
130
            branch:
131
              hello = you
132
            ''')
5447.4.2 by Vincent Ladeuil
Implement the 'brz config' command. Read-only.
133
134
    def test_locations_config_outside_branch(self):
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
135
        self.bazaar_config.set_user_option('hello', 'world')
5447.4.2 by Vincent Ladeuil
Implement the 'brz config' command. Read-only.
136
        self.locations_config.set_user_option('hello', 'world')
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
137
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
138
            $ bzr config
139
            bazaar:
140
              hello = world
141
            ''')
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
142
5533.1.1 by Vincent Ladeuil
Fix ``bzr config`` to respect policies when displaying values and also display sections when appropriate.
143
class TestConfigDisplayWithPolicy(tests.TestCaseWithTransport):
144
145
    def test_location_with_policy(self):
146
        # LocationConfig is the only one dealing with policies so far.
147
        self.make_branch_and_tree('tree')
148
        config_text = """\
149
[%(dir)s]
150
url = dir
151
url:policy = appendpath
152
[%(dir)s/tree]
153
url = tree
154
""" % {'dir': self.test_dir}
155
        # We don't use the config directly so we save it to disk
156
        config.LocationConfig.from_string(config_text, 'tree', save=True)
157
        # policies are displayed with their options since they are part of
158
        # their definition, likewise the path is not appended, we are just
159
        # presenting the relevant portions of the config files
160
        script.run_script(self, '''\
161
            $ bzr config -d tree --all url
162
            locations:
163
              [.../work/tree]
164
              url = tree
165
              [.../work]
166
              url = dir
167
              url:policy = appendpath
168
            ''')
169
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
170
5506.2.1 by Vincent Ladeuil
Implements ``bzr config --active option`` displaying only the value.
171
class TestConfigActive(tests.TestCaseWithTransport):
172
173
    def setUp(self):
174
        super(TestConfigActive, self).setUp()
175
        _t_config.create_configs_with_file_option(self)
176
177
    def test_active_in_locations(self):
178
        script.run_script(self, '''\
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
179
            $ bzr config -d tree file
5506.2.1 by Vincent Ladeuil
Implements ``bzr config --active option`` displaying only the value.
180
            locations
181
            ''')
182
183
    def test_active_in_bazaar(self):
184
        script.run_script(self, '''\
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
185
            $ bzr config -d tree --scope bazaar file
5506.2.1 by Vincent Ladeuil
Implements ``bzr config --active option`` displaying only the value.
186
            bazaar
187
            ''')
188
189
    def test_active_in_branch(self):
190
        # We need to delete the locations definition that overrides the branch
191
        # one
192
        script.run_script(self, '''\
6260.3.1 by Vincent Ladeuil
Switch ``bzr config`` to the new config implementation
193
            $ 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
194
            $ bzr config -d tree file
5506.2.1 by Vincent Ladeuil
Implements ``bzr config --active option`` displaying only the value.
195
            branch
196
            ''')
197
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
198
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
199
class TestConfigSetOption(tests.TestCaseWithTransport):
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
200
201
    def setUp(self):
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
202
        super(TestConfigSetOption, self).setUp()
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
203
        _t_config.create_configs(self)
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
204
205
    def test_unknown_config(self):
5447.4.10 by Vincent Ladeuil
Using dedicated exceptions feels cleaner.
206
        self.run_bzr_error(['The "moon" configuration does not exist'],
5447.4.17 by Vincent Ladeuil
Rename config --force to config --scope.
207
                           ['config', '--scope', 'moon', 'hello=world'])
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
208
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
209
    def test_bazaar_config_outside_branch(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
210
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
211
            $ bzr config --scope bazaar hello=world
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
212
            $ bzr config -d tree --all hello
5447.4.20 by Vincent Ladeuil
Indent inplace files.
213
            bazaar:
214
              hello = world
215
            ''')
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
216
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
217
    def test_bazaar_config_inside_branch(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
218
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
219
            $ 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
220
            $ bzr config -d tree --all hello
5447.4.20 by Vincent Ladeuil
Indent inplace files.
221
            bazaar:
222
              hello = world
223
            ''')
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
224
225
    def test_locations_config_inside_branch(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
226
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
227
            $ 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
228
            $ bzr config -d tree --all hello
5447.4.20 by Vincent Ladeuil
Indent inplace files.
229
            locations:
5533.1.1 by Vincent Ladeuil
Fix ``bzr config`` to respect policies when displaying values and also display sections when appropriate.
230
              [.../work/tree]
5447.4.20 by Vincent Ladeuil
Indent inplace files.
231
              hello = world
232
            ''')
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
233
234
    def test_branch_config_default(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
235
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
236
            $ bzr config -d tree hello=world
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
237
            $ bzr config -d tree --all hello
5447.4.20 by Vincent Ladeuil
Indent inplace files.
238
            branch:
239
              hello = world
240
            ''')
5447.4.5 by Vincent Ladeuil
Implement ``bzr config option=value``.
241
242
    def test_branch_config_forcing_branch(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
243
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
244
            $ 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
245
            $ bzr config -d tree --all hello
5447.4.20 by Vincent Ladeuil
Indent inplace files.
246
            branch:
247
              hello = world
248
            ''')
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
249
250
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
251
class TestConfigRemoveOption(tests.TestCaseWithTransport):
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
252
253
    def setUp(self):
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
254
        super(TestConfigRemoveOption, self).setUp()
5447.4.6 by Vincent Ladeuil
Start defining fixtures but we still have an unexpected sucessful test.
255
        _t_config.create_configs_with_file_option(self)
256
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
257
    def test_unknown_config(self):
258
        self.run_bzr_error(['The "moon" configuration does not exist'],
5447.4.17 by Vincent Ladeuil
Rename config --force to config --scope.
259
                           ['config', '--scope', 'moon', '--remove', 'file'])
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
260
261
    def test_bazaar_config_outside_branch(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
262
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
263
            $ bzr config --scope bazaar --remove file
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
264
            $ bzr config -d tree --all file
5447.4.20 by Vincent Ladeuil
Indent inplace files.
265
            locations:
5533.1.1 by Vincent Ladeuil
Fix ``bzr config`` to respect policies when displaying values and also display sections when appropriate.
266
              [.../work/tree]
5447.4.20 by Vincent Ladeuil
Indent inplace files.
267
              file = locations
268
            branch:
269
              file = branch
270
            ''')
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
271
272
    def test_bazaar_config_inside_branch(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
273
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
274
            $ 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
275
            $ bzr config -d tree --all file
5447.4.20 by Vincent Ladeuil
Indent inplace files.
276
            locations:
5533.1.1 by Vincent Ladeuil
Fix ``bzr config`` to respect policies when displaying values and also display sections when appropriate.
277
              [.../work/tree]
5447.4.20 by Vincent Ladeuil
Indent inplace files.
278
              file = locations
279
            branch:
280
              file = branch
281
            ''')
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
282
283
    def test_locations_config_inside_branch(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
284
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
285
            $ 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
286
            $ bzr config -d tree --all file
5447.4.20 by Vincent Ladeuil
Indent inplace files.
287
            branch:
288
              file = branch
289
            bazaar:
290
              file = bazaar
291
            ''')
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
292
293
    def test_branch_config_default(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
294
        script.run_script(self, '''\
6260.3.1 by Vincent Ladeuil
Switch ``bzr config`` to the new config implementation
295
            $ 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
296
            $ bzr config -d tree --all file
5447.4.20 by Vincent Ladeuil
Indent inplace files.
297
            branch:
298
              file = branch
299
            bazaar:
300
              file = bazaar
301
            ''')
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
302
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
303
            $ bzr config -d tree --remove file
5506.2.3 by Vincent Ladeuil
Take review comments into account and drive-by fix bug #670251
304
            $ bzr config -d tree --all file
5447.4.20 by Vincent Ladeuil
Indent inplace files.
305
            bazaar:
306
              file = bazaar
307
            ''')
5447.4.11 by Vincent Ladeuil
Implement ``bzr config --remove <option>``.
308
309
    def test_branch_config_forcing_branch(self):
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
310
        script.run_script(self, '''\
5447.4.20 by Vincent Ladeuil
Indent inplace files.
311
            $ 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
312
            $ bzr config -d tree --all file
5447.4.20 by Vincent Ladeuil
Indent inplace files.
313
            locations:
5533.1.1 by Vincent Ladeuil
Fix ``bzr config`` to respect policies when displaying values and also display sections when appropriate.
314
              [.../work/tree]
5447.4.20 by Vincent Ladeuil
Indent inplace files.
315
              file = locations
316
            bazaar:
317
              file = bazaar
318
            ''')
5447.4.18 by Vincent Ladeuil
Use a coherent script syntax.
319
        script.run_script(self, '''\
6260.3.1 by Vincent Ladeuil
Switch ``bzr config`` to the new config implementation
320
            $ 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
321
            $ bzr config -d tree --all file
5447.4.20 by Vincent Ladeuil
Indent inplace files.
322
            bazaar:
323
              file = bazaar
324
            ''')
6270.1.2 by Jelmer Vernooij
Add test for number of roundtrips of 'bzr config -d'.
325
326
327
class TestSmartServerConfig(tests.TestCaseWithTransport):
328
329
    def test_simple_branch_config(self):
330
        self.setup_smart_server_with_call_log()
331
        t = self.make_branch_and_tree('branch')
332
        self.reset_smart_call_log()
333
        out, err = self.run_bzr(['config', '-d', self.get_url('branch')])
334
        # This figure represent the amount of work to perform this use case. It
335
        # is entirely ok to reduce this number if a test fails due to rpc_count
336
        # being too low. If rpc_count increases, more network roundtrips have
337
        # become necessary for this use case. Please do not adjust this number
338
        # upwards without agreement from bzr's network support maintainers.
339
        self.assertLength(5, self.hpss_calls)