~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: 2007-10-24 12:49:17 UTC
  • mfrom: (2935.1.1 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20071024124917-xb75eckyxx6vkrlg
Makefile fixes - hooks.html generation & allow python to be overridden (Ian Clatworthy)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 by Canonical Ltd
 
1
# Copyright (C) 2005, 2006 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,
30
31
    urlutils,
 
32
    trace,
31
33
    )
32
34
from bzrlib.branch import Branch
33
35
from bzrlib.bzrdir import BzrDir
35
37
 
36
38
 
37
39
sample_long_alias="log -r-15..-1 --line"
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
 
 
 
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
"""
86
103
 
87
104
 
88
105
class InstrumentedConfigObj(object):
102
119
    def __setitem__(self, key, value):
103
120
        self._calls.append(('__setitem__', key, value))
104
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
 
105
129
    def write(self, arg):
106
130
        self._calls.append(('write',))
107
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
 
108
140
 
109
141
class FakeBranch(object):
110
142
 
179
211
        self.assertIs(co.get_bool('UPPERCASE', 'nonactive'), False)
180
212
 
181
213
 
 
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
 
182
229
class TestConfig(TestCase):
183
230
 
184
231
    def test_constructs(self):
239
286
 
240
287
    def setUp(self):
241
288
        super(TestConfigPath, self).setUp()
242
 
        self.old_home = os.environ.get('HOME', None)
243
 
        self.old_appdata = os.environ.get('APPDATA', None)
244
289
        os.environ['HOME'] = '/home/bogus'
245
 
        os.environ['APPDATA'] = \
246
 
            r'C:\Documents and Settings\bogus\Application Data'
 
290
        if sys.platform == 'win32':
 
291
            os.environ['BZR_HOME'] = \
 
292
                r'C:\Documents and Settings\bogus\Application Data'
247
293
 
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
 
    
259
294
    def test_config_dir(self):
260
295
        if sys.platform == 'win32':
261
296
            self.assertEqual(config.config_dir(), 
383
418
 
384
419
    def test_config_creates_local(self):
385
420
        """Creating a new entry in config uses a local path."""
386
 
        branch = self.make_branch('branch')
 
421
        branch = self.make_branch('branch', format='knit')
387
422
        branch.set_push_location('http://foobar')
388
423
        locations = config.locations_config_filename()
389
424
        local_path = osutils.getcwd().encode('utf8')
390
425
        # Surprisingly ConfigObj doesn't create a trailing newline
391
426
        self.check_file_contents(locations,
392
 
            '[%s/branch]\npush_location = http://foobar' % (local_path,))
 
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
393
469
 
394
470
 
395
471
class TestGlobalConfigItems(TestCase):
535
611
        self.failUnless(isinstance(global_config, config.GlobalConfig))
536
612
        self.failUnless(global_config is my_config._get_global_config())
537
613
 
538
 
    def test__get_section_no_match(self):
 
614
    def test__get_matching_sections_no_match(self):
539
615
        self.get_branch_config('/')
540
 
        self.assertEqual(None, self.my_location_config._get_section())
 
616
        self.assertEqual([], self.my_location_config._get_matching_sections())
541
617
        
542
 
    def test__get_section_exact(self):
 
618
    def test__get_matching_sections_exact(self):
543
619
        self.get_branch_config('http://www.example.com')
544
 
        self.assertEqual('http://www.example.com',
545
 
                         self.my_location_config._get_section())
 
620
        self.assertEqual([('http://www.example.com', '')],
 
621
                         self.my_location_config._get_matching_sections())
546
622
   
547
 
    def test__get_section_suffix_does_not(self):
 
623
    def test__get_matching_sections_suffix_does_not(self):
548
624
        self.get_branch_config('http://www.example.com-com')
549
 
        self.assertEqual(None, self.my_location_config._get_section())
 
625
        self.assertEqual([], self.my_location_config._get_matching_sections())
550
626
 
551
 
    def test__get_section_subdir_recursive(self):
 
627
    def test__get_matching_sections_subdir_recursive(self):
552
628
        self.get_branch_config('http://www.example.com/com')
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):
 
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):
562
638
        self.get_branch_config(
563
 
            'http://www.example.com/useglobal/childbranch')
564
 
        self.assertEqual('http://www.example.com',
565
 
                         self.my_location_config._get_section())
 
639
            'http://www.example.com/ignoreparent/childbranch')
 
640
        self.assertEqual([('http://www.example.com/ignoreparent', 'childbranch')],
 
641
                         self.my_location_config._get_matching_sections())
566
642
 
567
 
    def test__get_section_subdir_trailing_slash(self):
 
643
    def test__get_matching_sections_subdir_trailing_slash(self):
568
644
        self.get_branch_config('/b')
569
 
        self.assertEqual('/b/', self.my_location_config._get_section())
 
645
        self.assertEqual([('/b/', '')],
 
646
                         self.my_location_config._get_matching_sections())
570
647
 
571
 
    def test__get_section_subdir_child(self):
 
648
    def test__get_matching_sections_subdir_child(self):
572
649
        self.get_branch_config('/a/foo')
573
 
        self.assertEqual('/a/*', self.my_location_config._get_section())
 
650
        self.assertEqual([('/a/*', ''), ('/a/', 'foo')],
 
651
                         self.my_location_config._get_matching_sections())
574
652
 
575
 
    def test__get_section_subdir_child_child(self):
 
653
    def test__get_matching_sections_subdir_child_child(self):
576
654
        self.get_branch_config('/a/foo/bar')
577
 
        self.assertEqual('/a/', self.my_location_config._get_section())
 
655
        self.assertEqual([('/a/*', 'bar'), ('/a/', 'foo/bar')],
 
656
                         self.my_location_config._get_matching_sections())
578
657
 
579
 
    def test__get_section_trailing_slash_with_children(self):
 
658
    def test__get_matching_sections_trailing_slash_with_children(self):
580
659
        self.get_branch_config('/a/')
581
 
        self.assertEqual('/a/', self.my_location_config._get_section())
 
660
        self.assertEqual([('/a/', '')],
 
661
                         self.my_location_config._get_matching_sections())
582
662
 
583
 
    def test__get_section_explicit_over_glob(self):
 
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'.
584
668
        self.get_branch_config('/a/c')
585
 
        self.assertEqual('/a/c', self.my_location_config._get_section())
586
 
 
 
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)
587
697
 
588
698
    def test_location_without_username(self):
589
 
        self.get_branch_config('http://www.example.com/useglobal')
 
699
        self.get_branch_config('http://www.example.com/ignoreparent')
590
700
        self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>',
591
701
                         self.my_config.username())
592
702
 
641
751
        self.get_branch_config('/a')
642
752
        self.assertEqual('local',
643
753
                         self.my_config.get_user_option('user_local_option'))
644
 
        
 
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
 
645
834
    def test_post_commit_default(self):
646
835
        self.get_branch_config('/a/c')
647
836
        self.assertEqual('bzrlib.tests.test_config.post_commit',
674
863
 
675
864
        os.mkdir = checked_mkdir
676
865
        try:
677
 
            self.my_config.set_user_option('foo', 'bar', local=True)
 
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)
678
871
        finally:
679
872
            os.mkdir = real_mkdir
680
873
 
684
877
                          ('__setitem__', '/a/c', {}),
685
878
                          ('__getitem__', '/a/c'),
686
879
                          ('__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'),
687
888
                          ('write',)],
688
889
                         record._calls[1:])
689
890
 
695
896
            self.my_config.branch.control_files.files['branch.conf'], 
696
897
            'foo = bar')
697
898
        self.assertEqual(self.my_config.get_user_option('foo'), 'bar')
698
 
        self.my_config.set_user_option('foo', 'baz', local=True)
 
899
        self.my_config.set_user_option('foo', 'baz',
 
900
                                       store=config.STORE_LOCATION)
699
901
        self.assertEqual(self.my_config.get_user_option('foo'), 'baz')
700
902
        self.my_config.set_user_option('foo', 'qux')
701
903
        self.assertEqual(self.my_config.get_user_option('foo'), 'baz')
702
904
        
 
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
 
703
913
 
704
914
precedence_global = 'option = global'
705
915
precedence_branch = 'option = branch'
799
1009
        # post-commit is ignored when bresent in branch data
800
1010
        self.assertEqual('bzrlib.tests.test_config.post_commit',
801
1011
                         my_config.post_commit())
802
 
        my_config.set_user_option('post_commit', 'rmtree_root', local=True)
 
1012
        my_config.set_user_option('post_commit', 'rmtree_root',
 
1013
                                  store=config.STORE_LOCATION)
803
1014
        self.assertEqual('rmtree_root', my_config.post_commit())
804
1015
 
805
1016
    def test_config_precedence(self):
818
1029
                                      location='http://example.com/specific')
819
1030
        self.assertEqual(my_config.get_user_option('option'), 'exact')
820
1031
 
 
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
 
821
1074
 
822
1075
class TestMailAddressExtraction(TestCase):
823
1076
 
824
1077
    def test_extract_email_address(self):
825
1078
        self.assertEqual('jane@test.com',
826
1079
                         config.extract_email_address('Jane <jane@test.com>'))
827
 
        self.assertRaises(errors.BzrError,
 
1080
        self.assertRaises(errors.NoEmailInUsername,
828
1081
                          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')