~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Robert Collins
  • Date: 2007-09-06 04:20:55 UTC
  • mfrom: (2794.1.3 knits)
  • mto: This revision was merged to the branch mainline in revision 2803.
  • Revision ID: robertc@robertcollins.net-20070906042055-r2fa1adv2nudrjjl
(robertc) Trivially remove spurious call in revisionstore.add_revision. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
 
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
 
20
from bzrlib.util.configobj.configobj import ConfigObj, ConfigObjError
 
21
from cStringIO import StringIO
 
22
import os
 
23
import sys
 
24
 
 
25
#import bzrlib specific imports here
 
26
from bzrlib import (
 
27
    config,
 
28
    errors,
 
29
    osutils,
 
30
    mail_client,
 
31
    urlutils,
 
32
    trace,
 
33
    )
 
34
from bzrlib.branch import Branch
 
35
from bzrlib.bzrdir import BzrDir
 
36
from bzrlib.tests import TestCase, TestCaseInTempDir, TestCaseWithTransport
 
37
 
 
38
 
 
39
sample_long_alias="log -r-15..-1 --line"
 
40
sample_config_text = u"""
 
41
[DEFAULT]
 
42
email=Erik B\u00e5gfors <erik@bagfors.nu>
 
43
editor=vim
 
44
gpg_signing_command=gnome-gpg
 
45
log_format=short
 
46
user_global_option=something
 
47
[ALIASES]
 
48
h=help
 
49
ll=""" + sample_long_alias + "\n"
 
50
 
 
51
 
 
52
sample_always_signatures = """
 
53
[DEFAULT]
 
54
check_signatures=ignore
 
55
create_signatures=always
 
56
"""
 
57
 
 
58
sample_ignore_signatures = """
 
59
[DEFAULT]
 
60
check_signatures=require
 
61
create_signatures=never
 
62
"""
 
63
 
 
64
sample_maybe_signatures = """
 
65
[DEFAULT]
 
66
check_signatures=ignore
 
67
create_signatures=when-required
 
68
"""
 
69
 
 
70
sample_branches_text = """
 
71
[http://www.example.com]
 
72
# Top level policy
 
73
email=Robert Collins <robertc@example.org>
 
74
normal_option = normal
 
75
appendpath_option = append
 
76
appendpath_option:policy = appendpath
 
77
norecurse_option = norecurse
 
78
norecurse_option:policy = norecurse
 
79
[http://www.example.com/ignoreparent]
 
80
# different project: ignore parent dir config
 
81
ignore_parents=true
 
82
[http://www.example.com/norecurse]
 
83
# configuration items that only apply to this dir
 
84
recurse=false
 
85
normal_option = norecurse
 
86
[http://www.example.com/dir]
 
87
appendpath_option = normal
 
88
[/b/]
 
89
check_signatures=require
 
90
# test trailing / matching with no children
 
91
[/a/]
 
92
check_signatures=check-available
 
93
gpg_signing_command=false
 
94
user_local_option=local
 
95
# test trailing / matching
 
96
[/a/*]
 
97
#subdirs will match but not the parent
 
98
[/a/c]
 
99
check_signatures=ignore
 
100
post_commit=bzrlib.tests.test_config.post_commit
 
101
#testing explicit beats globs
 
102
"""
 
103
 
 
104
 
 
105
class InstrumentedConfigObj(object):
 
106
    """A config obj look-enough-alike to record calls made to it."""
 
107
 
 
108
    def __contains__(self, thing):
 
109
        self._calls.append(('__contains__', thing))
 
110
        return False
 
111
 
 
112
    def __getitem__(self, key):
 
113
        self._calls.append(('__getitem__', key))
 
114
        return self
 
115
 
 
116
    def __init__(self, input, encoding=None):
 
117
        self._calls = [('__init__', input, encoding)]
 
118
 
 
119
    def __setitem__(self, key, value):
 
120
        self._calls.append(('__setitem__', key, value))
 
121
 
 
122
    def __delitem__(self, key):
 
123
        self._calls.append(('__delitem__', key))
 
124
 
 
125
    def keys(self):
 
126
        self._calls.append(('keys',))
 
127
        return []
 
128
 
 
129
    def write(self, arg):
 
130
        self._calls.append(('write',))
 
131
 
 
132
    def as_bool(self, value):
 
133
        self._calls.append(('as_bool', value))
 
134
        return False
 
135
 
 
136
    def get_value(self, section, name):
 
137
        self._calls.append(('get_value', section, name))
 
138
        return None
 
139
 
 
140
 
 
141
class FakeBranch(object):
 
142
 
 
143
    def __init__(self, base=None, user_id=None):
 
144
        if base is None:
 
145
            self.base = "http://example.com/branches/demo"
 
146
        else:
 
147
            self.base = base
 
148
        self.control_files = FakeControlFiles(user_id=user_id)
 
149
 
 
150
    def lock_write(self):
 
151
        pass
 
152
 
 
153
    def unlock(self):
 
154
        pass
 
155
 
 
156
 
 
157
class FakeControlFiles(object):
 
158
 
 
159
    def __init__(self, user_id=None):
 
160
        self.email = user_id
 
161
        self.files = {}
 
162
 
 
163
    def get_utf8(self, filename):
 
164
        if filename != 'email':
 
165
            raise NotImplementedError
 
166
        if self.email is not None:
 
167
            return StringIO(self.email)
 
168
        raise errors.NoSuchFile(filename)
 
169
 
 
170
    def get(self, filename):
 
171
        try:
 
172
            return StringIO(self.files[filename])
 
173
        except KeyError:
 
174
            raise errors.NoSuchFile(filename)
 
175
 
 
176
    def put(self, filename, fileobj):
 
177
        self.files[filename] = fileobj.read()
 
178
 
 
179
 
 
180
class InstrumentedConfig(config.Config):
 
181
    """An instrumented config that supplies stubs for template methods."""
 
182
    
 
183
    def __init__(self):
 
184
        super(InstrumentedConfig, self).__init__()
 
185
        self._calls = []
 
186
        self._signatures = config.CHECK_NEVER
 
187
 
 
188
    def _get_user_id(self):
 
189
        self._calls.append('_get_user_id')
 
190
        return "Robert Collins <robert.collins@example.org>"
 
191
 
 
192
    def _get_signature_checking(self):
 
