~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-08-17 07:52:09 UTC
  • mfrom: (1910.3.4 trivial)
  • Revision ID: pqm@pqm.ubuntu.com-20060817075209-e85a1f9e05ff8b87
(andrew) Trivial fixes to NotImplemented errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 by Canonical Ltd
2
2
#   Authors: Robert Collins <robert.collins@canonical.com>
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
27
27
    config,
28
28
    errors,
29
29
    osutils,
30
 
    mail_client,
31
30
    urlutils,
32
 
    trace,
33
31
    )
34
32
from bzrlib.branch import Branch
35
33
from bzrlib.bzrdir import BzrDir
37
35
 
38
36
 
39
37
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
 
"""
 
38
sample_config_text = ("[DEFAULT]\n"
 
39
                      u"email=Erik B\u00e5gfors <erik@bagfors.nu>\n"
 
40
                      "editor=vim\n"
 
41
                      "gpg_signing_command=gnome-gpg\n"
 
42
                      "log_format=short\n"
 
43
                      "user_global_option=something\n"
 
44
                      "[ALIASES]\n"
 
45
                      "h=help\n"
 
46
                      "ll=" + sample_long_alias + "\n")
 
47
 
 
48
 
 
49
sample_always_signatures = ("[DEFAULT]\n"
 
50
                            "check_signatures=ignore\n"
 
51
                            "create_signatures=always")
 
52
 
 
53
 
 
54
sample_ignore_signatures = ("[DEFAULT]\n"
 
55
                            "check_signatures=require\n"
 
56
                            "create_signatures=never")
 
57
 
 
58
 
 
59
sample_maybe_signatures = ("[DEFAULT]\n"
 
60
                            "check_signatures=ignore\n"
 
61
                            "create_signatures=when-required")
 
62
 
 
63
 
 
64
sample_branches_text = ("[http://www.example.com]\n"
 
65
                        "# Top level policy\n"
 
66
                        "email=Robert Collins <robertc@example.org>\n"
 
67
                        "[http://www.example.com/useglobal]\n"
 
68
                        "# different project, forces global lookup\n"
 
69
                        "recurse=false\n"
 
70
                        "[/b/]\n"
 
71
                        "check_signatures=require\n"
 
72
                        "# test trailing / matching with no children\n"
 
73
                        "[/a/]\n"
 
74
                        "check_signatures=check-available\n"
 
75
                        "gpg_signing_command=false\n"
 
76
                        "user_local_option=local\n"
 
77
                        "# test trailing / matching\n"
 
78
                        "[/a/*]\n"
 
79
                        "#subdirs will match but not the parent\n"
 
80
                        "recurse=False\n"
 
81
                        "[/a/c]\n"
 
82
                        "check_signatures=ignore\n"
 
83
                        "post_commit=bzrlib.tests.test_config.post_commit\n"
 
84
                        "#testing explicit beats globs\n")
 
85
 
103
86
 
104
87
 
105
88
class InstrumentedConfigObj(object):
119
102
    def __setitem__(self, key, value):
120
103
        self._calls.append(('__setitem__', key, value))
121
104
 
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
105
    def write(self, arg):
130
106
        self._calls.append(('write',))
131
107
 
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
108
 
141
109
class FakeBranch(object):
142
110
 
211
179
        self.assertIs(co.get_bool('UPPERCASE', 'nonactive'), False)
212
180
 
213
181
 
214
 
erroneous_config = """[section] # line 1
215
 
good=good # line 2
216
 
[section] # line 3
217
 
whocares=notme # line 4
218
 
