~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

add some more tests for getting policy options, and behaviour of get_user_option in the presence of config policies

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
[http://www.example.com]
70
70
# Top level policy
71
71
email=Robert Collins <robertc@example.org>
 
72
normal_option = normal
 
73
appendpath_option = append
 
74
norecurse_option = norecurse
 
75
policy_appendpath = appendpath_option
 
76
policy_norecurse = norecurse_option
72
77
[http://www.example.com/ignoreparent]
73
78
# different project: ignore parent dir config
74
79
ignore_parents=true
75
80
[http://www.example.com/norecurse]
76
81
# configuration items that only apply to this dir
77
82
recurse=false
 
83
normal_option = norecurse
 
84
[http://www.example.com/dir]
 
85
appendpath_option = normal
78
86
[/b/]
79
87
check_signatures=require
80
88
# test trailing / matching with no children
600
608
        self.assertEqual([('/a/c', ''), ('/a/*', ''), ('/a/', 'c')],
601
609
                         self.my_location_config._get_matching_sections())
602
610
 
 
611
    def test__get_option_policy_normal(self):
 
612
        self.get_branch_config('http://www.example.com')
 
613
        self.assertEqual(
 
614
            self.my_location_config._get_config_policy(
 
615
            'http://www.example.com', 'normal_option'),
 
616
            config.POLICY_NONE)
 
617
 
 
618
    def test__get_option_policy_norecurse(self):
 
619
        self.get_branch_config('http://www.example.com')
 
620
        self.assertEqual(
 
621
            self.my_location_config._get_option_policy(
 
622
            'http://www.example.com', 'norecurse_option'),
 
623
            config.POLICY_NORECURSE)
 
624
        # Test old recurse=False setting:
 
625
        self.assertEqual(
 
626
            self.my_location_config._get_option_policy(
 
627
            'http://www.example.com/norecurse', 'normal_option'),
 
628
            config.POLICY_NORECURSE)
 
629
 
 
630
    def test__get_option_policy_normal(self):
 
631
        self.get_branch_config('http://www.example.com')
 
632
        self.assertEqual(
 
633
            self.my_location_config._get_option_policy(
 
634
            'http://www.example.com', 'appendpath_option'),
 
635
            config.POLICY_APPENDPATH)
 
636
 
603
637
    def test_location_without_username(self):
604
638
        self.get_branch_config('http://www.example.com/ignoreparent')
605
639
        self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>',
657
691
        self.assertEqual('local',
658
692
                         self.my_config.get_user_option('user_local_option'))
659
693
 
 
694
    def test_get_user_option_appendpath(self):
 
695
        # returned as is for the base path:
 
696
        self.get_branch_config('http://www.example.com')
 
697
        self.assertEqual('append',
 
698
                         self.my_config.get_user_option('appendpath_option'))
 
699
        # Extra path components get appended:
 
700
        self.get_branch_config('http://www.example.com/a/b/c')
 
701
        self.assertEqual('append/a/b/c',
 
702
                         self.my_config.get_user_option('appendpath_option'))
 
703
        # Overriden for http://www.example.com/dir, where it is a
 
704
        # normal option:
 
705
        self.get_branch_config('http://www.example.com/dir/a/b/c')
 
706
        self.assertEqual('normal',
 
707
                         self.my_config.get_user_option('appendpath_option'))
 
708
 
 
709
    def test_get_user_option_norecurse(self):
 
710
        self.get_branch_config('http://www.example.com')
 
711
        self.assertEqual('norecurse',
 
712
                         self.my_config.get_user_option('norecurse_option'))
 
713
        self.get_branch_config('http://www.example.com/dir')
 
714
        self.assertEqual(None,
 
715
                         self.my_config.get_user_option('norecurse_option'))
 
716
        # http://www.example.com/norecurse is a recurse=False section
 
717
        # that redefines normal_option.  Subdirectories do not pick up
 
718
        # this redefinition.
 
719
        self.get_branch_config('http://www.example.com/norecurse')
 
720
        self.assertEqual('norecurse',
 
721
                         self.my_config.get_user_option('normal_option'))
 
722
        self.get_branch_config('http://www.example.com/norecurse/subdir')
 
723
        self.assertEqual('normal',
 
724
                         self.my_config.get_user_option('normal_option'))
 
725
 
660
726
    def test_post_commit_default(self):
661
727
        self.get_branch_config('/a/c')
662
728
        self.assertEqual('bzrlib.tests.test_config.post_commit',