193
        self._calls.append('_get_signature_checking')
 
194
        return self._signatures
 
195
 
 
196
 
 
197
bool_config = """[DEFAULT]
 
198
active = true
 
199
inactive = false
 
200
[UPPERCASE]
 
201
active = True
 
202
nonactive = False
 
203
"""
 
204
class TestConfigObj(TestCase):
 
205
    def test_get_bool(self):
 
206
        from bzrlib.config import ConfigObj
 
207
        co = ConfigObj(StringIO(bool_config))
 
208
        self.assertIs(co.get_bool('DEFAULT', 'active'), True)
 
209
        self.assertIs(co.get_bool('DEFAULT', 'inactive'), False)
 
210
        self.assertIs(co.get_bool('UPPERCASE', 'active'), True)
 
211
        self.assertIs(co.get_bool('UPPERCASE', 'nonactive'), False)
 
212
 
 
213
 
 
214
class TestConfig(TestCase):
 
215
 
 
216
    def test_constructs(self):
 
217
        config.Config()
 
218
 
 
219
    def test_no_default_editor(self):
 
220
        self.assertRaises(NotImplementedError, config.Config().get_editor)
 
221
 
 
222
    def test_user_email(self):
 
223
        my_config = InstrumentedConfig()
 
224
        self.assertEqual('robert.collins@example.org', my_config.user_email())
 
225
        self.assertEqual(['_get_user_id'], my_config._calls)
 
226
 
 
227
    def test_username(self):
 
228
        my_config = InstrumentedConfig()
 
229
        self.assertEqual('Robert Collins <robert.collins@example.org>',
 
230
                         my_config.username())
 
231
        self.assertEqual(['_get_user_id'], my_config._calls)
 
232
 
 
233
    def test_signatures_default(self):
 
234
        my_config = config.Config()
 
235
        self.assertFalse(my_config.signature_needed())
 
236
        self.assertEqual(config.CHECK_IF_POSSIBLE,
 
237
                         my_config.signature_checking())
 
238
        self.assertEqual(config.SIGN_WHEN_REQUIRED,
 
239
                         my_config.signing_policy())
 
240
 
 
241
    def test_signatures_template_method(self):
 
242
        my_config = InstrumentedConfig()
 
243
        self.assertEqual(config.CHECK_NEVER, my_config.signature_checking())
 
244
        self.assertEqual(['_get_signature_checking'], my_config._calls)
 
245
 
 
246
    def test_signatures_template_method_none(self):
 
247
        my_config = InstrumentedConfig()
 
248
        my_config._signatures = None
 
249
        self.assertEqual(config.CHECK_IF_POSSIBLE,
 
250
                         my_config.signature_checking())
 
251
        self.assertEqual(['_get_signature_checking'], my_config._calls)
 
252
 
 
253
    def test_gpg_signing_command_default(self):
 
254
        my_config = config.Config()
 
255
        self.assertEqual('gpg', my_config.gpg_signing_command())
 
256
 
 
257
    def test_get_user_option_default(self):
 
258
        my_config = config.Config()
 
259
        self.assertEqual(None, my_config.get_user_option('no_option'))
 
260
 
 
261
    def test_post_commit_default(self):
 
262
        my_config = config.Config()
 
263
        self.assertEqual(None, my_config.post_commit())
 
264
 
 
265
    def test_log_format_default(self):
 
266
        my_config = config.Config()
 
267
        self.assertEqual('long', my_config.log_format())
 
268
 
 
269
 
 
270
class TestConfigPath(TestCase):
 
271
 
 
272
    def setUp(self):
 
273
        super(TestConfigPath, self).setUp()
 
274
        os.environ['HOME'] = '/home/bogus'
 
275
        if sys.platform == 'win32':
 
276
            os.environ['BZR_HOME'] = \
 
277
                r'C:\Documents and Settings\bogus\Application Data'
 
278
 
 
279
    def test_config_dir(self):
 
280
        if sys.platform == 'win32':
 
281
            self.assertEqual(config.config_dir(), 
 
282
                'C:/Documents and Settings/bogus/Application Data/bazaar/2.0')
 
283
        else:
 
284
            self.assertEqual(config.config_dir(), '/home/bogus/.bazaar')
 
285
 
 
286
    def test_config_filename(self):
 
287
        if sys.platform == 'win32':
 
288
            self.assertEqual(config.config_filename(), 
 
289
                'C:/Documents and Settings/bogus/Application Data/bazaar/2.0/bazaar.conf')
 
290
        else:
 
291
            self.assertEqual(config.config_filename(),
 
292
                             '/home/bogus/.bazaar/bazaar.conf')
 
293
 
 
294
    def test_branches_config_filename(self):
 
295
        if sys.platform == 'win32':
 
296
            self.assertEqual(config.branches_config_filename(), 
 
297
                'C:/Documents and Settings/bogus/Application Data/bazaar/2.0/branches.conf')
 
298
        else:
 
299
            self.assertEqual(config.branches_config_filename(),
 
300
                             '/home/bogus/.bazaar/branches.conf')
 
301
 
 
302
    def test_locations_config_filename(self):
 
303
        if sys.platform == 'win32':
 
304
            self.assertEqual(config.locations_config_filename(), 
 
305
                'C:/Documents and Settings/bogus/Application Data/bazaar/2.0/locations.conf')
 
306
        else:
 
307
            self.assertEqual(config.locations_config_filename(),
 
308
                             '/home/bogus/.bazaar/locations.conf')
 
309
 
 
310
class TestIniConfig(TestCase):
 
311
 
 
312
    def test_contructs(self):
 
313
        my_config = config.IniBasedConfig("nothing")
 
314
 
 
315
    def test_from_fp(self):
 
316
        config_file = StringIO(sample_config_text.encode('utf-8'))
 
317
        my_config = config.IniBasedConfig(None)
 
318
        self.failUnless(
 
319
            isinstance(my_config._get_parser(file=config_file),
 
320
                        ConfigObj))
 
321
 
 
322
    def test_cached(self):
 
323
        config_file = StringIO(sample_config_text.encode('utf-8'))
 
324
        my_config = config.IniBasedConfig(None)
 
325
        parser = my_config._get_parser(file=config_file)
 
326
        self.failUnless(my_config._get_parser() is parser)
 
327
 
 
328
 
 
329
class TestGetConfig(TestCase):
 