"""
219
 
class TestConfigObjErrors(TestCase):
220
 
 
221
 
    def test_duplicate_section_name_error_line(self):
222
 
        try:
223
 
            co = ConfigObj(StringIO(erroneous_config), raise_errors=True)
224
 
        except config.configobj.DuplicateError, e:
225
 
            self.assertEqual(3, e.line_number)
226
 
        else:
227
 
            self.fail('Error in config file not detected')
228
 
 
229
182
class TestConfig(TestCase):
230
183
 
231
184
    def test_constructs(self):
286
239
 
287
240
    def setUp(self):
288
241
        super(TestConfigPath, self).setUp()
 
242
        self.old_home = os.environ.get('HOME', None)
 
243
        self.old_appdata = os.environ.get('APPDATA', None)
289
244
        os.environ['HOME'] = '/home/bogus'
290
 
        if sys.platform == 'win32':
291
 
            os.environ['BZR_HOME'] = \
292
 
                r'C:\Documents and Settings\bogus\Application Data'
 
245
        os.environ['APPDATA'] = \
 
246
            r'C:\Documents and Settings\bogus\Application Data'
293
247
 
 
248
    def tearDown(self):
 
249
        if self.old_home is None:
 
250
            del os.environ['HOME']
 
251
        else:
 
252
            os.environ['HOME'] = self.old_home
 
253
        if self.old_appdata is None:
 
254
            del os.environ['APPDATA']
 
255
        else:
 
256
            os.environ['APPDATA'] = self.old_appdata
 
257
        super(TestConfigPath, self).tearDown()
 
258
    
294
259
    def test_config_dir(self):
295
260
        if sys.platform == 'win32':
296
261
            self.assertEqual(config.config_dir(), 
418
383
 
419
384
    def test_config_creates_local(self):
420
385
        """Creating a new entry in config uses a local path."""
421
 
        branch = self.make_branch('branch', format='knit')
 
386
        branch = self.make_branch('branch')
422
387
        branch.set_push_location('http://foobar')
423
388
        locations = config.locations_config_filename()
424
389
        local_path = osutils.getcwd().encode('utf8')
425
390
        # Surprisingly ConfigObj doesn't create a trailing newline
426
391
        self.check_file_contents(locations,
427
 
            '[%s/branch]\npush_location = http://foobar\npush_location:policy = norecurse' % (local_path,))
428
 
 
429
 
    def test_autonick_urlencoded(self):
430
 
        b = self.make_branch('!repo')
431
 
        self.assertEqual('!repo', b.get_config().get_nickname())
432
 
 
433
 
    def test_warn_if_masked(self):
434
 
        _warning = trace.warning
435
 
        warnings = []
436
 
        def warning(*args):
437
 
            warnings.append(args[0] % args[1:])
438
 
 
439
 
        def set_option(store, warn_masked=True):
440
 
            warnings[:] = []
441
 
            conf.set_user_option('example_option', repr(store), store=store,
442
 
                                 warn_masked=warn_masked)
443
 
        def assertWarning(warning):
444
 
            if warning is None:
445
 
                self.assertEqual(0, len(warnings))
446
 
            else:
447
 
                self.assertEqual(1, len(warnings))
448
 
                self.assertEqual(warning, warnings[0])
449
 
        trace.warning = warning
450
 
        try:
451
 
            branch = self.make_branch('.')
452
 
            conf = branch.get_config()
453
 
            set_option(config.STORE_GLOBAL)
454
 
            assertWarning(None)
455
 
            set_option(config.STORE_BRANCH)
456
 
            assertWarning(None)
457
 
            set_option(config.STORE_GLOBAL)
458
 
            assertWarning('Value "4" is masked by "3" from branch.conf')
459
 
            set_option(config.STORE_GLOBAL, warn_masked=False)
460
 
            assertWarning(None)
461
 
            set_option(config.STORE_LOCATION)
462
 
            assertWarning(None)
463
 
            set_option(config.STORE_BRANCH)
464
 
            assertWarning('Value "3" is masked by "0" from locations.conf')
465
 
            set_option(config.STORE_BRANCH, warn_masked=False)
466
 
            assertWarning(None)
467
 
        finally:
468
 
            trace.warning = _warning
 
392
            '[%s/branch]\npush_location = http://foobar' % (local_path,))
469
393
 
470
394
 
471
395
class TestGlobalConfigItems(TestCase):
611
535
        self.failUnless(isinstance(global_config, config.GlobalConfig))
612
536
        self.failUnless(global_config is my_config._get_global_config())
613
537
 
614
 
    def test__get_matching_sections_no_match(self):
 
538
    def test__get_section_no_match(self):
615
539
        self.get_branch_config('/')
616
 
        self.assertEqual([], self.my_location_config._get_matching_sections())
 
540
        self.assertEqual(None, self.my_location_config._get_section())
617
541
        
618
 
    def test__get_matching_sections_exact(self):
 
542
    def test__get_section_exact(self):
619
543
        self.get_branch_config('http://www.example.com')
620
 
        self.assertEqual([('http://www.example.com', '')],
621
 
                         self.my_location_config._get_matching_sections())
 
544
        self.assertEqual('http://www.example.com',
 
545
                         self.my_location_config._get_section())
622
546
   
623
 
    def test__get_matching_sections_suffix_does_not(self):
 
547
    def test__get_section_suffix_does_not(self):
624
548
        self.get_branch_config('http://www.example.com-com')
625
 
        self.assertEqual([], self.my_location_config._get_matching_sections())
 
549
        self.assertEqual(None, self.my_location_config._get_section())
626
550
 
627
 
    def test__get_matching_sections_subdir_recursive(self):
 
551
    def test__get_section_subdir_recursive(self):
628
552
        self.get_branch_config('http://www.example.com/com')
629
 
        self.assertEqual([('http://www.example.com', 'com')],
630
 
                         self.my_location_config._get_matching_sections())
631
 
 
632
 
    def test__get_matching_sections_ignoreparent(self):
633
 
        self.get_branch_config('http://www.example.com/ignoreparent')
634
 
        self.assertEqual([('http://www.example.com/ignoreparent', '')],
635
 
                         self.my_location_config._get_matching_sections())
636
 
 
637
 
    def test__get_matching_sections_ignoreparent_subdir(self):
 
553
        self.assertEqual('http://www.example.com',
 
554
                         self.my_location_config._get_section())
 
555
 
 
556
    def test__get_section_subdir_matches(self):
 
557
        self.get_branch_config('http://www.example.com/useglobal')
 
558
        self.assertEqual('http://www.example.com/useglobal',
 
559
                         self.my_location_config._get_section())
 
560
 
 
561
    def test__get_section_subdir_nonrecursive(self):
638
562
        self.get_branch_config(
639
 
            'http://www.example.com/ignoreparent/childbranch')
640
 
        self.assertEqual([('http://www.example.com/ignoreparent', 'childbranch')],
641
 
                         self.my_location_config._get_matching_sections())
 
563
            'http://www.example.com/useglobal/childbranch')
 
564
        self.assertEqual('http://www.example.com',
 
565
                         self.my_location_config._get_section())
642
566
 
643
 
    def test__get_matching_sections_subdir_trailing_slash(self):
 
567
    def test__get_section_subdir_trailing_slash(self):
644
568
        self.get_branch_config('/b')
645
 
        self.assertEqual([('/b/', '')],
646
 
                         self.my_location_config._get_matching_sections())
 
569
        self.assertEqual('/b/', self.my_location_config._get_section())
647
570
 
648
 
    def test__get_matching_sections_subdir_child(self):
 
571
    def test__get_section_subdir_child(self):
649
572
        self.get_branch_config('/a/foo')
650
 
        self.assertEqual([('/a/*', ''), ('/a/', 'foo')],
651
 
                         self.my_location_config._get_matching_sections())
 
573
        self.assertEqual('/a/*', self.my_location_config._get_section())
652
574
 
653
 
    def test__get_matching_sections_subdir_child_child(self):
 
575
    def test__get_section_subdir_child_child(self):
654
576
        self.get_branch_config('/a/foo/bar')
655
 
        self.assertEqual([('/a/*', 'bar'), ('/a/', 'foo/bar')],
656
 
                         self.my_location_config._get_matching_sections())
 
577
        self.assertEqual('/a/', self.my_location_config._get_section())
657
578
 
658
 
    def test__get_matching_sections_trailing_slash_with_children(self):
 
579
    def test__get_section_trailing_slash_with_children(self):
659
580
        self.get_branch_config('/a/')
660
 
        self.assertEqual([('/a/', '')],
661
 
                         self.my_location_config._get_matching_sections())
 
581
        self.assertEqual('/a/', self.my_location_config._get_section())
662
582
 
663
 
    def test__get_matching_sections_explicit_over_glob(self):
664
 
        # XXX: 2006-09-08 jamesh
665
 
        # This test only passes because ord('c') > ord('*').  If there
666
 
        # was a config section for '/a/?', it would get precedence
667
 
        # over '/a/c'.
 
583
    def test__get_section_explicit_over_glob(self):
668
584
        self.get_branch_config('/a/c')
669
 
        self.assertEqual([('/a/c', ''), ('/a/*', ''), ('/a/', 'c')],
670
 
                         self.my_location_config._get_matching_sections())
671
 
 
672
 
    def test__get_option_policy_normal(self):
673
 
        self.get_branch_config('http://www.example.com')
674
 
        self.assertEqual(
675
 
            self.my_location_config._get_config_policy(
676
 
            'http://www.example.com', 'normal_option'),
677
 
            config.POLICY_NONE)
678
 
 
679
 
    def test__get_option_policy_norecurse(self):
680
 
        self.get_branch_config('http://www.example.com')
681
 
        self.assertEqual(
682
 
            self.my_location_config._get_option_policy(
683
 
            'http://www.example.com', 'norecurse_option'),
684
 
            config.POLICY_NORECURSE)
685
 
        # Test old recurse=False setting:
686
 
        self.assertEqual(
687
 
            self.my_location_config._get_option_policy(
688
 
            'http://www.example.com/norecurse', 'normal_option'),
689
 
            config.POLICY_NORECURSE)
690
 
 
691
 
    def test__get_option_policy_normal(self):
692
 
        self.get_branch_config('http://www.example.com')
693
 
        self.assertEqual(
694
 
            self.my_location_config._get_option_policy(
695
 
            'http://www.example.com', 'appendpath_option'),
696
 
            config.POLICY_APPENDPATH)
 
585
        self.assertEqual('/a/c', self.my_location_config._get_section())
 
586
 
697
587
 
698
588
    def test_location_without_username(self):
699
 
        self.get_branch_config('http://www.example.com/ignoreparent')
 
589
        self.get_branch_config('http://www.example.com/useglobal')
700
590
        self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>',
701
591
                         self.my_config.username())
702
592
 
751
641
        self.get_branch_config('/a')
752
642
        self.assertEqual('local',
753
643
                         self.my_config.get_user_option('user_local_option'))
754
 
 
755
 
    def test_get_user_option_appendpath(self):
756
 
        # returned as is for the base path:
757
 
        self.get_branch_config('http://www.example.com')
758
 
        self.assertEqual('append',
759
 
                         self.my_config.get_user_option('appendpath_option'))
760
 
        # Extra path components get appended:
761
 
        self.get_branch_config('http://www.example.com/a/b/c')
762
 
        self.assertEqual('append/a/b/c',
763
 
                         self.my_config.get_user_option('appendpath_option'))
764
 
        # Overriden for http://www.example.com/dir, where it is a
765
 
        # normal option:
766
 
        self.get_branch_config('http://www.example.com/dir/a/b/c')
767
 
        self.assertEqual('normal',
768
 
                         self.my_config.get_user_option('appendpath_option'))
769
 
 
770
 
    def test_get_user_option_norecurse(self):
771
 
        self.get_branch_config('http://www.example.com')
772
 
        self.assertEqual('norecurse',
773
 
                         self.my_config.get_user_option('norecurse_option'))
774
 
        self.get_branch_config('http://www.example.com/dir')
775
 
        self.assertEqual(None,
776
 
                         self.my_config.get_user_option('norecurse_option'))
777
 
        # http://www.example.com/norecurse is a recurse=False section
778
 
        # that redefines normal_option.  Subdirectories do not pick up
779
 
        # this redefinition.
780
 
        self.get_branch_config('http://www.example.com/norecurse')
781
 
        self.assertEqual('norecurse',
782
 
                         self.my_config.get_user_option('normal_option'))
783
 
        self.get_branch_config('http://www.example.com/norecurse/subdir')
784
 
        self.assertEqual('normal',
785
 
                         self.my_config.get_user_option('normal_option'))
786
 
 
787
 
    def test_set_user_option_norecurse(self):
788
 
        self.get_branch_config('http://www.example.com')
789
 
        self.my_config.set_user_option('foo', 'bar',
790
 
                                       store=config.STORE_LOCATION_NORECURSE)
791
 
        self.assertEqual(
792
 
            self.my_location_config._get_option_policy(
793
 
            'http://www.example.com', 'foo'),
794
 
            config.POLICY_NORECURSE)
795
 
 
796
 
    def test_set_user_option_appendpath(self):
797
 
        self.get_branch_config('http://www.example.com')
798
 
        self.my_config.set_user_option('foo', 'bar',
799
 
                                       store=config.STORE_LOCATION_APPENDPATH)
800
 
        self.assertEqual(
801
 
            self.my_location_config._get_option_policy(
802
 
            'http://www.example.com', 'foo'),
803
 
            config.POLICY_APPENDPATH)
804
 
 
805
 
    def test_set_user_option_change_policy(self):
806
 
        self.get_branch_config('http://www.example.com')
807
 
        self.my_config.set_user_option('norecurse_option', 'normal',
808
 
                                       store=config.STORE_LOCATION)
809
 
        self.assertEqual(
810
 
            self.my_location_config._get_option_policy(
811
 
            'http://www.example.com', 'norecurse_option'),
812
 
            config.POLICY_NONE)
813
 
 
814
 
    def test_set_user_option_recurse_false_section(self):
815
 
        # The following section has recurse=False set.  The test is to
816
 
        # make sure that a normal option can be added to the section,
817
 
        # converting recurse=False to the norecurse policy.
818
 
        self.get_branch_config('http://www.example.com/norecurse')
819
 
        self.callDeprecated(['The recurse option is deprecated as of 0.14.  '
820
 
                             'The section "http://www.example.com/norecurse" '
821
 
                             'has been converted to use policies.'],
822
 
                            self.my_config.set_user_option,
823
 
                            'foo', 'bar', store=config.STORE_LOCATION)
824
 
        self.assertEqual(
825
 
            self.my_location_config._get_option_policy(
826
 
            'http://www.example.com/norecurse', 'foo'),
827
 
            config.POLICY_NONE)
828
 
        # The previously existing option is still norecurse:
829
 
        self.assertEqual(
830
 
            self.my_location_config._get_option_policy(
831
 
            'http://www.example.com/norecurse', 'normal_option'),
832
 
            config.POLICY_NORECURSE)
833
 
 
 
644
        
834
645
    def test_post_commit_default(self):
835
646
        self.get_branch_config('/a/c')
836
647
        self.assertEqual('bzrlib.tests.test_config.post_commit',
863
674
 
864
675
        os.mkdir = checked_mkdir
865
676
        try:
866
 
            self.callDeprecated(['The recurse option is deprecated as of '
867
 
                                 '0.14.  The section "/a/c" has been '
868
 
                                 'converted to use policies.'],
869
 
                                self.my_config.set_user_option,
870
 
                                'foo', 'bar', store=config.STORE_LOCATION)
 
677
            self.my_config.set_user_option('foo', 'bar', local=True)
871
678
        finally:
872
679
            os.mkdir = real_mkdir
873
680
 
877
684
                          ('__setitem__', '/a/c', {}),
878
685
                          ('__getitem__', '/a/c'),
879
686
                          ('__setitem__', 'foo', 'bar'),
880
 
                          ('__getitem__', '/a/c'),
881
 
                          ('as_bool', 'recurse'),
882
 
                          ('__getitem__', '/a/c'),
883
 
                          ('__delitem__', 'recurse'),
884
 
                          ('__getitem__', '/a/c'),
885
 
                          ('keys',),
886
 
                          ('__getitem__', '/a/c'),
887
 
                          ('__contains__', 'foo:policy'),
888
687
                          ('write',)],
889
688
                         record._calls[1:])
890
689
 
896
695
            self.my_config.branch.control_files.files['branch.conf'], 
897
696
            'foo = bar')
898
697
        self.assertEqual(self.my_config.get_user_option('foo'), 'bar')
899
 
        self.my_config.set_user_option('foo', 'baz',
900
 
                                       store=config.STORE_LOCATION)
 
698
        self.my_config.set_user_option('foo', 'baz', local=True)
901
699
        self.assertEqual(self.my_config.get_user_option('foo'), 'baz')
902
700
        self.my_config.set_user_option('foo', 'qux')
903
701
        self.assertEqual(self.my_config.get_user_option('foo'), 'baz')
904
702
        
905
 
    def test_get_bzr_remote_path(self):
906
 
        my_config = config.LocationConfig('/a/c')
907
 
        self.assertEqual('bzr', my_config.get_bzr_remote_path())
908
 
        my_config.set_user_option('bzr_remote_path', '/path-bzr')
909
 
        self.assertEqual('/path-bzr', my_config.get_bzr_remote_path())
910
 
        os.environ['BZR_REMOTE_PATH'] = '/environ-bzr'
911
 
        self.assertEqual('/environ-bzr', my_config.get_bzr_remote_path())
912
 
 
913
703
 
914
704
precedence_global = 'option = global'
915
705
precedence_branch = 'option = branch'
1009
799
        # post-commit is ignored when bresent in branch data
1010
800
        self.assertEqual('bzrlib.tests.test_config.post_commit',
1011
801
                         my_config.post_commit())
1012
 
        my_config.set_user_option('post_commit', 'rmtree_root',
1013
 
                                  store=config.STORE_LOCATION)
 
802
        my_config.set_user_option('post_commit', 'rmtree_root', local=True)
1014
803
        self.assertEqual('rmtree_root', my_config.post_commit())
1015
804
 
1016
805
    def test_config_precedence(self):
1029
818
                                      location='http://example.com/specific')
1030
819
        self.assertEqual(my_config.get_user_option('option'), 'exact')
1031
820
 
1032
 
    def test_get_mail_client(self):
1033
 
        config = self.get_branch_config()
1034
 
        client = config.get_mail_client()
1035
 
        self.assertIsInstance(client, mail_client.DefaultMail)
1036
 
 
1037
 
        # Specific clients
1038
 
        config.set_user_option('mail_client', 'evolution')
1039
 
        client = config.get_mail_client()
1040
 
        self.assertIsInstance(client, mail_client.Evolution)
1041
 
 
1042
 
        config.set_user_option('mail_client', 'kmail')
1043
 
        client = config.get_mail_client()
1044
 
        self.assertIsInstance(client, mail_client.KMail)
1045
 
 
1046
 
        config.set_user_option('mail_client', 'mutt')
1047
 
        client = config.get_mail_client()
1048
 
        self.assertIsInstance(client, mail_client.Mutt)
1049
 
 
1050
 
        config.set_user_option('mail_client', 'thunderbird')
1051
 
        client = config.get_mail_client()
1052
 
        self.assertIsInstance(client, mail_client.Thunderbird)
1053
 
 
1054
 
        # Generic options
1055
 
        config.set_user_option('mail_client', 'default')
1056
 
        client = config.get_mail_client()
1057
 
        self.assertIsInstance(client, mail_client.DefaultMail)
1058
 
 
1059
 
        config.set_user_option('mail_client', 'editor')
1060
 
        client = config.get_mail_client()
1061
 
        self.assertIsInstance(client, mail_client.Editor)
1062
 
 
1063
 
        config.set_user_option('mail_client', 'mapi')
1064
 
        client = config.get_mail_client()
1065
 
        self.assertIsInstance(client, mail_client.MAPIClient)
1066
 
 
1067
 
        config.set_user_option('mail_client', 'xdg-email')
1068
 
        client = config.get_mail_client()
1069
 
        self.assertIsInstance(client, mail_client.XDGEmail)
1070
 
 
1071
 
        config.set_user_option('mail_client', 'firebird')
1072
 
        self.assertRaises(errors.UnknownMailClient, config.get_mail_client)
1073
 
 
1074
821
 
1075
822
class TestMailAddressExtraction(TestCase):
1076
823
 
1077
824
    def test_extract_email_address(self):
1078
825
        self.assertEqual('jane@test.com',
1079
826
                         config.extract_email_address('Jane <jane@test.com>'))
1080
 
        self.assertRaises(errors.NoEmailInUsername,
 
827
        self.assertRaises(errors.BzrError,
1081
828
                          config.extract_email_address, 'Jane Tester')
1082
 
 
1083
 
 
1084
 
class TestTreeConfig(TestCaseWithTransport):
1085
 
 
1086
 
    def test_get_value(self):
1087
 
        """Test that retreiving a value from a section is possible"""
1088
 
        branch = self.make_branch('.')
1089
 
        tree_config = config.TreeConfig(branch)
1090
 
        tree_config.set_option('value', 'key', 'SECTION')
1091
 
        tree_config.set_option('value2', 'key2')
1092
 
        tree_config.set_option('value3-top', 'key3')
1093
 
        tree_config.set_option('value3-section', 'key3', 'SECTION')
1094
 
        value = tree_config.get_option('key', 'SECTION')
1095
 
        self.assertEqual(value, 'value')
1096
 
        value = tree_config.get_option('key2')
1097
 
        self.assertEqual(value, 'value2')
1098
 
        self.assertEqual(tree_config.get_option('non-existant'), None)
1099
 
        value = tree_config.get_option('non-existant', 'SECTION')
1100
 
        self.assertEqual(value, None)
1101
 
        value = tree_config.get_option('non-existant', default='default')
1102
 
        self.assertEqual(value, 'default')
1103
 
        self.assertEqual(tree_config.get_option('key2', 'NOSECTION'), None)
1104
 
        value = tree_config.get_option('key2', 'NOSECTION', default='default')
1105
 
        self.assertEqual(value, 'default')
1106
 
        value = tree_config.get_option('key3')
1107
 
        self.assertEqual(value, 'value3-top')
1108
 
        value = tree_config.get_option('key3', 'SECTION')
1109
 
        self.assertEqual(value, 'value3-section')