~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2011-05-11 11:35:28 UTC
  • mto: This revision was merged to the branch mainline in revision 5851.
  • Revision ID: john@arbash-meinel.com-20110511113528-qepibuwxicjrbb2h
Break compatibility with python <2.6.

This includes auditing the code for places where we were doing
explicit 'sys.version' checks and removing them as appropriate.

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
        # Fallout from bug 710410, the triple quotes have been toggled
 
80
        script.run_script(self, '''\
 
81
            $ bzr config -d tree
 
82
            bazaar:
 
83
              multiline = """1
 
84
            2
 
85
            """
 
86
            ''')
 
87
 
 
88
    def test_multiline_value_only(self):
 
89
        self.bazaar_config.set_user_option('multiline', '1\n2\n')
 
90
        # Fallout from bug 710410, the triple quotes have been toggled
 
91
        script.run_script(self, '''\
 
92
            $ bzr config -d tree multiline
 
93
            """1
 
94
            2
 
95
            """
 
96
            ''')
 
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
 
 
113
    def test_bazaar_config(self):
 
114
        self.bazaar_config.set_user_option('hello', 'world')
 
115
        script.run_script(self, '''\
 
116
            $ bzr config -d tree
 
117
            bazaar:
 
118
              hello = world
 
119
            ''')
 
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')
 
124
        script.run_script(self, '''\
 
125
            $ bzr config -d tree
 
126
            locations:
 
127
              [.../tree]
 
128
              hello = world
 
129
            branch:
 
130
              hello = you
 
131
            ''')
 
132
 
 
133
    def test_locations_config_outside_branch(self):
 
134
        self.bazaar_config.set_user_option('hello', 'world')
 
135
        self.locations_config.set_user_option('hello', 'world')
 
136
        script.run_script(self, '''\
 
137
            $ bzr config
 
138
            bazaar:
 
139
              hello = world
 
140
            ''')
 
141
 
 
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
 
 
169
 
 
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, '''\
 
178
            $ bzr config -d tree file
 
179
            locations
 
180
            ''')
 
181
 
 
182
    def test_active_in_bazaar(self):
 
183
        script.run_script(self, '''\
 
184
            $ bzr config -d tree --scope bazaar file
 
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
 
193
            $ bzr config -d tree file
 
194
            branch
 
195
            ''')
 
196
 
 
197
 
 
198
class TestConfigSetOption(tests.TestCaseWithTransport):
 
199
 
 
200
    def setUp(self):
 
201
        super(TestConfigSetOption, self).setUp()
 
202
        _t_config.create_configs(self)
 
203
 
 
204
    def test_unknown_config(self):
 
205
        self.run_bzr_error(['The "moon" configuration does not exist'],
 
206
                           ['config', '--scope', 'moon', 'hello=world'])
 
207
 
 
208
    def test_bazaar_config_outside_branch(self):
 
209
        script.run_script(self, '''\
 
210
            $ bzr config --scope bazaar hello=world
 
211
            $ bzr config -d tree --all hello
 
212
            bazaar:
 
213
              hello = world
 
214
            ''')
 
215
 
 
216
    def test_bazaar_config_inside_branch(self):
 
217
        script.run_script(self, '''\
 
218
            $ bzr config -d tree --scope bazaar hello=world
 
219
            $ bzr config -d tree --all hello
 
220
            bazaar:
 
221
              hello = world
 
222
            ''')
 
223
 
 
224
    def test_locations_config_inside_branch(self):
 
225
        script.run_script(self, '''\
 
226
            $ bzr config -d tree --scope locations hello=world
 
227
            $ bzr config -d tree --all hello
 
228
            locations:
 
229
              [.../work/tree]
 
230
              hello = world
 
231
            ''')
 
232
 
 
233
    def test_branch_config_default(self):
 
234
        script.run_script(self, '''\
 
235
            $ bzr config -d tree hello=world
 
236
            $ bzr config -d tree --all hello
 
237
            branch:
 
238
              hello = world
 
239
            ''')
 
240
 
 
241
    def test_branch_config_forcing_branch(self):
 
242
        script.run_script(self, '''\
 
243
            $ bzr config -d tree --scope branch hello=world
 
244
            $ bzr config -d tree --all hello
 
245
            branch:
 
246
              hello = world
 
247
            ''')
 
248
 
 
249
 
 
250
class TestConfigRemoveOption(tests.TestCaseWithTransport):
 
251
 
 
252
    def setUp(self):
 
253
        super(TestConfigRemoveOption, self).setUp()
 
254
        _t_config.create_configs_with_file_option(self)
 
255
 
 
256
    def test_unknown_config(self):
 
257
        self.run_bzr_error(['The "moon" configuration does not exist'],
 
258
                           ['config', '--scope', 'moon', '--remove', 'file'])
 
259
 
 
260
    def test_bazaar_config_outside_branch(self):
 
261
        script.run_script(self, '''\
 
262
            $ bzr config --scope bazaar --remove file
 
263
            $ bzr config -d tree --all file
 
264
            locations:
 
265
              [.../work/tree]
 
266
              file = locations
 
267
            branch:
 
268
              file = branch
 
269
            ''')
 
270
 
 
271
    def test_bazaar_config_inside_branch(self):
 
272
        script.run_script(self, '''\
 
273
            $ bzr config -d tree --scope bazaar --remove file
 
274
            $ bzr config -d tree --all file
 
275
            locations:
 
276
              [.../work/tree]
 
277
              file = locations
 
278
            branch:
 
279
              file = branch
 
280
            ''')
 
281
 
 
282
    def test_locations_config_inside_branch(self):
 
283
        script.run_script(self, '''\
 
284
            $ bzr config -d tree --scope locations --remove file
 
285
            $ bzr config -d tree --all file
 
286
            branch:
 
287
              file = branch
 
288
            bazaar:
 
289
              file = bazaar
 
290
            ''')
 
291
 
 
292
    def test_branch_config_default(self):
 
293
        script.run_script(self, '''\
 
294
            $ bzr config -d tree --remove file
 
295
            $ bzr config -d tree --all file
 
296
            branch:
 
297
              file = branch
 
298
            bazaar:
 
299
              file = bazaar
 
300
            ''')
 
301
        script.run_script(self, '''\
 
302
            $ bzr config -d tree --remove file
 
303
            $ bzr config -d tree --all file
 
304
            bazaar:
 
305
              file = bazaar
 
306
            ''')
 
307
 
 
308
    def test_branch_config_forcing_branch(self):
 
309
        script.run_script(self, '''\
 
310
            $ bzr config -d tree --scope branch --remove file
 
311
            $ bzr config -d tree --all file
 
312
            locations:
 
313
              [.../work/tree]
 
314
              file = locations
 
315
            bazaar:
 
316
              file = bazaar
 
317
            ''')
 
318
        script.run_script(self, '''\
 
319
            $ bzr config -d tree --remove file
 
320
            $ bzr config -d tree --all file
 
321
            bazaar:
 
322
              file = bazaar
 
323
            ''')