330
 
 
331
    def test_constructs(self):
 
332
        my_config = config.GlobalConfig()
 
333
 
 
334
    def test_calls_read_filenames(self):
 
335
        # replace the class that is constructured, to check its parameters
 
336
        oldparserclass = config.ConfigObj
 
337
        config.ConfigObj = InstrumentedConfigObj
 
338
        my_config = config.GlobalConfig()
 
339
        try:
 
340
            parser = my_config._get_parser()
 
341
        finally:
 
342
            config.ConfigObj = oldparserclass
 
343
        self.failUnless(isinstance(parser, InstrumentedConfigObj))
 
344
        self.assertEqual(parser._calls, [('__init__', config.config_filename(),
 
345
                                          'utf-8')])
 
346
 
 
347
 
 
348
class TestBranchConfig(TestCaseWithTransport):
 
349
 
 
350
    def test_constructs(self):
 
351
        branch = FakeBranch()
 
352
        my_config = config.BranchConfig(branch)
 
353
        self.assertRaises(TypeError, config.BranchConfig)
 
354
 
 
355
    def test_get_location_config(self):
 
356
        branch = FakeBranch()
 
357
        my_config = config.BranchConfig(branch)
 
358
        location_config = my_config._get_location_config()
 
359
        self.assertEqual(branch.base, location_config.location)
 
360
        self.failUnless(location_config is my_config._get_location_config())
 
361
 
 
362
    def test_get_config(self):
 
363
        """The Branch.get_config method works properly"""
 
364
        b = BzrDir.create_standalone_workingtree('.').branch
 
365
        my_config = b.get_config()
 
366
        self.assertIs(my_config.get_user_option('wacky'), None)
 
367
        my_config.set_user_option('wacky', 'unlikely')
 
368
        self.assertEqual(my_config.get_user_option('wacky'), 'unlikely')
 
369
 
 
370
        # Ensure we get the same thing if we start again
 
371
        b2 = Branch.open('.')
 
372
        my_config2 = b2.get_config()
 
373
        self.assertEqual(my_config2.get_user_option('wacky'), 'unlikely')
 
374
 
 
375
    def test_has_explicit_nickname(self):
 
376
        b = self.make_branch('.')
 
377
        self.assertFalse(b.get_config().has_explicit_nickname())
 
378
        b.nick = 'foo'
 
379
        self.assertTrue(b.get_config().has_explicit_nickname())
 
380
 
 
381
    def test_config_url(self):
 
382
        """The Branch.get_config will use section that uses a local url"""
 
383
        branch = self.make_branch('branch')
 
384
        self.assertEqual('branch', branch.nick)
 
385
 
 
386
        locations = config.locations_config_filename()
 
387
        config.ensure_config_dir_exists()
 
388
        local_url = urlutils.local_path_to_url('branch')
 
389
        open(locations, 'wb').write('[%s]\nnickname = foobar' 
 
390
                                    % (local_url,))
 
391
        self.assertEqual('foobar', branch.nick)
 
392
 
 
393
    def test_config_local_path(self):
 
394
        """The Branch.get_config will use a local system path"""
 
395
        branch = self.make_branch('branch')
 
396
        self.assertEqual('branch', branch.nick)
 
397
 
 
398
        locations = config.locations_config_filename()
 
399
        config.ensure_config_dir_exists()
 
400
        open(locations, 'wb').write('[%s/branch]\nnickname = barry' 
 
401
                                    % (osutils.getcwd().encode('utf8'),))
 
402
        self.assertEqual('barry', branch.nick)
 
403
 
 
404
    def test_config_creates_local(self):
 
405
        """Creating a new entry in config uses a local path."""
 
406
        branch = self.make_branch('branch', format='knit')
 
407
        branch.set_push_location('http://foobar')
 
408
        locations = config.locations_config_filename()
 
409
        local_path = osutils.getcwd().encode('utf8')
 
410
        # Surprisingly ConfigObj doesn't create a trailing newline
 
411
        self.check_file_contents(locations,
 
412
            '[%s/branch]\npush_location = http://foobar\npush_location:policy = norecurse' % (local_path,))
 
413
 
 
414
    def test_autonick_urlencoded(self):
 
415
        b = self.make_branch('!repo')
 
416
        self.assertEqual('!repo', b.get_config().get_nickname())
 
417
 
 
418
    def test_warn_if_masked(self):
 
419
        _warning = trace.warning
 
420
        warnings = []
 
421
        def warning(*args):
 
422
            warnings.append(args[0] % args[1:])
 
423
 
 
424
        def set_option(store, warn_masked=True):
 
425
            warnings[:] = []
 
426
            conf.set_user_option('example_option', repr(store), store=store,
 
427
                                 warn_masked=warn_masked)
 
428
        def assertWarning(warning):
 
429
            if warning is None:
 
430
                self.assertEqual(0, len(warnings))
 
431
            else:
 
432
                self.assertEqual(1, len(warnings))
 
433
                self.assertEqual(warning, warnings[0])
 
434
        trace.warning = warning
 
435
        try:
 
436
            branch = self.make_branch('.')
 
437
            conf = branch.get_config()
 
438
            set_option(config.STORE_GLOBAL)
 
439
            assertWarning(None)
 
440
            set_option(config.STORE_BRANCH)
 
441
            assertWarning(None)
 
442
            set_option(config.STORE_GLOBAL)
 
443
            assertWarning('Value "4" is masked by "3" from branch.conf')
 
444
            set_option(config.STORE_GLOBAL, warn_masked=False)
 
445
            assertWarning(None)
 
446
            set_option(config.STORE_LOCATION)
 
447
            assertWarning(None)
 
448
            set_option(config.STORE_BRANCH)
 
449
            assertWarning('Value "3" is masked by "0" from locations.conf')
 
450
            set_option(config.STORE_BRANCH, warn_masked=False)
 
451
            assertWarning(None)
 
452
        finally:
 
453
            trace.warning = _warning
 
454
 
 
455
 
 
456
class TestGlobalConfigItems(TestCase):
 
457
 
 
458
    def test_user_id(self):
 
459
        config_file = StringIO(sample_config_text.encode('utf-8'))
 
460
        my_config = config.GlobalConfig()
 
461
        my_config._parser = my_config._get_parser(file=config_file)
 
