/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2005, 2006 Canonical Ltd
1442.1.1 by Robert Collins
move config_dir into bzrlib.config
2
#   Authors: Robert Collins <robert.collins@canonical.com>
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18
"""Tests for finding and reading the bzr config file[s]."""
19
# import system imports here
1474 by Robert Collins
Merge from Aaron Bentley.
20
from bzrlib.util.configobj.configobj import ConfigObj, ConfigObjError
1442.1.2 by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing.
21
from cStringIO import StringIO
1442.1.1 by Robert Collins
move config_dir into bzrlib.config
22
import os
23
import sys
24
25
#import bzrlib specific imports here
1878.1.3 by John Arbash Meinel
some test cleanups
26
from bzrlib import (
27
    config,
28
    errors,
29
    osutils,
30
    urlutils,
1551.15.35 by Aaron Bentley
Warn when setting config values that will be masked (#122286)
31
    trace,
1878.1.3 by John Arbash Meinel
some test cleanups
32
    )
1770.2.9 by Aaron Bentley
Add Branch.get_config, update BranchConfig() callers
33
from bzrlib.branch import Branch
34
from bzrlib.bzrdir import BzrDir
1824.1.1 by Robert Collins
Add BranchConfig.has_explicit_nickname call.
35
from bzrlib.tests import TestCase, TestCaseInTempDir, TestCaseWithTransport
1442.1.1 by Robert Collins
move config_dir into bzrlib.config
36
37
1553.6.12 by Erik Bågfors
remove AliasConfig, based on input from abentley
38
sample_long_alias="log -r-15..-1 --line"
2120.6.2 by James Henstridge
remove get_matching_sections() norecurse tests, since that feature is handled in the config policy code now
39
sample_config_text = u"""
40
[DEFAULT]
41
email=Erik B\u00e5gfors <erik@bagfors.nu>
42
editor=vim
43
gpg_signing_command=gnome-gpg
44
log_format=short
45
user_global_option=something
46
[ALIASES]
47
h=help
48
ll=""" + sample_long_alias + "\n"
49
50
51
sample_always_signatures = """
52
[DEFAULT]
53
check_signatures=ignore
54
create_signatures=always
55
"""
56
57
sample_ignore_signatures = """
58
[DEFAULT]
59
check_signatures=require
60
create_signatures=never
61
"""
62
63
sample_maybe_signatures = """
64
[DEFAULT]
65
check_signatures=ignore
66
create_signatures=when-required
67
"""
68
69
sample_branches_text = """
70
[http://www.example.com]
71
# Top level policy
72
email=Robert Collins <robertc@example.org>
2120.6.3 by James Henstridge
add some more tests for getting policy options, and behaviour of get_user_option in the presence of config policies
73
normal_option = normal
74
appendpath_option = append
2120.6.8 by James Henstridge
Change syntax for setting config option policies. Rather than
75
appendpath_option:policy = appendpath
2120.6.3 by James Henstridge
add some more tests for getting policy options, and behaviour of get_user_option in the presence of config policies
76
norecurse_option = norecurse
2120.6.8 by James Henstridge
Change syntax for setting config option policies. Rather than
77
norecurse_option:policy = norecurse
2120.6.2 by James Henstridge
remove get_matching_sections() norecurse tests, since that feature is handled in the config policy code now
78
[http://www.example.com/ignoreparent]
79
# different project: ignore parent dir config
80
ignore_parents=true
81
[http://www.example.com/norecurse]
82
# configuration items that only apply to this dir
83
recurse=false
2120.6.3 by James Henstridge
add some more tests for getting policy options, and behaviour of get_user_option in the presence of config policies
84
normal_option = norecurse
85
[http://www.example.com/dir]
86
appendpath_option = normal
2120.6.2 by James Henstridge
remove get_matching_sections() norecurse tests, since that feature is handled in the config policy code now
87
[/b/]
88
check_signatures=require
89
# test trailing / matching with no children
90
[/a/]
91
check_signatures=check-available
92
gpg_signing_command=false
93
user_local_option=local
94
# test trailing / matching
95
[/a/*]
96
#subdirs will match but not the parent
97
[/a/c]
98
check_signatures=ignore
99
post_commit=bzrlib.tests.test_config.post_commit
100
#testing explicit beats globs
101
"""
1553.6.3 by Erik Bågfors
tests for AliasesConfig
102
1442.1.8 by Robert Collins
preparing some tests for LocationConfig
103
1474 by Robert Collins
Merge from Aaron Bentley.
104
class InstrumentedConfigObj(object):
105
    """A config obj look-enough-alike to record calls made to it."""
106
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
107
    def __contains__(self, thing):
108
        self._calls.append(('__contains__', thing))
109
        return False
110
111
    def __getitem__(self, key):
112
        self._calls.append(('__getitem__', key))
113
        return self
114
1551.2.20 by Aaron Bentley
Treated config files as utf-8
115
    def __init__(self, input, encoding=None):
116
        self._calls = [('__init__', input, encoding)]
1442.1.2 by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing.
117
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
118
    def __setitem__(self, key, value):
119
        self._calls.append(('__setitem__', key, value))
120
2120.6.4 by James Henstridge
add support for specifying policy when storing options
121
    def __delitem__(self, key):
122
        self._calls.append(('__delitem__', key))
123
124
    def keys(self):
125
        self._calls.append(('keys',))
126
        return []
127
1551.2.49 by abentley
Made ConfigObj output binary-identical files on win32 and *nix
128
    def write(self, arg):
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
129
        self._calls.append(('write',))
130
2120.6.4 by James Henstridge
add support for specifying policy when storing options
131
    def as_bool(self, value):
132
        self._calls.append(('as_bool', value))
133
        return False
134
135
    def get_value(self, section, name):
136
        self._calls.append(('get_value', section, name))
137
        return None
138
1442.1.2 by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing.
139
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
140
class FakeBranch(object):
141
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
142
    def __init__(self, base=None, user_id=None):
143
        if base is None:
144
            self.base = "http://example.com/branches/demo"
145
        else:
146
            self.base = base
147
        self.control_files = FakeControlFiles(user_id=user_id)
148
149
    def lock_write(self):
150
        pass
151
152
    def unlock(self):
153
        pass
1185.65.11 by Robert Collins
Disable inheritance for getting at LockableFiles, rather use composition.
154
155
156
class FakeControlFiles(object):
157
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
158
    def __init__(self, user_id=None):
159
        self.email = user_id
160
        self.files = {}
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
161
1185.65.29 by Robert Collins
Implement final review suggestions.
162
    def get_utf8(self, filename):
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
163
        if filename != 'email':
164
            raise NotImplementedError
165
        if self.email is not None:
166
            return StringIO(self.email)
1185.31.45 by John Arbash Meinel
Refactoring Exceptions found some places where the wrong exception was caught.
167
        raise errors.NoSuchFile(filename)
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
168
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
169
    def get(self, filename):
1770.2.6 by Aaron Bentley
Ensure branch.conf works properly
170
        try:
171
            return StringIO(self.files[filename])
172
        except KeyError:
173
            raise errors.NoSuchFile(filename)
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
174
175
    def put(self, filename, fileobj):
1770.2.6 by Aaron Bentley
Ensure branch.conf works properly
176
        self.files[filename] = fileobj.read()
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
177
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
178
179
class InstrumentedConfig(config.Config):
180
    """An instrumented config that supplies stubs for template methods."""
181
    
182
    def __init__(self):
183
        super(InstrumentedConfig, self).__init__()
184
        self._calls = []
1442.1.15 by Robert Collins
make getting the signature checking policy a template method
185
        self._signatures = config.CHECK_NEVER
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
186
187
    def _get_user_id(self):
188
        self._calls.append('_get_user_id')
189
        return "Robert Collins <robert.collins@example.org>"
190
1442.1.15 by Robert Collins
make getting the signature checking policy a template method
191
    def _get_signature_checking(self):
192
        self._calls.append('_get_signature_checking')
193
        return self._signatures
194
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
195
1556.2.2 by Aaron Bentley
Fixed get_bool
196
bool_config = """[DEFAULT]
197
active = true
198
inactive = false
199
[UPPERCASE]
200
active = True
201
nonactive = False
202
"""
203
class TestConfigObj(TestCase):
204
    def test_get_bool(self):
205
        from bzrlib.config import ConfigObj
206
        co = ConfigObj(StringIO(bool_config))
207
        self.assertIs(co.get_bool('DEFAULT', 'active'), True)
208
        self.assertIs(co.get_bool('DEFAULT', 'inactive'), False)
209
        self.assertIs(co.get_bool('UPPERCASE', 'active'), True)
210
        self.assertIs(co.get_bool('UPPERCASE', 'nonactive'), False)
211
212
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
213
class TestConfig(TestCase):
214
215
    def test_constructs(self):
216
        config.Config()
217
 
218
    def test_no_default_editor(self):
219
        self.assertRaises(NotImplementedError, config.Config().get_editor)
220
221
    def test_user_email(self):
222
        my_config = InstrumentedConfig()
223
        self.assertEqual('robert.collins@example.org', my_config.user_email())
224
        self.assertEqual(['_get_user_id'], my_config._calls)
225
226
    def test_username(self):
227
        my_config = InstrumentedConfig()
228
        self.assertEqual('Robert Collins <robert.collins@example.org>',
229
                         my_config.username())
230
        self.assertEqual(['_get_user_id'], my_config._calls)
1442.1.14 by Robert Collins
Create a default signature checking policy of CHECK_IF_POSSIBLE
231
232
    def test_signatures_default(self):
233
        my_config = config.Config()
1770.2.1 by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this
234
        self.assertFalse(my_config.signature_needed())
1442.1.14 by Robert Collins
Create a default signature checking policy of CHECK_IF_POSSIBLE
235
        self.assertEqual(config.CHECK_IF_POSSIBLE,
236
                         my_config.signature_checking())
1770.2.1 by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this
237
        self.assertEqual(config.SIGN_WHEN_REQUIRED,
238
                         my_config.signing_policy())
1442.1.14 by Robert Collins
Create a default signature checking policy of CHECK_IF_POSSIBLE
239
1442.1.15 by Robert Collins
make getting the signature checking policy a template method
240
    def test_signatures_template_method(self):
241
        my_config = InstrumentedConfig()
242
        self.assertEqual(config.CHECK_NEVER, my_config.signature_checking())
243
        self.assertEqual(['_get_signature_checking'], my_config._calls)
244
245
    def test_signatures_template_method_none(self):
246
        my_config = InstrumentedConfig()
247
        my_config._signatures = None
248
        self.assertEqual(config.CHECK_IF_POSSIBLE,
249
                         my_config.signature_checking())
250
        self.assertEqual(['_get_signature_checking'], my_config._calls)
251
1442.1.56 by Robert Collins
gpg_signing_command configuration item
252
    def test_gpg_signing_command_default(self):
253
        my_config = config.Config()
254
        self.assertEqual('gpg', my_config.gpg_signing_command())
255
1442.1.69 by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name.
256
    def test_get_user_option_default(self):
257
        my_config = config.Config()
258
        self.assertEqual(None, my_config.get_user_option('no_option'))
259
1472 by Robert Collins
post commit hook, first pass implementation
260
    def test_post_commit_default(self):
261
        my_config = config.Config()
262
        self.assertEqual(None, my_config.post_commit())
263
1553.2.9 by Erik Bågfors
log_formatter => log_format for "named" formatters
264
    def test_log_format_default(self):
1553.2.8 by Erik Bågfors
tests for config log_formatter
265
        my_config = config.Config()
1553.2.9 by Erik Bågfors
log_formatter => log_format for "named" formatters
266
        self.assertEqual('long', my_config.log_format())
1553.2.8 by Erik Bågfors
tests for config log_formatter
267
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
268
1442.1.1 by Robert Collins
move config_dir into bzrlib.config
269
class TestConfigPath(TestCase):
270
1442.1.2 by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing.
271
    def setUp(self):
272
        super(TestConfigPath, self).setUp()
273
        os.environ['HOME'] = '/home/bogus'
2309.2.6 by Alexander Belchenko
bzr now use Win32 API to determine Application Data location, and don't rely solely on $APPDATA
274
        if sys.platform == 'win32':
275
            os.environ['BZR_HOME'] = \
276
                r'C:\Documents and Settings\bogus\Application Data'
1442.1.2 by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing.
277
1442.1.1 by Robert Collins
move config_dir into bzrlib.config
278
    def test_config_dir(self):
1185.38.1 by John Arbash Meinel
Adding my win32 patch for moving the home directory.
279
        if sys.platform == 'win32':
280
            self.assertEqual(config.config_dir(), 
1185.31.36 by John Arbash Meinel
Fixup test_config.py to handle new paths
281
                'C:/Documents and Settings/bogus/Application Data/bazaar/2.0')
1185.38.1 by John Arbash Meinel
Adding my win32 patch for moving the home directory.
282
        else:
283
            self.assertEqual(config.config_dir(), '/home/bogus/.bazaar')
1442.1.2 by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing.
284
285
    def test_config_filename(self):
1185.38.1 by John Arbash Meinel
Adding my win32 patch for moving the home directory.
286
        if sys.platform == 'win32':
287
            self.assertEqual(config.config_filename(), 
1185.31.36 by John Arbash Meinel
Fixup test_config.py to handle new paths
288
                'C:/Documents and Settings/bogus/Application Data/bazaar/2.0/bazaar.conf')
1185.38.1 by John Arbash Meinel
Adding my win32 patch for moving the home directory.
289
        else:
290
            self.assertEqual(config.config_filename(),
291
                             '/home/bogus/.bazaar/bazaar.conf')
1442.1.2 by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing.
292
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
293
    def test_branches_config_filename(self):
1185.38.1 by John Arbash Meinel
Adding my win32 patch for moving the home directory.
294
        if sys.platform == 'win32':
295
            self.assertEqual(config.branches_config_filename(), 
1185.31.36 by John Arbash Meinel
Fixup test_config.py to handle new paths
296
                'C:/Documents and Settings/bogus/Application Data/bazaar/2.0/branches.conf')
1185.38.1 by John Arbash Meinel
Adding my win32 patch for moving the home directory.
297
        else:
298
            self.assertEqual(config.branches_config_filename(),
299
                             '/home/bogus/.bazaar/branches.conf')
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
300
1770.2.2 by Aaron Bentley
Rename branches.conf to locations.conf
301
    def test_locations_config_filename(self):
302
        if sys.platform == 'win32':
303
            self.assertEqual(config.locations_config_filename(), 
304
                'C:/Documents and Settings/bogus/Application Data/bazaar/2.0/locations.conf')
305
        else:
306
            self.assertEqual(config.locations_config_filename(),
307
                             '/home/bogus/.bazaar/locations.conf')
308
1442.1.18 by Robert Collins
permit per branch location overriding of signature checking policy
309
class TestIniConfig(TestCase):
310
311
    def test_contructs(self):
312
        my_config = config.IniBasedConfig("nothing")
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
313
1442.1.2 by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing.
314
    def test_from_fp(self):
1551.2.20 by Aaron Bentley
Treated config files as utf-8
315
        config_file = StringIO(sample_config_text.encode('utf-8'))
1442.1.18 by Robert Collins
permit per branch location overriding of signature checking policy
316
        my_config = config.IniBasedConfig(None)
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
317
        self.failUnless(
1442.1.18 by Robert Collins
permit per branch location overriding of signature checking policy
318
            isinstance(my_config._get_parser(file=config_file),
1474 by Robert Collins
Merge from Aaron Bentley.
319
                        ConfigObj))
1442.1.2 by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing.
320
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
321
    def test_cached(self):
1551.2.20 by Aaron Bentley
Treated config files as utf-8
322
        config_file = StringIO(sample_config_text.encode('utf-8'))
1442.1.18 by Robert Collins
permit per branch location overriding of signature checking policy
323
        my_config = config.IniBasedConfig(None)
324
        parser = my_config._get_parser(file=config_file)
325
        self.failUnless(my_config._get_parser() is parser)
326
327
328
class TestGetConfig(TestCase):
329
330
    def test_constructs(self):
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
331
        my_config = config.GlobalConfig()
332
1442.1.2 by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing.
333
    def test_calls_read_filenames(self):
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
334
        # replace the class that is constructured, to check its parameters
1474 by Robert Collins
Merge from Aaron Bentley.
335
        oldparserclass = config.ConfigObj
336
        config.ConfigObj = InstrumentedConfigObj
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
337
        my_config = config.GlobalConfig()
1442.1.2 by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing.
338
        try:
1442.1.18 by Robert Collins
permit per branch location overriding of signature checking policy
339
            parser = my_config._get_parser()
1442.1.2 by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing.
340
        finally:
1474 by Robert Collins
Merge from Aaron Bentley.
341
            config.ConfigObj = oldparserclass
342
        self.failUnless(isinstance(parser, InstrumentedConfigObj))
1551.2.20 by Aaron Bentley
Treated config files as utf-8
343
        self.assertEqual(parser._calls, [('__init__', config.config_filename(),
344
                                          'utf-8')])
1442.1.2 by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing.
345
346
1824.1.1 by Robert Collins
Add BranchConfig.has_explicit_nickname call.
347
class TestBranchConfig(TestCaseWithTransport):
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
348
349
    def test_constructs(self):
350
        branch = FakeBranch()
351
        my_config = config.BranchConfig(branch)
352
        self.assertRaises(TypeError, config.BranchConfig)
353
354
    def test_get_location_config(self):
355
        branch = FakeBranch()
356
        my_config = config.BranchConfig(branch)
357
        location_config = my_config._get_location_config()
358
        self.assertEqual(branch.base, location_config.location)
359
        self.failUnless(location_config is my_config._get_location_config())
360
1770.2.9 by Aaron Bentley
Add Branch.get_config, update BranchConfig() callers
361
    def test_get_config(self):
362
        """The Branch.get_config method works properly"""
363
        b = BzrDir.create_standalone_workingtree('.').branch
364
        my_config = b.get_config()
365
        self.assertIs(my_config.get_user_option('wacky'), None)
366
        my_config.set_user_option('wacky', 'unlikely')
367
        self.assertEqual(my_config.get_user_option('wacky'), 'unlikely')
368
369
        # Ensure we get the same thing if we start again
370
        b2 = Branch.open('.')
371
        my_config2 = b2.get_config()
372
        self.assertEqual(my_config2.get_user_option('wacky'), 'unlikely')
373
1824.1.1 by Robert Collins
Add BranchConfig.has_explicit_nickname call.
374
    def test_has_explicit_nickname(self):
375
        b = self.make_branch('.')
376
        self.assertFalse(b.get_config().has_explicit_nickname())
377
        b.nick = 'foo'
378
        self.assertTrue(b.get_config().has_explicit_nickname())
379
1878.1.1 by John Arbash Meinel
Entries in locations.conf should prefer local paths if available (bug #53653)
380
    def test_config_url(self):
381
        """The Branch.get_config will use section that uses a local url"""
382
        branch = self.make_branch('branch')
383
        self.assertEqual('branch', branch.nick)
384
385
        locations = config.locations_config_filename()
386
        config.ensure_config_dir_exists()
387
        local_url = urlutils.local_path_to_url('branch')
388
        open(locations, 'wb').write('[%s]\nnickname = foobar' 
389
                                    % (local_url,))
390
        self.assertEqual('foobar', branch.nick)
391
392
    def test_config_local_path(self):
393
        """The Branch.get_config will use a local system path"""
394
        branch = self.make_branch('branch')
395
        self.assertEqual('branch', branch.nick)
396
397
        locations = config.locations_config_filename()
398
        config.ensure_config_dir_exists()
399
        open(locations, 'wb').write('[%s/branch]\nnickname = barry' 
400
                                    % (osutils.getcwd().encode('utf8'),))
401
        self.assertEqual('barry', branch.nick)
402
1878.1.2 by John Arbash Meinel
Add a test that new locations.conf entries are created with a local path, rather than a URL
403
    def test_config_creates_local(self):
404
        """Creating a new entry in config uses a local path."""
2230.3.6 by Aaron Bentley
work in progress bind stuff
405
        branch = self.make_branch('branch', format='knit')
1878.1.2 by John Arbash Meinel
Add a test that new locations.conf entries are created with a local path, rather than a URL
406
        branch.set_push_location('http://foobar')
407
        locations = config.locations_config_filename()
408
        local_path = osutils.getcwd().encode('utf8')
409
        # Surprisingly ConfigObj doesn't create a trailing newline
410
        self.check_file_contents(locations,
2120.6.8 by James Henstridge
Change syntax for setting config option policies. Rather than
411
            '[%s/branch]\npush_location = http://foobar\npush_location:policy = norecurse' % (local_path,))
1878.1.2 by John Arbash Meinel
Add a test that new locations.conf entries are created with a local path, rather than a URL
412
2120.5.4 by Alexander Belchenko
Whitebox test for Config.get_nickname (req. by Aaron Bentley)
413
    def test_autonick_urlencoded(self):
414
        b = self.make_branch('!repo')
415
        self.assertEqual('!repo', b.get_config().get_nickname())
416
1551.15.35 by Aaron Bentley
Warn when setting config values that will be masked (#122286)
417
    def test_warn_if_masked(self):
418
        _warning = trace.warning
419
        warnings = []
420
        def warning(*args):
421
            warnings.append(args[0] % args[1:])
422
423
        def set_option(store, warn_masked=True):
424
            warnings[:] = []
425
            conf.set_user_option('example_option', repr(store), store=store,
426
                                 warn_masked=warn_masked)
427
        def assertWarning(warning):
428
            if warning is None:
429
                self.assertEqual(0, len(warnings))
430
            else:
431
                self.assertEqual(1, len(warnings))
432
                self.assertEqual(warning, warnings[0])
433
        trace.warning = warning
434
        try:
435
            branch = self.make_branch('.')
436
            conf = branch.get_config()
437
            set_option(config.STORE_GLOBAL)
438
            assertWarning(None)
439
            set_option(config.STORE_BRANCH)
440
            assertWarning(None)
441
            set_option(config.STORE_GLOBAL)
442
            assertWarning('Value "4" is masked by "3" from branch.conf')
443
            set_option(config.STORE_GLOBAL, warn_masked=False)
444
            assertWarning(None)
445
            set_option(config.STORE_LOCATION)
446
            assertWarning(None)
447
            set_option(config.STORE_BRANCH)
448
            assertWarning('Value "3" is masked by "0" from locations.conf')
449
            set_option(config.STORE_BRANCH, warn_masked=False)
450
            assertWarning(None)
451
        finally:
452
            trace.warning = _warning
453
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
454
1442.1.55 by Robert Collins
move environment preservation up to the root test case, making it available to all tests
455
class TestGlobalConfigItems(TestCase):
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
456
1442.1.2 by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing.
457
    def test_user_id(self):
1551.2.20 by Aaron Bentley
Treated config files as utf-8
458
        config_file = StringIO(sample_config_text.encode('utf-8'))
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
459
        my_config = config.GlobalConfig()
1442.1.18 by Robert Collins
permit per branch location overriding of signature checking policy
460
        my_config._parser = my_config._get_parser(file=config_file)
1551.2.21 by Aaron Bentley
Formatted unicode config tests as ASCII
461
        self.assertEqual(u"Erik B\u00e5gfors <erik@bagfors.nu>",
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
462
                         my_config._get_user_id())
1442.1.2 by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing.
463
464
    def test_absent_user_id(self):
465
        config_file = StringIO("")
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
466
        my_config = config.GlobalConfig()
1442.1.18 by Robert Collins
permit per branch location overriding of signature checking policy
467
        my_config._parser = my_config._get_parser(file=config_file)
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
468
        self.assertEqual(None, my_config._get_user_id())
469
470
    def test_configured_editor(self):
1551.2.20 by Aaron Bentley
Treated config files as utf-8
471
        config_file = StringIO(sample_config_text.encode('utf-8'))
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
472
        my_config = config.GlobalConfig()
1442.1.18 by Robert Collins
permit per branch location overriding of signature checking policy
473
        my_config._parser = my_config._get_parser(file=config_file)
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
474
        self.assertEqual("vim", my_config.get_editor())
475
1442.1.17 by Robert Collins
allow global overriding of signature policy to force checking, or (pointless but allowed) to set auto checking
476
    def test_signatures_always(self):
477
        config_file = StringIO(sample_always_signatures)
478
        my_config = config.GlobalConfig()
1442.1.18 by Robert Collins
permit per branch location overriding of signature checking policy
479
        my_config._parser = my_config._get_parser(file=config_file)
1770.2.1 by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this
480
        self.assertEqual(config.CHECK_NEVER,
1442.1.17 by Robert Collins
allow global overriding of signature policy to force checking, or (pointless but allowed) to set auto checking
481
                         my_config.signature_checking())
1770.2.1 by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this
482
        self.assertEqual(config.SIGN_ALWAYS,
483
                         my_config.signing_policy())
1442.1.21 by Robert Collins
create signature_needed() call for commit to trigger creating signatures
484
        self.assertEqual(True, my_config.signature_needed())
1442.1.17 by Robert Collins
allow global overriding of signature policy to force checking, or (pointless but allowed) to set auto checking
485
486
    def test_signatures_if_possible(self):
487
        config_file = StringIO(sample_maybe_signatures)
488
        my_config = config.GlobalConfig()
1442.1.18 by Robert Collins
permit per branch location overriding of signature checking policy
489
        my_config._parser = my_config._get_parser(file=config_file)
1770.2.1 by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this
490
        self.assertEqual(config.CHECK_NEVER,
1442.1.17 by Robert Collins
allow global overriding of signature policy to force checking, or (pointless but allowed) to set auto checking
491
                         my_config.signature_checking())
1770.2.1 by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this
492
        self.assertEqual(config.SIGN_WHEN_REQUIRED,
493
                         my_config.signing_policy())
1442.1.21 by Robert Collins
create signature_needed() call for commit to trigger creating signatures
494
        self.assertEqual(False, my_config.signature_needed())
1442.1.17 by Robert Collins
allow global overriding of signature policy to force checking, or (pointless but allowed) to set auto checking
495
1442.1.16 by Robert Collins
allow global overriding of signature policy to never check
496
    def test_signatures_ignore(self):
497
        config_file = StringIO(sample_ignore_signatures)
498
        my_config = config.GlobalConfig()
1442.1.18 by Robert Collins
permit per branch location overriding of signature checking policy
499
        my_config._parser = my_config._get_parser(file=config_file)
1770.2.1 by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this
500
        self.assertEqual(config.CHECK_ALWAYS,
1442.1.16 by Robert Collins
allow global overriding of signature policy to never check
501
                         my_config.signature_checking())
1770.2.1 by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this
502
        self.assertEqual(config.SIGN_NEVER,
503
                         my_config.signing_policy())
1442.1.21 by Robert Collins
create signature_needed() call for commit to trigger creating signatures
504
        self.assertEqual(False, my_config.signature_needed())
1442.1.16 by Robert Collins
allow global overriding of signature policy to never check
505
1442.1.69 by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name.
506
    def _get_sample_config(self):
1551.2.20 by Aaron Bentley
Treated config files as utf-8
507
        config_file = StringIO(sample_config_text.encode('utf-8'))
1534.7.154 by Aaron Bentley
Removed changes from bzr.ab 1529..1536
508
        my_config = config.GlobalConfig()
509
        my_config._parser = my_config._get_parser(file=config_file)
510
        return my_config
1442.1.69 by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name.
511
1442.1.56 by Robert Collins
gpg_signing_command configuration item
512
    def test_gpg_signing_command(self):
1442.1.69 by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name.
513
        my_config = self._get_sample_config()
1442.1.56 by Robert Collins
gpg_signing_command configuration item
514
        self.assertEqual("gnome-gpg", my_config.gpg_signing_command())
515
        self.assertEqual(False, my_config.signature_needed())
516
1442.1.69 by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name.
517
    def _get_empty_config(self):
518
        config_file = StringIO("")
519
        my_config = config.GlobalConfig()
520
        my_config._parser = my_config._get_parser(file=config_file)
521
        return my_config
522
1442.1.59 by Robert Collins
Add re-sign command to generate a digital signature on a single revision.
523
    def test_gpg_signing_command_unset(self):
1442.1.69 by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name.
524
        my_config = self._get_empty_config()
1442.1.59 by Robert Collins
Add re-sign command to generate a digital signature on a single revision.
525
        self.assertEqual("gpg", my_config.gpg_signing_command())
526
1442.1.69 by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name.
527
    def test_get_user_option_default(self):
528
        my_config = self._get_empty_config()
529
        self.assertEqual(None, my_config.get_user_option('no_option'))
530
531
    def test_get_user_option_global(self):
532
        my_config = self._get_sample_config()
533
        self.assertEqual("something",
534
                         my_config.get_user_option('user_global_option'))
1472 by Robert Collins
post commit hook, first pass implementation
535
        
536
    def test_post_commit_default(self):
537
        my_config = self._get_sample_config()
538
        self.assertEqual(None, my_config.post_commit())
539
1553.2.9 by Erik Bågfors
log_formatter => log_format for "named" formatters
540
    def test_configured_logformat(self):
1553.2.8 by Erik Bågfors
tests for config log_formatter
541
        my_config = self._get_sample_config()
1553.2.9 by Erik Bågfors
log_formatter => log_format for "named" formatters
542
        self.assertEqual("short", my_config.log_format())
1553.2.8 by Erik Bågfors
tests for config log_formatter
543
1553.6.12 by Erik Bågfors
remove AliasConfig, based on input from abentley
544
    def test_get_alias(self):
545
        my_config = self._get_sample_config()
546
        self.assertEqual('help', my_config.get_alias('h'))
547
548
    def test_get_no_alias(self):
549
        my_config = self._get_sample_config()
550
        self.assertEqual(None, my_config.get_alias('foo'))
551
552
    def test_get_long_alias(self):
553
        my_config = self._get_sample_config()
554
        self.assertEqual(sample_long_alias, my_config.get_alias('ll'))
1442.1.69 by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name.
555
1704.2.18 by Martin Pool
Remove duplicated TestLocationConfig and update previously hidden tests. (#32587)
556
557
class TestLocationConfig(TestCaseInTempDir):
1442.1.8 by Robert Collins
preparing some tests for LocationConfig
558
559
    def test_constructs(self):
560
        my_config = config.LocationConfig('http://example.com')
561
        self.assertRaises(TypeError, config.LocationConfig)
562
563
    def test_branch_calls_read_filenames(self):
1474 by Robert Collins
Merge from Aaron Bentley.
564
        # This is testing the correct file names are provided.
565
        # TODO: consolidate with the test for GlobalConfigs filename checks.
566
        #
1442.1.8 by Robert Collins
preparing some tests for LocationConfig
567
        # replace the class that is constructured, to check its parameters
1474 by Robert Collins
Merge from Aaron Bentley.
568
        oldparserclass = config.ConfigObj
569
        config.ConfigObj = InstrumentedConfigObj
1442.1.8 by Robert Collins
preparing some tests for LocationConfig
570
        try:
1770.2.2 by Aaron Bentley
Rename branches.conf to locations.conf
571
            my_config = config.LocationConfig('http://www.example.com')
1442.1.18 by Robert Collins
permit per branch location overriding of signature checking policy
572
            parser = my_config._get_parser()
1442.1.8 by Robert Collins
preparing some tests for LocationConfig
573
        finally:
1474 by Robert Collins
Merge from Aaron Bentley.
574
            config.ConfigObj = oldparserclass
575
        self.failUnless(isinstance(parser, InstrumentedConfigObj))
576
        self.assertEqual(parser._calls,
1770.2.2 by Aaron Bentley
Rename branches.conf to locations.conf
577
                         [('__init__', config.locations_config_filename(),
1704.2.18 by Martin Pool
Remove duplicated TestLocationConfig and update previously hidden tests. (#32587)
578
                           'utf-8')])
1711.4.29 by John Arbash Meinel
Alexander Belchenko, fix test_config to use ensure_config_dir, rather than os.mkdir()
579
        config.ensure_config_dir_exists()
580
        #os.mkdir(config.config_dir())
1770.2.2 by Aaron Bentley
Rename branches.conf to locations.conf
581
        f = file(config.branches_config_filename(), 'wb')
582
        f.write('')
583
        f.close()
584
        oldparserclass = config.ConfigObj
585
        config.ConfigObj = InstrumentedConfigObj
586
        try:
587
            my_config = config.LocationConfig('http://www.example.com')
588
            parser = my_config._get_parser()
589
        finally:
590
            config.ConfigObj = oldparserclass
1442.1.8 by Robert Collins
preparing some tests for LocationConfig
591
592
    def test_get_global_config(self):
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
593
        my_config = config.BranchConfig(FakeBranch('http://example.com'))
1442.1.8 by Robert Collins
preparing some tests for LocationConfig
594
        global_config = my_config._get_global_config()
595
        self.failUnless(isinstance(global_config, config.GlobalConfig))
596
        self.failUnless(global_config is my_config._get_global_config())
597
1993.3.1 by James Henstridge
first go at making location config lookup recursive
598
    def test__get_matching_sections_no_match(self):
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
599
        self.get_branch_config('/')
1993.3.1 by James Henstridge
first go at making location config lookup recursive
600
        self.assertEqual([], self.my_location_config._get_matching_sections())
1442.1.8 by Robert Collins
preparing some tests for LocationConfig
601
        
1993.3.1 by James Henstridge
first go at making location config lookup recursive
602
    def test__get_matching_sections_exact(self):
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
603
        self.get_branch_config('http://www.example.com')
1993.3.3 by James Henstridge
make _get_matching_sections() return (section, extra_path) tuples, and adjust other code to match
604
        self.assertEqual([('http://www.example.com', '')],
1993.3.1 by James Henstridge
first go at making location config lookup recursive
605
                         self.my_location_config._get_matching_sections())
1442.1.8 by Robert Collins
preparing some tests for LocationConfig
606
   
1993.3.1 by James Henstridge
first go at making location config lookup recursive
607
    def test__get_matching_sections_suffix_does_not(self):
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
608
        self.get_branch_config('http://www.example.com-com')
1993.3.1 by James Henstridge
first go at making location config lookup recursive
609
        self.assertEqual([], self.my_location_config._get_matching_sections())
1442.1.8 by Robert Collins
preparing some tests for LocationConfig
610
1993.3.1 by James Henstridge
first go at making location config lookup recursive
611
    def test__get_matching_sections_subdir_recursive(self):
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
612
        self.get_branch_config('http://www.example.com/com')
1993.3.3 by James Henstridge
make _get_matching_sections() return (section, extra_path) tuples, and adjust other code to match
613
        self.assertEqual([('http://www.example.com', 'com')],
1993.3.1 by James Henstridge
first go at making location config lookup recursive
614
                         self.my_location_config._get_matching_sections())
1442.1.8 by Robert Collins
preparing some tests for LocationConfig
615
1993.3.5 by James Henstridge
add back recurse=False option to config file
616
    def test__get_matching_sections_ignoreparent(self):
1993.3.3 by James Henstridge
make _get_matching_sections() return (section, extra_path) tuples, and adjust other code to match
617
        self.get_branch_config('http://www.example.com/ignoreparent')
618
        self.assertEqual([('http://www.example.com/ignoreparent', '')],
1993.3.1 by James Henstridge
first go at making location config lookup recursive
619
                         self.my_location_config._get_matching_sections())
1442.1.8 by Robert Collins
preparing some tests for LocationConfig
620
1993.3.5 by James Henstridge
add back recurse=False option to config file
621
    def test__get_matching_sections_ignoreparent_subdir(self):
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
622
        self.get_branch_config(
1993.3.3 by James Henstridge
make _get_matching_sections() return (section, extra_path) tuples, and adjust other code to match
623
            'http://www.example.com/ignoreparent/childbranch')
624
        self.assertEqual([('http://www.example.com/ignoreparent', 'childbranch')],
1993.3.1 by James Henstridge
first go at making location config lookup recursive
625
                         self.my_location_config._get_matching_sections())
1442.1.8 by Robert Collins
preparing some tests for LocationConfig
626
1993.3.1 by James Henstridge
first go at making location config lookup recursive
627
    def test__get_matching_sections_subdir_trailing_slash(self):
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
628
        self.get_branch_config('/b')
1993.3.3 by James Henstridge
make _get_matching_sections() return (section, extra_path) tuples, and adjust other code to match
629
        self.assertEqual([('/b/', '')],
1993.3.1 by James Henstridge
first go at making location config lookup recursive
630
                         self.my_location_config._get_matching_sections())
1442.1.8 by Robert Collins
preparing some tests for LocationConfig
631
1993.3.1 by James Henstridge
first go at making location config lookup recursive
632
    def test__get_matching_sections_subdir_child(self):
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
633
        self.get_branch_config('/a/foo')
1993.3.3 by James Henstridge
make _get_matching_sections() return (section, extra_path) tuples, and adjust other code to match
634
        self.assertEqual([('/a/*', ''), ('/a/', 'foo')],
1993.3.1 by James Henstridge
first go at making location config lookup recursive
635
                         self.my_location_config._get_matching_sections())
1442.1.8 by Robert Collins
preparing some tests for LocationConfig
636
1993.3.1 by James Henstridge
first go at making location config lookup recursive
637
    def test__get_matching_sections_subdir_child_child(self):
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
638
        self.get_branch_config('/a/foo/bar')
1993.3.3 by James Henstridge
make _get_matching_sections() return (section, extra_path) tuples, and adjust other code to match
639
        self.assertEqual([('/a/*', 'bar'), ('/a/', 'foo/bar')],
1993.3.1 by James Henstridge
first go at making location config lookup recursive
640
                         self.my_location_config._get_matching_sections())
1442.1.8 by Robert Collins
preparing some tests for LocationConfig
641
1993.3.1 by James Henstridge
first go at making location config lookup recursive
642
    def test__get_matching_sections_trailing_slash_with_children(self):
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
643
        self.get_branch_config('/a/')
1993.3.3 by James Henstridge
make _get_matching_sections() return (section, extra_path) tuples, and adjust other code to match
644
        self.assertEqual([('/a/', '')],
1993.3.1 by James Henstridge
first go at making location config lookup recursive
645
                         self.my_location_config._get_matching_sections())
1442.1.18 by Robert Collins
permit per branch location overriding of signature checking policy
646
1993.3.1 by James Henstridge
first go at making location config lookup recursive
647
    def test__get_matching_sections_explicit_over_glob(self):
648
        # XXX: 2006-09-08 jamesh
649
        # This test only passes because ord('c') > ord('*').  If there
650
        # was a config section for '/a/?', it would get precedence
651
        # over '/a/c'.
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
652
        self.get_branch_config('/a/c')
1993.3.3 by James Henstridge
make _get_matching_sections() return (section, extra_path) tuples, and adjust other code to match
653
        self.assertEqual([('/a/c', ''), ('/a/*', ''), ('/a/', 'c')],
1993.3.1 by James Henstridge
first go at making location config lookup recursive
654
                         self.my_location_config._get_matching_sections())
1442.1.8 by Robert Collins
preparing some tests for LocationConfig
655
2120.6.3 by James Henstridge
add some more tests for getting policy options, and behaviour of get_user_option in the presence of config policies
656
    def test__get_option_policy_normal(self):
657
        self.get_branch_config('http://www.example.com')
658
        self.assertEqual(
659
            self.my_location_config._get_config_policy(
660
            'http://www.example.com', 'normal_option'),
661
            config.POLICY_NONE)
662
663
    def test__get_option_policy_norecurse(self):
664
        self.get_branch_config('http://www.example.com')
665
        self.assertEqual(
666
            self.my_location_config._get_option_policy(
667
            'http://www.example.com', 'norecurse_option'),
668
            config.POLICY_NORECURSE)
669
        # Test old recurse=False setting:
670
        self.assertEqual(
671
            self.my_location_config._get_option_policy(
672
            'http://www.example.com/norecurse', 'normal_option'),
673
            config.POLICY_NORECURSE)
674
675
    def test__get_option_policy_normal(self):
676
        self.get_branch_config('http://www.example.com')
677
        self.assertEqual(
678
            self.my_location_config._get_option_policy(
679
            'http://www.example.com', 'appendpath_option'),
680
            config.POLICY_APPENDPATH)
681
1442.1.8 by Robert Collins
preparing some tests for LocationConfig
682
    def test_location_without_username(self):
1993.3.3 by James Henstridge
make _get_matching_sections() return (section, extra_path) tuples, and adjust other code to match
683
        self.get_branch_config('http://www.example.com/ignoreparent')
1704.2.18 by Martin Pool
Remove duplicated TestLocationConfig and update previously hidden tests. (#32587)
684
        self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>',
1442.1.8 by Robert Collins
preparing some tests for LocationConfig
685
                         self.my_config.username())
686
687
    def test_location_not_listed(self):
1704.2.18 by Martin Pool
Remove duplicated TestLocationConfig and update previously hidden tests. (#32587)
688
        """Test that the global username is used when no location matches"""
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
689
        self.get_branch_config('/home/robertc/sources')
1704.2.18 by Martin Pool
Remove duplicated TestLocationConfig and update previously hidden tests. (#32587)
690
        self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>',
1442.1.8 by Robert Collins
preparing some tests for LocationConfig
691
                         self.my_config.username())
692
1442.1.13 by Robert Collins
branches.conf is now able to override the users email
693
    def test_overriding_location(self):
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
694
        self.get_branch_config('http://www.example.com/foo')
1442.1.13 by Robert Collins
branches.conf is now able to override the users email
695
        self.assertEqual('Robert Collins <robertc@example.org>',
696
                         self.my_config.username())
1442.1.16 by Robert Collins
allow global overriding of signature policy to never check
697
1442.1.18 by Robert Collins
permit per branch location overriding of signature checking policy
698
    def test_signatures_not_set(self):
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
699
        self.get_branch_config('http://www.example.com',
1442.1.18 by Robert Collins
permit per branch location overriding of signature checking policy
700
                                 global_config=sample_ignore_signatures)
1770.2.1 by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this
701
        self.assertEqual(config.CHECK_ALWAYS,
1442.1.18 by Robert Collins
permit per branch location overriding of signature checking policy
702
                         self.my_config.signature_checking())
1770.2.1 by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this
703
        self.assertEqual(config.SIGN_NEVER,
704
                         self.my_config.signing_policy())
1442.1.18 by Robert Collins
permit per branch location overriding of signature checking policy
705
706
    def test_signatures_never(self):
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
707
        self.get_branch_config('/a/c')
1442.1.18 by Robert Collins
permit per branch location overriding of signature checking policy
708
        self.assertEqual(config.CHECK_NEVER,
709
                         self.my_config.signature_checking())
710
        
1442.1.16 by Robert Collins
allow global overriding of signature policy to never check
711
    def test_signatures_when_available(self):
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
712
        self.get_branch_config('/a/', global_config=sample_ignore_signatures)
1442.1.16 by Robert Collins
allow global overriding of signature policy to never check
713
        self.assertEqual(config.CHECK_IF_POSSIBLE,
714
                         self.my_config.signature_checking())
1442.1.13 by Robert Collins
branches.conf is now able to override the users email
715
        
1442.1.18 by Robert Collins
permit per branch location overriding of signature checking policy
716
    def test_signatures_always(self):
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
717
        self.get_branch_config('/b')
1442.1.18 by Robert Collins
permit per branch location overriding of signature checking policy
718
        self.assertEqual(config.CHECK_ALWAYS,
719
                         self.my_config.signature_checking())
720
        
1442.1.56 by Robert Collins
gpg_signing_command configuration item
721
    def test_gpg_signing_command(self):
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
722
        self.get_branch_config('/b')
1442.1.56 by Robert Collins
gpg_signing_command configuration item
723
        self.assertEqual("gnome-gpg", self.my_config.gpg_signing_command())
724
725
    def test_gpg_signing_command_missing(self):
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
726
        self.get_branch_config('/a')
1442.1.56 by Robert Collins
gpg_signing_command configuration item
727
        self.assertEqual("false", self.my_config.gpg_signing_command())
728
1442.1.69 by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name.
729
    def test_get_user_option_global(self):
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
730
        self.get_branch_config('/a')
1442.1.69 by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name.
731
        self.assertEqual('something',
732
                         self.my_config.get_user_option('user_global_option'))
733
734
    def test_get_user_option_local(self):
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
735
        self.get_branch_config('/a')
1442.1.69 by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name.
736
        self.assertEqual('local',
737
                         self.my_config.get_user_option('user_local_option'))
1993.3.3 by James Henstridge
make _get_matching_sections() return (section, extra_path) tuples, and adjust other code to match
738
2120.6.3 by James Henstridge
add some more tests for getting policy options, and behaviour of get_user_option in the presence of config policies
739
    def test_get_user_option_appendpath(self):
740
        # returned as is for the base path:
741
        self.get_branch_config('http://www.example.com')
742
        self.assertEqual('append',
743
                         self.my_config.get_user_option('appendpath_option'))
744
        # Extra path components get appended:
745
        self.get_branch_config('http://www.example.com/a/b/c')
746
        self.assertEqual('append/a/b/c',
747
                         self.my_config.get_user_option('appendpath_option'))
748
        # Overriden for http://www.example.com/dir, where it is a
749
        # normal option:
750
        self.get_branch_config('http://www.example.com/dir/a/b/c')
751
        self.assertEqual('normal',
752
                         self.my_config.get_user_option('appendpath_option'))
753
754
    def test_get_user_option_norecurse(self):
755
        self.get_branch_config('http://www.example.com')
756
        self.assertEqual('norecurse',
757
                         self.my_config.get_user_option('norecurse_option'))
758
        self.get_branch_config('http://www.example.com/dir')
759
        self.assertEqual(None,
760
                         self.my_config.get_user_option('norecurse_option'))
761
        # http://www.example.com/norecurse is a recurse=False section
762
        # that redefines normal_option.  Subdirectories do not pick up
763
        # this redefinition.
764
        self.get_branch_config('http://www.example.com/norecurse')
765
        self.assertEqual('norecurse',
766
                         self.my_config.get_user_option('normal_option'))
767
        self.get_branch_config('http://www.example.com/norecurse/subdir')
768
        self.assertEqual('normal',
769
                         self.my_config.get_user_option('normal_option'))
770
2120.6.4 by James Henstridge
add support for specifying policy when storing options
771
    def test_set_user_option_norecurse(self):
772
        self.get_branch_config('http://www.example.com')
773
        self.my_config.set_user_option('foo', 'bar',
774
                                       store=config.STORE_LOCATION_NORECURSE)
775
        self.assertEqual(
776
            self.my_location_config._get_option_policy(
777
            'http://www.example.com', 'foo'),
778
            config.POLICY_NORECURSE)
779
780
    def test_set_user_option_appendpath(self):
781
        self.get_branch_config('http://www.example.com')
782
        self.my_config.set_user_option('foo', 'bar',
783
                                       store=config.STORE_LOCATION_APPENDPATH)
784
        self.assertEqual(
785
            self.my_location_config._get_option_policy(
786
            'http://www.example.com', 'foo'),
787
            config.POLICY_APPENDPATH)
788
789
    def test_set_user_option_change_policy(self):
790
        self.get_branch_config('http://www.example.com')
791
        self.my_config.set_user_option('norecurse_option', 'normal',
792
                                       store=config.STORE_LOCATION)
793
        self.assertEqual(
794
            self.my_location_config._get_option_policy(
795
            'http://www.example.com', 'norecurse_option'),
796
            config.POLICY_NONE)
797
798
    def test_set_user_option_recurse_false_section(self):
2120.6.9 by James Henstridge
Fixes for issues brought up in John's review
799
        # The following section has recurse=False set.  The test is to
800
        # make sure that a normal option can be added to the section,
801
        # converting recurse=False to the norecurse policy.
2120.6.4 by James Henstridge
add support for specifying policy when storing options
802
        self.get_branch_config('http://www.example.com/norecurse')
2120.6.11 by James Henstridge
s/0.13/0.14/ in deprecation warning
803
        self.callDeprecated(['The recurse option is deprecated as of 0.14.  '
2120.6.9 by James Henstridge
Fixes for issues brought up in John's review
804
                             'The section "http://www.example.com/norecurse" '
805
                             'has been converted to use policies.'],
806
                            self.my_config.set_user_option,
807
                            'foo', 'bar', store=config.STORE_LOCATION)
2120.6.4 by James Henstridge
add support for specifying policy when storing options
808
        self.assertEqual(
809
            self.my_location_config._get_option_policy(
810
            'http://www.example.com/norecurse', 'foo'),
811
            config.POLICY_NONE)
812
        # The previously existing option is still norecurse:
813
        self.assertEqual(
814
            self.my_location_config._get_option_policy(
815
            'http://www.example.com/norecurse', 'normal_option'),
816
            config.POLICY_NORECURSE)
817
1472 by Robert Collins
post commit hook, first pass implementation
818
    def test_post_commit_default(self):
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
819
        self.get_branch_config('/a/c')
1185.31.25 by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py
820
        self.assertEqual('bzrlib.tests.test_config.post_commit',
1472 by Robert Collins
post commit hook, first pass implementation
821
                         self.my_config.post_commit())
1442.1.69 by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name.
822
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
823
    def get_branch_config(self, location, global_config=None):
1502 by Robert Collins
Bugfix the config test suite to not create .bazaar in the dir where it is run.
824
        if global_config is None:
1551.2.20 by Aaron Bentley
Treated config files as utf-8
825
            global_file = StringIO(sample_config_text.encode('utf-8'))
1502 by Robert Collins
Bugfix the config test suite to not create .bazaar in the dir where it is run.
826
        else:
1551.2.20 by Aaron Bentley
Treated config files as utf-8
827
            global_file = StringIO(global_config.encode('utf-8'))
828
        branches_file = StringIO(sample_branches_text.encode('utf-8'))
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
829
        self.my_config = config.BranchConfig(FakeBranch(location))
830
        # Force location config to use specified file
831
        self.my_location_config = self.my_config._get_location_config()
832
        self.my_location_config._get_parser(branches_file)
833
        # Force global config to use specified file
1502 by Robert Collins
Bugfix the config test suite to not create .bazaar in the dir where it is run.
834
        self.my_config._get_global_config()._get_parser(global_file)
835
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
836
    def test_set_user_setting_sets_and_saves(self):
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
837
        self.get_branch_config('/a/c')
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
838
        record = InstrumentedConfigObj("foo")
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
839
        self.my_location_config._parser = record
1185.62.6 by John Arbash Meinel
Updated test_set_user_setting_sets_and_saves to remove the print statement, and make sure it is doing the right thing
840
841
        real_mkdir = os.mkdir
842
        self.created = False
843
        def checked_mkdir(path, mode=0777):
844
            self.log('making directory: %s', path)
845
            real_mkdir(path, mode)
846
            self.created = True
847
848
        os.mkdir = checked_mkdir
849
        try:
2120.6.10 by James Henstridge
Catch another deprecation warning, and more cleanup
850
            self.callDeprecated(['The recurse option is deprecated as of '
2120.6.11 by James Henstridge
s/0.13/0.14/ in deprecation warning
851
                                 '0.14.  The section "/a/c" has been '
2120.6.10 by James Henstridge
Catch another deprecation warning, and more cleanup
852
                                 'converted to use policies.'],
853
                                self.my_config.set_user_option,
854
                                'foo', 'bar', store=config.STORE_LOCATION)
1185.62.6 by John Arbash Meinel
Updated test_set_user_setting_sets_and_saves to remove the print statement, and make sure it is doing the right thing
855
        finally:
856
            os.mkdir = real_mkdir
857
858
        self.failUnless(self.created, 'Failed to create ~/.bazaar')
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
859
        self.assertEqual([('__contains__', '/a/c'),
860
                          ('__contains__', '/a/c/'),
861
                          ('__setitem__', '/a/c', {}),
862
                          ('__getitem__', '/a/c'),
863
                          ('__setitem__', 'foo', 'bar'),
2120.6.4 by James Henstridge
add support for specifying policy when storing options
864
                          ('__getitem__', '/a/c'),
865
                          ('as_bool', 'recurse'),
866
                          ('__getitem__', '/a/c'),
867
                          ('__delitem__', 'recurse'),
868
                          ('__getitem__', '/a/c'),
869
                          ('keys',),
2120.6.8 by James Henstridge
Change syntax for setting config option policies. Rather than
870
                          ('__getitem__', '/a/c'),
871
                          ('__contains__', 'foo:policy'),
1490 by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1.
872
                          ('write',)],
873
                         record._calls[1:])
874
1770.2.6 by Aaron Bentley
Ensure branch.conf works properly
875
    def test_set_user_setting_sets_and_saves2(self):
876
        self.get_branch_config('/a/c')
877
        self.assertIs(self.my_config.get_user_option('foo'), None)
878
        self.my_config.set_user_option('foo', 'bar')
879
        self.assertEqual(
880
            self.my_config.branch.control_files.files['branch.conf'], 
881
            'foo = bar')
882
        self.assertEqual(self.my_config.get_user_option('foo'), 'bar')
2120.6.4 by James Henstridge
add support for specifying policy when storing options
883
        self.my_config.set_user_option('foo', 'baz',
884
                                       store=config.STORE_LOCATION)
1770.2.6 by Aaron Bentley
Ensure branch.conf works properly
885
        self.assertEqual(self.my_config.get_user_option('foo'), 'baz')
886
        self.my_config.set_user_option('foo', 'qux')
887
        self.assertEqual(self.my_config.get_user_option('foo'), 'baz')
888
        
1185.62.7 by John Arbash Meinel
Whitespace cleanup.
889
1770.2.8 by Aaron Bentley
Add precedence test
890
precedence_global = 'option = global'
891
precedence_branch = 'option = branch'
892
precedence_location = """
893
[http://]
894
recurse = true
895
option = recurse
896
[http://example.com/specific]
897
option = exact
898
"""
899
900
1770.2.6 by Aaron Bentley
Ensure branch.conf works properly
901
class TestBranchConfigItems(TestCaseInTempDir):
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
902
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
903
    def get_branch_config(self, global_config=None, location=None, 
1770.2.6 by Aaron Bentley
Ensure branch.conf works properly
904
                          location_config=None, branch_data_config=None):
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
905
        my_config = config.BranchConfig(FakeBranch(location))
906
        if global_config is not None:
907
            global_file = StringIO(global_config.encode('utf-8'))
908
            my_config._get_global_config()._get_parser(global_file)
909
        self.my_location_config = my_config._get_location_config()
910
        if location_config is not None:
911
            location_file = StringIO(location_config.encode('utf-8'))
912
            self.my_location_config._get_parser(location_file)
1770.2.6 by Aaron Bentley
Ensure branch.conf works properly
913
        if branch_data_config is not None:
914
            my_config.branch.control_files.files['branch.conf'] = \
915
                branch_data_config
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
916
        return my_config
917
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
918
    def test_user_id(self):
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
919
        branch = FakeBranch(user_id='Robert Collins <robertc@example.net>')
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
920
        my_config = config.BranchConfig(branch)
921
        self.assertEqual("Robert Collins <robertc@example.net>",
1770.2.6 by Aaron Bentley
Ensure branch.conf works properly
922
                         my_config.username())
1185.65.11 by Robert Collins
Disable inheritance for getting at LockableFiles, rather use composition.
923
        branch.control_files.email = "John"
1770.2.6 by Aaron Bentley
Ensure branch.conf works properly
924
        my_config.set_user_option('email', 
925
                                  "Robert Collins <robertc@example.org>")
926
        self.assertEqual("John", my_config.username())
927
        branch.control_files.email = None
928
        self.assertEqual("Robert Collins <robertc@example.org>",
929
                         my_config.username())
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
930
931
    def test_not_set_in_branch(self):
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
932
        my_config = self.get_branch_config(sample_config_text)
933
        my_config.branch.control_files.email = None
1551.2.21 by Aaron Bentley
Formatted unicode config tests as ASCII
934
        self.assertEqual(u"Erik B\u00e5gfors <erik@bagfors.nu>",
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
935
                         my_config._get_user_id())
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
936
        my_config.branch.control_files.email = "John"
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
937
        self.assertEqual("John", my_config._get_user_id())
938
1861.4.1 by Matthieu Moy
BZREMAIL renamed to BZR_EMAIL.
939
    def test_BZR_EMAIL_OVERRIDES(self):
940
        os.environ['BZR_EMAIL'] = "Robert Collins <robertc@example.org>"
1442.1.6 by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs
941
        branch = FakeBranch()
942
        my_config = config.BranchConfig(branch)
943
        self.assertEqual("Robert Collins <robertc@example.org>",
944
                         my_config.username())
945
    
1442.1.19 by Robert Collins
BranchConfigs inherit signature_checking policy from their LocationConfig.
946
    def test_signatures_forced(self):
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
947
        my_config = self.get_branch_config(
948
            global_config=sample_always_signatures)
1770.2.1 by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this
949
        self.assertEqual(config.CHECK_NEVER, my_config.signature_checking())
950
        self.assertEqual(config.SIGN_ALWAYS, my_config.signing_policy())
951
        self.assertTrue(my_config.signature_needed())
1442.1.56 by Robert Collins
gpg_signing_command configuration item
952
1770.2.6 by Aaron Bentley
Ensure branch.conf works properly
953
    def test_signatures_forced_branch(self):
954
        my_config = self.get_branch_config(
955
            global_config=sample_ignore_signatures,
956
            branch_data_config=sample_always_signatures)
957
        self.assertEqual(config.CHECK_NEVER, my_config.signature_checking())
958
        self.assertEqual(config.SIGN_ALWAYS, my_config.signing_policy())
959
        self.assertTrue(my_config.signature_needed())
960
1442.1.56 by Robert Collins
gpg_signing_command configuration item
961
    def test_gpg_signing_command(self):
1770.2.10 by Aaron Bentley
Added test that branch_config can't influence gpg_signing_command
962
        my_config = self.get_branch_config(
963
            # branch data cannot set gpg_signing_command
964
            branch_data_config="gpg_signing_command=pgp")
1551.2.20 by Aaron Bentley
Treated config files as utf-8
965
        config_file = StringIO(sample_config_text.encode('utf-8'))
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
966
        my_config._get_global_config()._get_parser(config_file)
1442.1.56 by Robert Collins
gpg_signing_command configuration item
967
        self.assertEqual('gnome-gpg', my_config.gpg_signing_command())
1442.1.69 by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name.
968
969
    def test_get_user_option_global(self):
970
        branch = FakeBranch()
971
        my_config = config.BranchConfig(branch)
1551.2.20 by Aaron Bentley
Treated config files as utf-8
972
        config_file = StringIO(sample_config_text.encode('utf-8'))
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
973
        (my_config._get_global_config()._get_parser(config_file))
1442.1.69 by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name.
974
        self.assertEqual('something',
975
                         my_config.get_user_option('user_global_option'))
1472 by Robert Collins
post commit hook, first pass implementation
976
977
    def test_post_commit_default(self):
978
        branch = FakeBranch()
1770.2.5 by Aaron Bentley
Integrate branch.conf into BranchConfig
979
        my_config = self.get_branch_config(sample_config_text, '/a/c',
980
                                           sample_branches_text)
981
        self.assertEqual(my_config.branch.base, '/a/c')
1185.31.25 by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py
982
        self.assertEqual('bzrlib.tests.test_config.post_commit',
1472 by Robert Collins
post commit hook, first pass implementation
983
                         my_config.post_commit())
1770.2.6 by Aaron Bentley
Ensure branch.conf works properly
984
        my_config.set_user_option('post_commit', 'rmtree_root')
985
        # post-commit is ignored when bresent in branch data
986
        self.assertEqual('bzrlib.tests.test_config.post_commit',
987
                         my_config.post_commit())
2120.6.4 by James Henstridge
add support for specifying policy when storing options
988
        my_config.set_user_option('post_commit', 'rmtree_root',
989
                                  store=config.STORE_LOCATION)
1770.2.6 by Aaron Bentley
Ensure branch.conf works properly
990
        self.assertEqual('rmtree_root', my_config.post_commit())
1185.33.31 by Martin Pool
Make annotate cope better with revisions committed without a valid
991
1770.2.8 by Aaron Bentley
Add precedence test
992
    def test_config_precedence(self):
993
        my_config = self.get_branch_config(global_config=precedence_global)
994
        self.assertEqual(my_config.get_user_option('option'), 'global')
995
        my_config = self.get_branch_config(global_config=precedence_global, 
996
                                      branch_data_config=precedence_branch)
997
        self.assertEqual(my_config.get_user_option('option'), 'branch')
998
        my_config = self.get_branch_config(global_config=precedence_global, 
999
                                      branch_data_config=precedence_branch,
1000
                                      location_config=precedence_location)
1001
        self.assertEqual(my_config.get_user_option('option'), 'recurse')
1002
        my_config = self.get_branch_config(global_config=precedence_global, 
1003
                                      branch_data_config=precedence_branch,
1004
                                      location_config=precedence_location,
1005
                                      location='http://example.com/specific')
1006
        self.assertEqual(my_config.get_user_option('option'), 'exact')
1007
1185.33.31 by Martin Pool
Make annotate cope better with revisions committed without a valid
1008
1009
class TestMailAddressExtraction(TestCase):
1010
1011
    def test_extract_email_address(self):
1012
        self.assertEqual('jane@test.com',
1013
                         config.extract_email_address('Jane <jane@test.com>'))
2055.2.2 by John Arbash Meinel
Switch extract_email_address() to use a more specific exception
1014
        self.assertRaises(errors.NoEmailInUsername,
1185.33.31 by Martin Pool
Make annotate cope better with revisions committed without a valid
1015
                          config.extract_email_address, 'Jane Tester')
2533.1.1 by James Westby
Fix TreeConfig to return values from sections.
1016
2562.1.2 by John Arbash Meinel
Clean up whitespace
1017
2533.1.1 by James Westby
Fix TreeConfig to return values from sections.
1018
class TestTreeConfig(TestCaseWithTransport):
1019
1020
    def test_get_value(self):
1021
        """Test that retreiving a value from a section is possible"""
1022
        branch = self.make_branch('.')
1023
        tree_config = config.TreeConfig(branch)
1024
        tree_config.set_option('value', 'key', 'SECTION')
1025
        tree_config.set_option('value2', 'key2')
1026
        tree_config.set_option('value3-top', 'key3')
1027
        tree_config.set_option('value3-section', 'key3', 'SECTION')
1028
        value = tree_config.get_option('key', 'SECTION')
1029
        self.assertEqual(value, 'value')
1030
        value = tree_config.get_option('key2')
1031
        self.assertEqual(value, 'value2')
1032
        self.assertEqual(tree_config.get_option('non-existant'), None)
1033
        value = tree_config.get_option('non-existant', 'SECTION')
1034
        self.assertEqual(value, None)
1035
        value = tree_config.get_option('non-existant', default='default')
1036
        self.assertEqual(value, 'default')
1037
        self.assertEqual(tree_config.get_option('key2', 'NOSECTION'), None)
1038
        value = tree_config.get_option('key2', 'NOSECTION', default='default')
1039
        self.assertEqual(value, 'default')
1040
        value = tree_config.get_option('key3')
1041
        self.assertEqual(value, 'value3-top')
1042
        value = tree_config.get_option('key3', 'SECTION')
1043
        self.assertEqual(value, 'value3-section')