39
37
sample_long_alias="log -r-15..-1 --line"
40
sample_config_text = u"""
42
email=Erik B\u00e5gfors <erik@bagfors.nu>
44
gpg_signing_command=gnome-gpg
46
user_global_option=something
49
ll=""" + sample_long_alias + "\n"
52
sample_always_signatures = """
54
check_signatures=ignore
55
create_signatures=always
58
sample_ignore_signatures = """
60
check_signatures=require
61
create_signatures=never
64
sample_maybe_signatures = """
66
check_signatures=ignore
67
create_signatures=when-required
70
sample_branches_text = """
71
[http://www.example.com]
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
82
[http://www.example.com/norecurse]
83
# configuration items that only apply to this dir
85
normal_option = norecurse
86
[http://www.example.com/dir]
87
appendpath_option = normal
89
check_signatures=require
90
# test trailing / matching with no children
92
check_signatures=check-available
93
gpg_signing_command=false
94
user_local_option=local
95
# test trailing / matching
97
#subdirs will match but not the parent
99
check_signatures=ignore
100
post_commit=bzrlib.tests.test_config.post_commit
101
#testing explicit beats globs
38
sample_config_text = ("[DEFAULT]\n"
39
u"email=Erik B\u00e5gfors <erik@bagfors.nu>\n"
41
"gpg_signing_command=gnome-gpg\n"
43
"user_global_option=something\n"
46
"ll=" + sample_long_alias + "\n")
49
sample_always_signatures = ("[DEFAULT]\n"
50
"check_signatures=ignore\n"
51
"create_signatures=always")
54
sample_ignore_signatures = ("[DEFAULT]\n"
55
"check_signatures=require\n"
56
"create_signatures=never")
59
sample_maybe_signatures = ("[DEFAULT]\n"
60
"check_signatures=ignore\n"
61
"create_signatures=when-required")
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"
71
"check_signatures=require\n"
72
"# test trailing / matching with no children\n"
74
"check_signatures=check-available\n"
75
"gpg_signing_command=false\n"
76
"user_local_option=local\n"
77
"# test trailing / matching\n"
79
"#subdirs will match but not the parent\n"
82
"check_signatures=ignore\n"
83
"post_commit=bzrlib.tests.test_config.post_commit\n"
84
"#testing explicit beats globs\n")
105
88
class InstrumentedConfigObj(object):
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,))
429
def test_autonick_urlencoded(self):
430
b = self.make_branch('!repo')
431
self.assertEqual('!repo', b.get_config().get_nickname())
433
def test_warn_if_masked(self):
434
_warning = trace.warning
437
warnings.append(args[0] % args[1:])
439
def set_option(store, warn_masked=True):
441
conf.set_user_option('example_option', repr(store), store=store,
442
warn_masked=warn_masked)
443
def assertWarning(warning):
445
self.assertEqual(0, len(warnings))
447
self.assertEqual(1, len(warnings))
448
self.assertEqual(warning, warnings[0])
449
trace.warning = warning
451
branch = self.make_branch('.')
452
conf = branch.get_config()
453
set_option(config.STORE_GLOBAL)
455
set_option(config.STORE_BRANCH)
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)
461
set_option(config.STORE_LOCATION)
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)
468
trace.warning = _warning
392
'[%s/branch]\npush_location = http://foobar' % (local_path,))
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())
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())
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())
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())
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())
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())
637
def test__get_matching_sections_ignoreparent_subdir(self):
553
self.assertEqual('http://www.example.com',
554
self.my_location_config._get_section())
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())
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())
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())
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())
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())
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())
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
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())
672
def test__get_option_policy_normal(self):
673
self.get_branch_config('http://www.example.com')
675
self.my_location_config._get_config_policy(
676
'http://www.example.com', 'normal_option'),
679
def test__get_option_policy_norecurse(self):
680
self.get_branch_config('http://www.example.com')
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:
687
self.my_location_config._get_option_policy(
688
'http://www.example.com/norecurse', 'normal_option'),
689
config.POLICY_NORECURSE)
691
def test__get_option_policy_normal(self):
692
self.get_branch_config('http://www.example.com')
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())
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())
751
641
self.get_branch_config('/a')
752
642
self.assertEqual('local',
753
643
self.my_config.get_user_option('user_local_option'))
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
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'))
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
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'))
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)
792
self.my_location_config._get_option_policy(
793
'http://www.example.com', 'foo'),
794
config.POLICY_NORECURSE)
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)
801
self.my_location_config._get_option_policy(
802
'http://www.example.com', 'foo'),
803
config.POLICY_APPENDPATH)
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)
810
self.my_location_config._get_option_policy(
811
'http://www.example.com', 'norecurse_option'),
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)
825
self.my_location_config._get_option_policy(
826
'http://www.example.com/norecurse', 'foo'),
828
# The previously existing option is still norecurse:
830
self.my_location_config._get_option_policy(
831
'http://www.example.com/norecurse', 'normal_option'),
832
config.POLICY_NORECURSE)
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',
896
695
self.my_config.branch.control_files.files['branch.conf'],
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')
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())
914
704
precedence_global = 'option = global'
915
705
precedence_branch = 'option = branch'
1029
818
location='http://example.com/specific')
1030
819
self.assertEqual(my_config.get_user_option('option'), 'exact')
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)
1038
config.set_user_option('mail_client', 'evolution')
1039
client = config.get_mail_client()
1040
self.assertIsInstance(client, mail_client.Evolution)
1042
config.set_user_option('mail_client', 'kmail')
1043
client = config.get_mail_client()
1044
self.assertIsInstance(client, mail_client.KMail)
1046
config.set_user_option('mail_client', 'mutt')
1047
client = config.get_mail_client()
1048
self.assertIsInstance(client, mail_client.Mutt)
1050
config.set_user_option('mail_client', 'thunderbird')
1051
client = config.get_mail_client()
1052
self.assertIsInstance(client, mail_client.Thunderbird)
1055
config.set_user_option('mail_client', 'default')
1056
client = config.get_mail_client()
1057
self.assertIsInstance(client, mail_client.DefaultMail)
1059
config.set_user_option('mail_client', 'editor')
1060
client = config.get_mail_client()
1061
self.assertIsInstance(client, mail_client.Editor)
1063
config.set_user_option('mail_client', 'mapi')
1064
client = config.get_mail_client()
1065
self.assertIsInstance(client, mail_client.MAPIClient)
1067
config.set_user_option('mail_client', 'xdg-email')
1068
client = config.get_mail_client()
1069
self.assertIsInstance(client, mail_client.XDGEmail)
1071
config.set_user_option('mail_client', 'firebird')
1072
self.assertRaises(errors.UnknownMailClient, config.get_mail_client)
1075
822
class TestMailAddressExtraction(TestCase):
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')
1084
class TestTreeConfig(TestCaseWithTransport):
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')