462
        self.assertEqual(u"Erik B\u00e5gfors <erik@bagfors.nu>",
 
463
                         my_config._get_user_id())
 
464
 
 
465
    def test_absent_user_id(self):
 
466
        config_file = StringIO("")
 
467
        my_config = config.GlobalConfig()
 
468
        my_config._parser = my_config._get_parser(file=config_file)
 
469
        self.assertEqual(None, my_config._get_user_id())
 
470
 
 
471
    def test_configured_editor(self):
 
472
        config_file = StringIO(sample_config_text.encode('utf-8'))
 
473
        my_config = config.GlobalConfig()
 
474
        my_config._parser = my_config._get_parser(file=config_file)
 
475
        self.assertEqual("vim", my_config.get_editor())
 
476
 
 
477
    def test_signatures_always(self):
 
478
        config_file = StringIO(sample_always_signatures)
 
479
        my_config = config.GlobalConfig()
 
480
        my_config._parser = my_config._get_parser(file=config_file)
 
481
        self.assertEqual(config.CHECK_NEVER,
 
482
                         my_config.signature_checking())
 
483
        self.assertEqual(config.SIGN_ALWAYS,
 
484
                         my_config.signing_policy())
 
485
        self.assertEqual(True, my_config.signature_needed())
 
486
 
 
487
    def test_signatures_if_possible(self):
 
488
        config_file = StringIO(sample_maybe_signatures)
 
489
        my_config = config.GlobalConfig()
 
490
        my_config._parser = my_config._get_parser(file=config_file)
 
491
        self.assertEqual(config.CHECK_NEVER,
 
492
                         my_config.signature_checking())
 
493
        self.assertEqual(config.SIGN_WHEN_REQUIRED,
 
494
                         my_config.signing_policy())
 
495
        self.assertEqual(False, my_config.signature_needed())
 
496
 
 
497
    def test_signatures_ignore(self):
 
498
        config_file = StringIO(sample_ignore_signatures)
 
499
        my_config = config.GlobalConfig()
 
500
        my_config._parser = my_config._get_parser(file=config_file)
 
501
        self.assertEqual(config.CHECK_ALWAYS,
 
502
                         my_config.signature_checking())
 
503
        self.assertEqual(config.SIGN_NEVER,
 
504
                         my_config.signing_policy())
 
505
        self.assertEqual(False, my_config.signature_needed())
 
506
 
 
507
    def _get_sample_config(self):
 
508
        config_file = StringIO(sample_config_text.encode('utf-8'))
 
509
        my_config = config.GlobalConfig()
 
510
        my_config._parser = my_config._get_parser(file=config_file)
 
511
        return my_config
 
512
 
 
513
    def test_gpg_signing_command(self):
 
514
        my_config = self._get_sample_config()
 
515
        self.assertEqual("gnome-gpg", my_config.gpg_signing_command())
 
516
        self.assertEqual(False, my_config.signature_needed())
 
517
 
 
518
    def _get_empty_config(self):
 
519
        config_file = StringIO("")
 
520
        my_config = config.GlobalConfig()
 
521
        my_config._parser = my_config._get_parser(file=config_file)
 
522
        return my_config
 
523
 
 
524
    def test_gpg_signing_command_unset(self):
 
525
        my_config = self._get_empty_config()
 
526
        self.assertEqual("gpg", my_config.gpg_signing_command())
 
527
 
 
528
    def test_get_user_option_default(self):
 
529
        my_config = self._get_empty_config()
 
530
        self.assertEqual(None, my_config.get_user_option('no_option'))
 
531
 
 
532
    def test_get_user_option_global(self):
 
533
        my_config = self._get_sample_config()
 
534
        self.assertEqual("something",
 
535
                         my_config.get_user_option('user_global_option'))
 
536
        
 
537
    def test_post_commit_default(self):
 
538
        my_config = self._get_sample_config()
 
539
        self.assertEqual(None, my_config.post_commit())
 
540
 
 
541
    def test_configured_logformat(self):
 
542
        my_config = self._get_sample_config()
 
543
        self.assertEqual("short", my_config.log_format())
 
544
 
 
545
    def test_get_alias(self):
 
546
        my_config = self._get_sample_config()
 
547
        self.assertEqual('help', my_config.get_alias('h'))
 
548
 
 
549
    def test_get_no_alias(self):
 
550
        my_config = self._get_sample_config()
 
551
        self.assertEqual(None, my_config.get_alias('foo'))
 
552
 
 
553
    def test_get_long_alias(self):
 
554
        my_config = self._get_sample_config()
 
555
        self.assertEqual(sample_long_alias, my_config.get_alias('ll'))
 
556
 
 
557
 
 
558
class TestLocationConfig(TestCaseInTempDir):
 
559
 
 
560
    def test_constructs(self):
 
561
        my_config = config.LocationConfig('http://example.com')
 
562
        self.assertRaises(TypeError, config.LocationConfig)
 
563
 
 
564
    def test_branch_calls_read_filenames(self):
 
565
        # This is testing the correct file names are provided.
 
566
        # TODO: consolidate with the test for GlobalConfigs filename checks.
 
567
        #
 
568
        # replace the class that is constructured, to check its parameters
 
569
        oldparserclass = config.ConfigObj
 
570
        config.ConfigObj = InstrumentedConfigObj
 
571
        try:
 
572
            my_config = config.LocationConfig('http://www.example.com')
 
573
            parser = my_config._get_parser()
 
574
        finally:
 
575
            config.ConfigObj = oldparserclass
 
576
        self.failUnless(isinstance(parser, InstrumentedConfigObj))
 
577
        self.assertEqual(parser._calls,
 
578
                         [('__init__', config.locations_config_filename(),
 
579
                           'utf-8')])
 
580
        config.ensure_config_dir_exists()
 
581
        #os.mkdir(config.config_dir())
 
582
        f = file(config.branches_config_filename(), 'wb')
 
583
        f.write('')
 
584
        f.close()
 
585
        oldparserclass = config.ConfigObj
 
586
        config.ConfigObj = InstrumentedConfigObj
 
587
        try:
 
588
            my_config = config.LocationConfig('http://www.example.com')
 
589
            parser = my_config._get_parser()
 
590
        finally:
 
591
            config.ConfigObj = oldparserclass
 
592
 
 
593
    def test_get_global_config(self):
 
