37
37
sample_long_alias="log -r-15..-1 --line"
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")
38
sample_config_text = u"""
40
email=Erik B\u00e5gfors <erik@bagfors.nu>
42
gpg_signing_command=gnome-gpg
44
user_global_option=something
47
ll=""" + sample_long_alias + "\n"
50
sample_always_signatures = """
52
check_signatures=ignore
53
create_signatures=always
56
sample_ignore_signatures = """
58
check_signatures=require
59
create_signatures=never
62
sample_maybe_signatures = """
64
check_signatures=ignore
65
create_signatures=when-required
68
sample_branches_text = """
69
[http://www.example.com]
71
email=Robert Collins <robertc@example.org>
72
normal_option = normal
73
appendpath_option = append
74
appendpath_option:policy = appendpath
75
norecurse_option = norecurse
76
norecurse_option:policy = norecurse
77
[http://www.example.com/ignoreparent]
78
# different project: ignore parent dir config
80
[http://www.example.com/norecurse]
81
# configuration items that only apply to this dir
83
normal_option = norecurse
84
[http://www.example.com/dir]
85
appendpath_option = normal
87
check_signatures=require
88
# test trailing / matching with no children
90
check_signatures=check-available
91
gpg_signing_command=false
92
user_local_option=local
93
# test trailing / matching
95
#subdirs will match but not the parent
97
check_signatures=ignore
98
post_commit=bzrlib.tests.test_config.post_commit
99
#testing explicit beats globs
88
103
class InstrumentedConfigObj(object):
535
569
self.failUnless(isinstance(global_config, config.GlobalConfig))
536
570
self.failUnless(global_config is my_config._get_global_config())
538
def test__get_section_no_match(self):
572
def test__get_matching_sections_no_match(self):
539
573
self.get_branch_config('/')
540
self.assertEqual(None, self.my_location_config._get_section())
574
self.assertEqual([], self.my_location_config._get_matching_sections())
542
def test__get_section_exact(self):
576
def test__get_matching_sections_exact(self):
543
577
self.get_branch_config('http://www.example.com')
544
self.assertEqual('http://www.example.com',
545
self.my_location_config._get_section())
578
self.assertEqual([('http://www.example.com', '')],
579
self.my_location_config._get_matching_sections())
547
def test__get_section_suffix_does_not(self):
581
def test__get_matching_sections_suffix_does_not(self):
548
582
self.get_branch_config('http://www.example.com-com')
549
self.assertEqual(None, self.my_location_config._get_section())
583
self.assertEqual([], self.my_location_config._get_matching_sections())
551
def test__get_section_subdir_recursive(self):
585
def test__get_matching_sections_subdir_recursive(self):
552
586
self.get_branch_config('http://www.example.com/com')
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):
587
self.assertEqual([('http://www.example.com', 'com')],
588
self.my_location_config._get_matching_sections())
590
def test__get_matching_sections_ignoreparent(self):
591
self.get_branch_config('http://www.example.com/ignoreparent')
592
self.assertEqual([('http://www.example.com/ignoreparent', '')],
593
self.my_location_config._get_matching_sections())
595
def test__get_matching_sections_ignoreparent_subdir(self):
562
596
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())
597
'http://www.example.com/ignoreparent/childbranch')
598
self.assertEqual([('http://www.example.com/ignoreparent', 'childbranch')],
599
self.my_location_config._get_matching_sections())
567
def test__get_section_subdir_trailing_slash(self):
601
def test__get_matching_sections_subdir_trailing_slash(self):
568
602
self.get_branch_config('/b')
569
self.assertEqual('/b/', self.my_location_config._get_section())
603
self.assertEqual([('/b/', '')],
604
self.my_location_config._get_matching_sections())
571
def test__get_section_subdir_child(self):
606
def test__get_matching_sections_subdir_child(self):
572
607
self.get_branch_config('/a/foo')
573
self.assertEqual('/a/*', self.my_location_config._get_section())
608
self.assertEqual([('/a/*', ''), ('/a/', 'foo')],
609
self.my_location_config._get_matching_sections())
575
def test__get_section_subdir_child_child(self):
611
def test__get_matching_sections_subdir_child_child(self):
576
612
self.get_branch_config('/a/foo/bar')
577
self.assertEqual('/a/', self.my_location_config._get_section())
613
self.assertEqual([('/a/*', 'bar'), ('/a/', 'foo/bar')],
614
self.my_location_config._get_matching_sections())
579
def test__get_section_trailing_slash_with_children(self):
616
def test__get_matching_sections_trailing_slash_with_children(self):
580
617
self.get_branch_config('/a/')
581
self.assertEqual('/a/', self.my_location_config._get_section())
618
self.assertEqual([('/a/', '')],
619
self.my_location_config._get_matching_sections())
583
def test__get_section_explicit_over_glob(self):
621
def test__get_matching_sections_explicit_over_glob(self):
622
# XXX: 2006-09-08 jamesh
623
# This test only passes because ord('c') > ord('*'). If there
624
# was a config section for '/a/?', it would get precedence
584
626
self.get_branch_config('/a/c')
585
self.assertEqual('/a/c', self.my_location_config._get_section())
627
self.assertEqual([('/a/c', ''), ('/a/*', ''), ('/a/', 'c')],
628
self.my_location_config._get_matching_sections())
630
def test__get_option_policy_normal(self):
631
self.get_branch_config('http://www.example.com')
633
self.my_location_config._get_config_policy(
634
'http://www.example.com', 'normal_option'),
637
def test__get_option_policy_norecurse(self):
638
self.get_branch_config('http://www.example.com')
640
self.my_location_config._get_option_policy(
641
'http://www.example.com', 'norecurse_option'),
642
config.POLICY_NORECURSE)
643
# Test old recurse=False setting:
645
self.my_location_config._get_option_policy(
646
'http://www.example.com/norecurse', 'normal_option'),
647
config.POLICY_NORECURSE)
649
def test__get_option_policy_normal(self):
650
self.get_branch_config('http://www.example.com')
652
self.my_location_config._get_option_policy(
653
'http://www.example.com', 'appendpath_option'),
654
config.POLICY_APPENDPATH)
588
656
def test_location_without_username(self):
589
self.get_branch_config('http://www.example.com/useglobal')
657
self.get_branch_config('http://www.example.com/ignoreparent')
590
658
self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>',
591
659
self.my_config.username())
641
709
self.get_branch_config('/a')
642
710
self.assertEqual('local',
643
711
self.my_config.get_user_option('user_local_option'))
713
def test_get_user_option_appendpath(self):
714
# returned as is for the base path:
715
self.get_branch_config('http://www.example.com')
716
self.assertEqual('append',
717
self.my_config.get_user_option('appendpath_option'))
718
# Extra path components get appended:
719
self.get_branch_config('http://www.example.com/a/b/c')
720
self.assertEqual('append/a/b/c',
721
self.my_config.get_user_option('appendpath_option'))
722
# Overriden for http://www.example.com/dir, where it is a
724
self.get_branch_config('http://www.example.com/dir/a/b/c')
725
self.assertEqual('normal',
726
self.my_config.get_user_option('appendpath_option'))
728
def test_get_user_option_norecurse(self):
729
self.get_branch_config('http://www.example.com')
730
self.assertEqual('norecurse',
731
self.my_config.get_user_option('norecurse_option'))
732
self.get_branch_config('http://www.example.com/dir')
733
self.assertEqual(None,
734
self.my_config.get_user_option('norecurse_option'))
735
# http://www.example.com/norecurse is a recurse=False section
736
# that redefines normal_option. Subdirectories do not pick up
738
self.get_branch_config('http://www.example.com/norecurse')
739
self.assertEqual('norecurse',
740
self.my_config.get_user_option('normal_option'))
741
self.get_branch_config('http://www.example.com/norecurse/subdir')
742
self.assertEqual('normal',
743
self.my_config.get_user_option('normal_option'))
745
def test_set_user_option_norecurse(self):
746
self.get_branch_config('http://www.example.com')
747
self.my_config.set_user_option('foo', 'bar',
748
store=config.STORE_LOCATION_NORECURSE)
750
self.my_location_config._get_option_policy(
751
'http://www.example.com', 'foo'),
752
config.POLICY_NORECURSE)
754
def test_set_user_option_appendpath(self):
755
self.get_branch_config('http://www.example.com')
756
self.my_config.set_user_option('foo', 'bar',
757
store=config.STORE_LOCATION_APPENDPATH)
759
self.my_location_config._get_option_policy(
760
'http://www.example.com', 'foo'),
761
config.POLICY_APPENDPATH)
763
def test_set_user_option_change_policy(self):
764
self.get_branch_config('http://www.example.com')
765
self.my_config.set_user_option('norecurse_option', 'normal',
766
store=config.STORE_LOCATION)
768
self.my_location_config._get_option_policy(
769
'http://www.example.com', 'norecurse_option'),
772
def test_set_user_option_recurse_false_section(self):
773
# The following section has recurse=False set. The test is to
774
# make sure that a normal option can be added to the section,
775
# converting recurse=False to the norecurse policy.
776
self.get_branch_config('http://www.example.com/norecurse')
777
self.callDeprecated(['The recurse option is deprecated as of 0.14. '
778
'The section "http://www.example.com/norecurse" '
779
'has been converted to use policies.'],
780
self.my_config.set_user_option,
781
'foo', 'bar', store=config.STORE_LOCATION)
783
self.my_location_config._get_option_policy(
784
'http://www.example.com/norecurse', 'foo'),
786
# The previously existing option is still norecurse:
788
self.my_location_config._get_option_policy(
789
'http://www.example.com/norecurse', 'normal_option'),
790
config.POLICY_NORECURSE)
645
793
def test_post_commit_default(self):
646
794
self.get_branch_config('/a/c')
647
795
self.assertEqual('bzrlib.tests.test_config.post_commit',