594
        my_config = config.BranchConfig(FakeBranch('http://example.com'))
 
595
        global_config = my_config._get_global_config()
 
596
        self.failUnless(isinstance(global_config, config.GlobalConfig))
 
597
        self.failUnless(global_config is my_config._get_global_config())
 
598
 
 
599
    def test__get_matching_sections_no_match(self):
 
600
        self.get_branch_config('/')
 
601
        self.assertEqual([], self.my_location_config._get_matching_sections())
 
602
        
 
603
    def test__get_matching_sections_exact(self):
 
604
        self.get_branch_config('http://www.example.com')
 
605
        self.assertEqual([('http://www.example.com', '')],
 
606
                         self.my_location_config._get_matching_sections())
 
607
   
 
608
    def test__get_matching_sections_suffix_does_not(self):
 
609
        self.get_branch_config('http://www.example.com-com')
 
610
        self.assertEqual([], self.my_location_config._get_matching_sections())
 
611
 
 
612
    def test__get_matching_sections_subdir_recursive(self):
 
613
        self.get_branch_config('http://www.example.com/com')
 
614
        self.assertEqual([('http://www.example.com', 'com')],
 
615
                         self.my_location_config._get_matching_sections())
 
616
 
 
617
    def test__get_matching_sections_ignoreparent(self):
 
618
        self.get_branch_config('http://www.example.com/ignoreparent')
 
619
        self.assertEqual([('http://www.example.com/ignoreparent', '')],
 
620
                         self.my_location_config._get_matching_sections())
 
621
 
 
622
    def test__get_matching_sections_ignoreparent_subdir(self):
 
623
        self.get_branch_config(
 
624
            'http://www.example.com/ignoreparent/childbranch')
 
625
        self.assertEqual([('http://www.example.com/ignoreparent', 'childbranch')],
 
626
                         self.my_location_config._get_matching_sections())
 
627
 
 
628
    def test__get_matching_sections_subdir_trailing_slash(self):
 
629
        self.get_branch_config('/b')
 
630
        self.assertEqual([('/b/', '')],
 
631
                         self.my_location_config._get_matching_sections())
 
632
 
 
633
    def test__get_matching_sections_subdir_child(self):
 
634
        self.get_branch_config('/a/foo')
 
635
        self.assertEqual([('/a/*', ''), ('/a/', 'foo')],
 
636
                         self.my_location_config._get_matching_sections())
 
637
 
 
638
    def test__get_matching_sections_subdir_child_child(self):
 
639
        self.get_branch_config('/a/foo/bar')
 
640
        self.assertEqual([('/a/*', 'bar'), ('/a/', 'foo/bar')],
 
641
                         self.my_location_config._get_matching_sections())
 
642
 
 
643
    def test__get_matching_sections_trailing_slash_with_children(self):
 
644
        self.get_branch_config('/a/')
 
645
        self.assertEqual([('/a/', '')],
 
646
                         self.my_location_config._get_matching_sections())
 
647
 
 
648
    def test__get_matching_sections_explicit_over_glob(self):
 
649
        # XXX: 2006-09-08 jamesh
 
650
        # This test only passes because ord('c') > ord('*').  If there
 
651
        # was a config section for '/a/?', it would get precedence
 
652
        # over '/a/c'.
 
653
        self.get_branch_config('/a/c')
 
654
        self.assertEqual([('/a/c', ''), ('/a/*', ''), ('/a/', 'c')],
 
655
                         self.my_location_config._get_matching_sections())
 
656
 
 
657
    def test__get_option_policy_normal(self):
 
658
        self.get_branch_config('http://www.example.com')
 
659
        self.assertEqual(
 
660
            self.my_location_config._get_config_policy(
 
661
            'http://www.example.com', 'normal_option'),
 
662
            config.POLICY_NONE)
 
663
 
 
664
    def test__get_option_policy_norecurse(self):
 
665
        self.get_branch_config('http://www.example.com')
 
666
        self.assertEqual(
 
667
            self.my_location_config._get_option_policy(
 
668
            'http://www.example.com', 'norecurse_option'),
 
669
            config.POLICY_NORECURSE)
 
670
        # Test old recurse=False setting:
 
671
        self.assertEqual(
 
672
            self.my_location_config._get_option_policy(
 
673
            'http://www.example.com/norecurse', 'normal_option'),
 
674
            config.POLICY_NORECURSE)
 
675
 
 
676
    def test__get_option_policy_normal(self):
 
677
        self.get_branch_config('http://www.example.com')
 
678
        self.assertEqual(
 
679
            self.my_location_config._get_option_policy(
 
680
            'http://www.example.com', 'appendpath_option'),
 
681
            config.POLICY_APPENDPATH)
 
682
 
 
683
    def test_location_without_username(self):
 
684
        self.get_branch_config('http://www.example.com/ignoreparent')
 
685
        self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>',
 
686
                         self.my_config.username())
 
687
 
 
688
    def test_location_not_listed(self):
 
689
        """Test that the global username is used when no location matches"""
 
690
        self.get_branch_config('/home/robertc/sources')
 
691
        self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>',
 
692
                         self.my_config.username())
 
693
 
 
694
    def test_overriding_location(self):
 
695
        self.get_branch_config('http://www.example.com/foo')
 
696
        self.assertEqual('Robert Collins <robertc@example.org>',
 
697
                         self.my_config.username())
 
698
 
 
699
    def test_signatures_not_set(self):
 
700
        self.get_branch_config('http://www.example.com',
 
701
                                 global_config=sample_ignore_signatures)
 
702
        self.assertEqual(config.CHECK_ALWAYS,
 
703
                         self.my_config.signature_checking())
 
704
        self.assertEqual(config.SIGN_NEVER,
 
705
                         self.my_config.signing_policy())
 
706
 
 
707
    def test_signatures_never(self):
 
708
        self.get_branch_config('/a/c')
 
709
        self.assertEqual(config.CHECK_NEVER,
 
710
                         self.my_config.signature_checking())
 
711
        
 
712
    def test_signatures_when_available(self):
 
713
        self.get_branch_config('/a/', global_config=sample_ignore_signatures)
 
714
        self.assertEqual(config.CHECK_IF_POSSIBLE,
 
715
                         self.my_config.signature_checking())
 
716
        
 
717
    def test_signatures_always(self):
 
718
        self.get_branch_config('/b')
 
719
        self.assertEqual(config.CHECK_ALWAYS,
 
720
                         self.my_config.signature_checking())
 
721
        
 
722
    def test_gpg_signing_command(self):
 
723
        self.get_branch_config('/b')
 
724
        self.assertEqual("gnome-gpg", self.my_config.gpg_signing_command())
 
725
 
 
726
    def test_gpg_signing_command_missing(self):
 
727
        self.get_branch_config('/a')
 
728
        self.assertEqual("false", self.my_config.gpg_signing_command())
 
729
 
 
730
    def test_get_user_option_global(self):
 
731
        self.get_branch_config('/a')
 
732
        self.assertEqual('something',
 
733
                         self.my_config.get_user_option('user_global_option'))
 
734
 
 
735
    def test_get_user_option_local(self):
 
736
        self.get_branch_config('/a')
 
737
        self.assertEqual('local',
 
738
                         self.my_config.get_user_option('user_local_option'))
 
739
 
 
740
    def test_get_user_option_appendpath(self):
 
741
        # returned as is for the base path:
 
742
        self.get_branch_config('http://www.example.com')
 
743
        self.assertEqual('append',
 
744
                         self.my_config.get_user_option('appendpath_option'))
 
745
        # Extra path components get appended:
 
746
        self.get_branch_config('http://www.example.com/a/b/c')
 
747
        self.assertEqual('append/a/b/c',
 
748
                         self.my_config.get_user_option('appendpath_option'))
 
749
        # Overriden for http://www.example.com/dir, where it is a
 
750
        # normal option:
 
751
        self.get_branch_config('http://www.example.com/dir/a/b/c')
 
752
        self.assertEqual('normal',
 
753
                         self.my_config.get_user_option('appendpath_option'))
 
754
 
 
755
    def test_get_user_option_norecurse(self):
 
756
        self.get_branch_config('http://www.example.com')
 
757
        self.assertEqual('norecurse',
 
758
                         self.my_config.get_user_option('norecurse_option'))
 
759
        self.get_branch_config('http://www.example.com/dir')
 
760
        self.assertEqual(None,
 
761
                         self.my_config.get_user_option('norecurse_option'))
 
762
        # http://www.example.com/norecurse is a recurse=False section
 
763
        # that redefines normal_option.  Subdirectories do not pick up
 
764
        # this redefinition.
 
765
        self.get_branch_config('http://www.example.com/norecurse')
 
766
        self.assertEqual('norecurse',
 
767
                         self.my_config.get_user_option('normal_option'))
 
768
        self.get_branch_config('http://www.example.com/norecurse/subdir')
 
769
        self.assertEqual('normal',
 
770
                         self.my_config.get_user_option('normal_option'))
 
771
 
 
772
    def test_set_user_option_norecurse(self):
 
773
        self.get_branch_config('http://www.example.com')
 
774
        self.my_config.set_user_option('foo', 'bar',
 
775
                                       store=config.STORE_LOCATION_NORECURSE)
 
776
        self.assertEqual(
 
777
            self.my_location_config._get_option_policy(
 
778
            'http://www.example.com', 'foo'),
 
779
            config.POLICY_NORECURSE)
 
780
 
 
781
    def test_set_user_option_appendpath(self):
 
782
        self.get_branch_config('http://www.example.com')
 
783
        self.my_config.set_user_option('foo', 'bar',
 
784
                                       store=config.STORE_LOCATION_APPENDPATH)
 
785
        self.assertEqual(
 
786
            self.my_location_config._get_option_policy(
 
787
            'http://www.example.com', 'foo'),
 
788
            config.POLICY_APPENDPATH)
 
789
 
 
790
    def test_set_user_option_change_policy(self):
 
791
        self.get_branch_config('http://www.example.com')
 
792
        self.my_config.set_user_option('norecurse_option', 'normal',
 
793
                                       store=config.STORE_LOCATION)
 
794
        self.assertEqual(
 
795
            self.my_location_config._get_option_policy(
 
796
            'http://www.example.com', 'norecurse_option'),
 
797
            config.POLICY_NONE)
 
798
 
 
799
    def test_set_user_option_recurse_false_section(self):
 
800
        # The following section has recurse=False set.  The test is to
 
801
        # make sure that a normal option can be added to the section,
 
802
        # converting recurse=False to the norecurse policy.
 
803
        self.get_branch_config('http://www.example.com/norecurse')
 
804
        self.callDeprecated(['The recurse option is deprecated as of 0.14.  '
 
805
                             'The section "http://www.example.com/norecurse" '
 
806
                             'has been converted to use policies.'],
 
807
                            self.my_config.set_user_option,
 
808
                            'foo', 'bar', store=config.STORE_LOCATION)
 
809
        self.assertEqual(
 
810
            self.my_location_config._get_option_policy(
 
811
            'http://www.example.com/norecurse', 'foo'),
 
812
            config.POLICY_NONE)
 
813
        # The previously existing option is still norecurse:
 
814
        self.assertEqual(
 
815
            self.my_location_config._get_option_policy(
 
816
            'http://www.example.com/norecurse', 'normal_option'),
 
817
            config.POLICY_NORECURSE)
 
818
 
 
819
    def test_post_commit_default(self):
 
820
        self.get_branch_config('/a/c')
 
821
        self.assertEqual('bzrlib.tests.test_config.post_commit',
 
822
                         self.my_config.post_commit())
 
823
 
 
824
    def get_branch_config(self, location, global_config=None):
 
825
        if global_config is None:
 
826
            global_file = StringIO(sample_config_text.encode('utf-8'))
 
827
        else:
 
828
            global_file = StringIO(global_config.encode('utf-8'))
 
829
        branches_file = StringIO(sample_branches_text.encode('utf-8'))
 
830
        self.my_config = config.BranchConfig(FakeBranch(location))
 
831
        # Force location config to use specified file
 
832
        self.my_location_config = self.my_config._get_location_config()
 
833
        self.my_location_config._get_parser(branches_file)
 
834
        # Force global config to use specified file
 
835
        self.my_config._get_global_config()._get_parser(global_file)
 
836
 
 
837
    def test_set_user_setting_sets_and_saves(self):
 
838
        self.get_branch_config('/a/c')
 
839
        record = InstrumentedConfigObj("foo")
 
840
        self.my_location_config._parser = record
 
841
 
 
842
        real_mkdir = os.mkdir
 
843
        self.created = False
 
844
        def checked_mkdir(path, mode=0777):
 
845
            self.log('making directory: %s', path)
 
846
            real_mkdir(path, mode)
 
847
            self.created = True
 
848
 
 
849
        os.mkdir = checked_mkdir
 
850
        try:
 
851
            self.callDeprecated(['The recurse option is deprecated as of '
 
852
                                 '0.14.  The section "/a/c" has been '
 
853
                                 'converted to use policies.'],
 
854
                                self.my_config.set_user_option,
 
855
                                'foo', 'bar', store=config.STORE_LOCATION)
 
856
        finally:
 
857
            os.mkdir = real_mkdir
 
858
 
 
859
        self.failUnless(self.created, 'Failed to create ~/.bazaar')
 
860
        self.assertEqual([('__contains__', '/a/c'),
 
861
                          ('__contains__', '/a/c/'),
 
862
                          ('__setitem__', '/a/c', {}),
 
863
                          ('__getitem__', '/a/c'),
 
864
                          ('__setitem__', 'foo', 'bar'),
 
865
                          ('__getitem__', '/a/c'),
 
866
                          ('as_bool', 'recurse'),
 
867
                          ('__getitem__', '/a/c'),
 
868
                          ('__delitem__', 'recurse'),
 
869
                          ('__getitem__', '/a/c'),
 
870
                          ('keys',),
 
871
                          ('__getitem__', '/a/c'),
 
872
                          ('__contains__', 'foo:policy'),
 
873
                          ('write',)],
 
874
                         record._calls[1:])
 
875
 
 
876
    def test_set_user_setting_sets_and_saves2(self):
 
877
        self.get_branch_config('/a/c')
 
878
        self.assertIs(self.my_config.get_user_option('foo'), None)
 
879
        self.my_config.set_user_option('foo', 'bar')
 
880
        self.assertEqual(
 
881
            self.my_config.branch.control_files.files['branch.conf'], 
 
882
            'foo = bar')
 
883
        self.assertEqual(self.my_config.get_user_option('foo'), 'bar')
 
884
        self.my_config.set_user_option('foo', 'baz',
 
885
                                       store=config.STORE_LOCATION)
 
886
        self.assertEqual(self.my_config.get_user_option('foo'), 'baz')
 
887
        self.my_config.set_user_option('foo', 'qux')
 
888
        self.assertEqual(self.my_config.get_user_option('foo'), 'baz')
 
889
        
 
890
 
 
891
precedence_global = 'option = global'
 
892
precedence_branch = 'option = branch'
 
893
precedence_location = """
 
894
[http://]
 
895
recurse = true
 
896
option = recurse
 
897
[http://example.com/specific]
 
898
option = exact
 
899
"""
 
900
 
 
901
 
 
902
class TestBranchConfigItems(TestCaseInTempDir):
 
903
 
 
904
    def get_branch_config(self, global_config=None, location=None, 
 
905
                          location_config=None, branch_data_config=None):
 
906
        my_config = config.BranchConfig(FakeBranch(location))
 
907
        if global_config is not None:
 
908
            global_file = StringIO(global_config.encode('utf-8'))
 
909
            my_config._get_global_config()._get_parser(global_file)
 
910
        self.my_location_config = my_config._get_location_config()
 
911
        if location_config is not None:
 
912
            location_file = StringIO(location_config.encode('utf-8'))
 
913
            self.my_location_config._get_parser(location_file)
 
914
        if branch_data_config is not None:
 
915
            my_config.branch.control_files.files['branch.conf'] = \
 
916
                branch_data_config
 
917
        return my_config
 
918
 
 
919
    def test_user_id(self):
 
920
        branch = FakeBranch(user_id='Robert Collins <robertc@example.net>')
 
921
        my_config = config.BranchConfig(branch)
 
922
        self.assertEqual("Robert Collins <robertc@example.net>",
 
923
                         my_config.username())
 
924
        branch.control_files.email = "John"
 
925
        my_config.set_user_option('email', 
 
926
                                  "Robert Collins <robertc@example.org>")
 
927
        self.assertEqual("John", my_config.username())
 
928
        branch.control_files.email = None
 
929
        self.assertEqual("Robert Collins <robertc@example.org>",
 
930
                         my_config.username())
 
931
 
 
932
    def test_not_set_in_branch(self):
 
933
        my_config = self.get_branch_config(sample_config_text)
 
934
        my_config.branch.control_files.email = None
 
935
        self.assertEqual(u"Erik B\u00e5gfors <erik@bagfors.nu>",
 
936
                         my_config._get_user_id())
 
937
        my_config.branch.control_files.email = "John"
 
938
        self.assertEqual("John", my_config._get_user_id())
 
939
 
 
940
    def test_BZR_EMAIL_OVERRIDES(self):
 
941
        os.environ['BZR_EMAIL'] = "Robert Collins <robertc@example.org>"
 
942
        branch = FakeBranch()
 
943
        my_config = config.BranchConfig(branch)
 
944
        self.assertEqual("Robert Collins <robertc@example.org>",
 
945
                         my_config.username())
 
946
    
 
947
    def test_signatures_forced(self):
 
948
        my_config = self.get_branch_config(
 
949
            global_config=sample_always_signatures)
 
950
        self.assertEqual(config.CHECK_NEVER, my_config.signature_checking())
 
951
        self.assertEqual(config.SIGN_ALWAYS, my_config.signing_policy())
 
952
        self.assertTrue(my_config.signature_needed())
 
953
 
 
954
    def test_signatures_forced_branch(self):
 
955
        my_config = self.get_branch_config(
 
956
            global_config=sample_ignore_signatures,
 
957
            branch_data_config=sample_always_signatures)
 
958
        self.assertEqual(config.CHECK_NEVER, my_config.signature_checking())
 
959
        self.assertEqual(config.SIGN_ALWAYS, my_config.signing_policy())
 
960
        self.assertTrue(my_config.signature_needed())
 
961
 
 
962
    def test_gpg_signing_command(self):
 
963
        my_config = self.get_branch_config(
 
964
            # branch data cannot set gpg_signing_command
 
965
            branch_data_config="gpg_signing_command=pgp")
 
966
        config_file = StringIO(sample_config_text.encode('utf-8'))
 
967
        my_config._get_global_config()._get_parser(config_file)
 
968
        self.assertEqual('gnome-gpg', my_config.gpg_signing_command())
 
969
 
 
970
    def test_get_user_option_global(self):
 
971
        branch = FakeBranch()
 
972
        my_config = config.BranchConfig(branch)
 
973
        config_file = StringIO(sample_config_text.encode('utf-8'))
 
974
        (my_config._get_global_config()._get_parser(config_file))
 
975
        self.assertEqual('something',
 
976
                         my_config.get_user_option('user_global_option'))
 
977
 
 
978
    def test_post_commit_default(self):
 
979
        branch = FakeBranch()
 
980
        my_config = self.get_branch_config(sample_config_text, '/a/c',
 
981
                                           sample_branches_text)
 
982
        self.assertEqual(my_config.branch.base, '/a/c')
 
983
        self.assertEqual('bzrlib.tests.test_config.post_commit',
 
984
                         my_config.post_commit())
 
985
        my_config.set_user_option('post_commit', 'rmtree_root')
 
986
        # post-commit is ignored when bresent in branch data
 
987
        self.assertEqual('bzrlib.tests.test_config.post_commit',
 
988
                         my_config.post_commit())
 
989
        my_config.set_user_option('post_commit', 'rmtree_root',
 
990
                                  store=config.STORE_LOCATION)
 
991
        self.assertEqual('rmtree_root', my_config.post_commit())
 
992
 
 
993
    def test_config_precedence(self):
 
994
        my_config = self.get_branch_config(global_config=precedence_global)
 
995
        self.assertEqual(my_config.get_user_option('option'), 'global')
 
996
        my_config = self.get_branch_config(global_config=precedence_global, 
 
997
                                      branch_data_config=precedence_branch)
 
998
        self.assertEqual(my_config.get_user_option('option'), 'branch')
 
999
        my_config = self.get_branch_config(global_config=precedence_global, 
 
1000
                                      branch_data_config=precedence_branch,
 
1001
                                      location_config=precedence_location)
 
1002
        self.assertEqual(my_config.get_user_option('option'), 'recurse')
 
1003
        my_config = self.get_branch_config(global_config=precedence_global, 
 
1004
                                      branch_data_config=precedence_branch,
 
1005
                                      location_config=precedence_location,
 
1006
                                      location='http://example.com/specific')
 
1007
        self.assertEqual(my_config.get_user_option('option'), 'exact')
 
1008
 
 
1009
    def test_get_mail_client(self):
 
1010
        config = self.get_branch_config()
 
1011
        client = config.get_mail_client()
 
1012
        self.assertIsInstance(client, mail_client.DefaultMail)
 
1013
 
 
1014
        config.set_user_option('mail_client', 'default')
 
1015
        client = config.get_mail_client()
 
1016
        self.assertIsInstance(client, mail_client.DefaultMail)
 
1017
 
 
1018
        config.set_user_option('mail_client', 'editor')
 
1019
        client = config.get_mail_client()
 
1020
        self.assertIsInstance(client, mail_client.Editor)
 
1021
 
 
1022
        config.set_user_option('mail_client', 'thunderbird')
 
1023
        client = config.get_mail_client()
 
1024
        self.assertIsInstance(client, mail_client.Thunderbird)
 
1025
 
 
1026
        config.set_user_option('mail_client', 'evolution')
 
1027
        client = config.get_mail_client()
 
1028
        self.assertIsInstance(client, mail_client.Evolution)
 
1029
 
 
1030
        config.set_user_option('mail_client', 'kmail')
 
1031
        client = config.get_mail_client()
 
1032
        self.assertIsInstance(client, mail_client.KMail)
 
1033
 
 
1034
        config.set_user_option('mail_client', 'xdg-email')
 
1035
        client = config.get_mail_client()
 
1036
        self.assertIsInstance(client, mail_client.XDGEmail)
 
1037
 
 
1038
        config.set_user_option('mail_client', 'mapi')
 
1039
        client = config.get_mail_client()
 
1040
        self.assertIsInstance(client, mail_client.MAPIClient)
 
1041
 
 
1042
        config.set_user_option('mail_client', 'firebird')
 
1043
        self.assertRaises(errors.UnknownMailClient, config.get_mail_client)
 
1044
 
 
1045
 
 
1046
class TestMailAddressExtraction(TestCase):
 
1047
 
 
1048
    def test_extract_email_address(self):
 
1049
        self.assertEqual('jane@test.com',
 
1050
                         config.extract_email_address('Jane <jane@test.com>'))
 
1051
        self.assertRaises(errors.NoEmailInUsername,
 
1052
                          config.extract_email_address, 'Jane Tester')
 
1053
 
 
1054
 
 
1055
class TestTreeConfig(TestCaseWithTransport):
 
1056
 
 
1057
    def test_get_value(self):
 
1058
        """Test that retreiving a value from a section is possible"""
 
1059
        branch = self.make_branch('.')
 
1060
        tree_config = config.TreeConfig(branch)
 
1061
        tree_config.set_option('value', 'key', 'SECTION')
 
1062
        tree_config.set_option('value2', 'key2')
 
1063
        tree_config.set_option('value3-top', 'key3')
 
1064
        tree_config.set_option('value3-section', 'key3', 'SECTION')
 
1065
        value = tree_config.get_option('key', 'SECTION')
 
1066
        self.assertEqual(value, 'value')
 
1067
        value = tree_config.get_option('key2')
 
1068
        self.assertEqual(value, 'value2')
 
1069
        self.assertEqual(tree_config.get_option('non-existant'), None)
 
1070
        value = tree_config.get_option('non-existant', 'SECTION')
 
1071
        self.assertEqual(value, None)
 
1072
        value = tree_config.get_option('non-existant', default='default')
 
1073
        self.assertEqual(value, 'default')
 
1074
        self.assertEqual(tree_config.get_option('key2', 'NOSECTION'), None)
 
1075
        value = tree_config.get_option('key2', 'NOSECTION', default='default')
 
1076
        self.assertEqual(value, 'default')
 
1077
        value = tree_config.get_option('key3')
 
1078
        self.assertEqual(value, 'value3-top')
 
1079
        value = tree_config.get_option('key3', 'SECTION')
 
1080
        self.assertEqual(value, 'value3-section')