~jameinel/bzr/fix-push2

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: John Arbash Meinel
  • Date: 2006-12-18 15:57:21 UTC
  • mfrom: (2194 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2196.
  • Revision ID: john@arbash-meinel.com-20061218155721-9xb84yhuww8dz1ri
[merge] bzr.dev 2194

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
 
36
36
 
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"
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/ignoreparent]\n"
68
 
                        "# different project: ignore parent dir config\n"
69
 
                        "ignore_parents=true\n"
70
 
                        "[http://www.example.com/norecurse]\n"
71
 
                        "# configuration items that only apply to this dir\n"
72
 
                        "recurse=false\n"
73
 
                        "[/b/]\n"
74
 
                        "check_signatures=require\n"
75
 
                        "# test trailing / matching with no children\n"
76
 
                        "[/a/]\n"
77
 
                        "check_signatures=check-available\n"
78
 
                        "gpg_signing_command=false\n"
79
 
                        "user_local_option=local\n"
80
 
                        "# test trailing / matching\n"
81
 
                        "[/a/*]\n"
82
 
                        "#subdirs will match but not the parent\n"
83
 
                        "[/a/c]\n"
84
 
                        "check_signatures=ignore\n"
85
 
                        "post_commit=bzrlib.tests.test_config.post_commit\n"
86
 
                        "#testing explicit beats globs\n")
87
 
 
 
38
sample_config_text = u"""
 
39
[DEFAULT]
 
40
email=Erik B\u00e5gfors <erik@bagfors.nu>
 
41
editor=vim
 
42
gpg_signing_command=gnome-gpg
 
43
log_format=short
 
44
user_global_option=something
 
45
[ALIASES]
 
46
h=help
 
47
ll=""" + sample_long_alias + "\n"
 
48
 
 
49
 
 
50
sample_always_signatures = """
 
51
[DEFAULT]
 
52
check_signatures=ignore
 
53
create_signatures=always
 
54
"""
 
55
 
 
56
sample_ignore_signatures = """
 
57
[DEFAULT]
 
58
check_signatures=require
 
59
create_signatures=never
 
60
"""
 
61
 
 
62
sample_maybe_signatures = """
 
63
[DEFAULT]
 
64
check_signatures=ignore
 
65
create_signatures=when-required
 
66
"""
 
67
 
 
68
sample_branches_text = """
 
69
[http://www.example.com]
 
70
# Top level policy
 
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
 
79
ignore_parents=true
 
80
[http://www.example.com/norecurse]
 
81
# configuration items that only apply to this dir
 
82
recurse=false
 
83
normal_option = norecurse
 
84
[http://www.example.com/dir]
 
85
appendpath_option = normal
 
86
[/b/]
 
87
check_signatures=require
 
88
# test trailing / matching with no children
 
89
[/a/]
 
90
check_signatures=check-available
 
91
gpg_signing_command=false
 
92
user_local_option=local
 
93
# test trailing / matching
 
94
[/a/*]
 
95
#subdirs will match but not the parent
 
96
[/a/c]
 
97
check_signatures=ignore
 
98
post_commit=bzrlib.tests.test_config.post_commit
 
99
#testing explicit beats globs
 
100
"""
88
101
 
89
102
 
90
103
class InstrumentedConfigObj(object):
104
117
    def __setitem__(self, key, value):
105
118
        self._calls.append(('__setitem__', key, value))
106
119
 
 
120
    def __delitem__(self, key):
 
121
        self._calls.append(('__delitem__', key))
 
122
 
 
123
    def keys(self):
 
124
        self._calls.append(('keys',))
 
125
        return []
 
126
 
107
127
    def write(self, arg):
108
128
        self._calls.append(('write',))
109
129
 
 
130
    def as_bool(self, value):
 
131
        self._calls.append(('as_bool', value))
 
132
        return False
 
133
 
 
134
    def get_value(self, section, name):
 
135
        self._calls.append(('get_value', section, name))
 
136
        return None
 
137
 
110
138
 
111
139
class FakeBranch(object):
112
140
 
391
419
        local_path = osutils.getcwd().encode('utf8')
392
420
        # Surprisingly ConfigObj doesn't create a trailing newline
393
421
        self.check_file_contents(locations,
394
 
            '[%s/branch]\npush_location = http://foobar' % (local_path,))
 
422
            '[%s/branch]\npush_location = http://foobar\npush_location:policy = norecurse' % (local_path,))
395
423
 
396
424
    def test_autonick_urlencoded(self):
397
425
        b = self.make_branch('!repo')
570
598
        self.assertEqual([('http://www.example.com/ignoreparent', 'childbranch')],
571
599
                         self.my_location_config._get_matching_sections())
572
600
 
573
 
    def test__get_matching_sections_norecurse(self):
574
 
        self.get_branch_config('http://www.example.com/norecurse')
575
 
        self.assertEqual([('http://www.example.com/norecurse', ''),
576
 
                          ('http://www.example.com', 'norecurse')],
577
 
                         self.my_location_config._get_matching_sections())
578
 
 
579
 
    def test__get_matching_sections_norecurse_subdir(self):
580
 
        self.get_branch_config(
581
 
            'http://www.example.com/norecurse/childbranch')
582
 
        self.assertEqual([('http://www.example.com', 'norecurse/childbranch')],
583
 
                         self.my_location_config._get_matching_sections())
584
 
 
585
601
    def test__get_matching_sections_subdir_trailing_slash(self):
586
602
        self.get_branch_config('/b')
587
603
        self.assertEqual([('/b/', '')],
611
627
        self.assertEqual([('/a/c', ''), ('/a/*', ''), ('/a/', 'c')],
612
628
                         self.my_location_config._get_matching_sections())
613
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_config_policy(
 
634
            'http://www.example.com', 'normal_option'),
 
635
            config.POLICY_NONE)
 
636
 
 
637
    def test__get_option_policy_norecurse(self):
 
638
        self.get_branch_config('http://www.example.com')
 
639
        self.assertEqual(
 
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:
 
644
        self.assertEqual(
 
645
            self.my_location_config._get_option_policy(
 
646
            'http://www.example.com/norecurse', 'normal_option'),
 
647
            config.POLICY_NORECURSE)
 
648
 
 
649
    def test__get_option_policy_normal(self):
 
650
        self.get_branch_config('http://www.example.com')
 
651
        self.assertEqual(
 
652
            self.my_location_config._get_option_policy(
 
653
            'http://www.example.com', 'appendpath_option'),
 
654
            config.POLICY_APPENDPATH)
 
655
 
614
656
    def test_location_without_username(self):
615
657
        self.get_branch_config('http://www.example.com/ignoreparent')
616
658
        self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>',
668
710
        self.assertEqual('local',
669
711
                         self.my_config.get_user_option('user_local_option'))
670
712
 
 
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
 
723
        # normal option:
 
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'))
 
727
 
 
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
 
737
        # this redefinition.
 
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'))
 
744
 
 
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)
 
749
        self.assertEqual(
 
750
            self.my_location_config._get_option_policy(
 
751
            'http://www.example.com', 'foo'),
 
752
            config.POLICY_NORECURSE)
 
753
 
 
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)
 
758
        self.assertEqual(
 
759
            self.my_location_config._get_option_policy(
 
760
            'http://www.example.com', 'foo'),
 
761
            config.POLICY_APPENDPATH)
 
762
 
 
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)
 
767
        self.assertEqual(
 
768
            self.my_location_config._get_option_policy(
 
769
            'http://www.example.com', 'norecurse_option'),
 
770
            config.POLICY_NONE)
 
771
 
 
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)
 
782
        self.assertEqual(
 
783
            self.my_location_config._get_option_policy(
 
784
            'http://www.example.com/norecurse', 'foo'),
 
785
            config.POLICY_NONE)
 
786
        # The previously existing option is still norecurse:
 
787
        self.assertEqual(
 
788
            self.my_location_config._get_option_policy(
 
789
            'http://www.example.com/norecurse', 'normal_option'),
 
790
            config.POLICY_NORECURSE)
 
791
        
 
792
 
671
793
    def test_post_commit_default(self):
672
794
        self.get_branch_config('/a/c')
673
795
        self.assertEqual('bzrlib.tests.test_config.post_commit',
700
822
 
701
823
        os.mkdir = checked_mkdir
702
824
        try:
703
 
            self.my_config.set_user_option('foo', 'bar', local=True)
 
825
            self.callDeprecated(['The recurse option is deprecated as of '
 
826
                                 '0.14.  The section "/a/c" has been '
 
827
                                 'converted to use policies.'],
 
828
                                self.my_config.set_user_option,
 
829
                                'foo', 'bar', store=config.STORE_LOCATION)
704
830
        finally:
705
831
            os.mkdir = real_mkdir
706
832
 
710
836
                          ('__setitem__', '/a/c', {}),
711
837
                          ('__getitem__', '/a/c'),
712
838
                          ('__setitem__', 'foo', 'bar'),
 
839
                          ('__getitem__', '/a/c'),
 
840
                          ('as_bool', 'recurse'),
 
841
                          ('__getitem__', '/a/c'),
 
842
                          ('__delitem__', 'recurse'),
 
843
                          ('__getitem__', '/a/c'),
 
844
                          ('keys',),
 
845
                          ('__getitem__', '/a/c'),
 
846
                          ('__contains__', 'foo:policy'),
713
847
                          ('write',)],
714
848
                         record._calls[1:])
715
849
 
721
855
            self.my_config.branch.control_files.files['branch.conf'], 
722
856
            'foo = bar')
723
857
        self.assertEqual(self.my_config.get_user_option('foo'), 'bar')
724
 
        self.my_config.set_user_option('foo', 'baz', local=True)
 
858
        self.my_config.set_user_option('foo', 'baz',
 
859
                                       store=config.STORE_LOCATION)
725
860
        self.assertEqual(self.my_config.get_user_option('foo'), 'baz')
726
861
        self.my_config.set_user_option('foo', 'qux')
727
862
        self.assertEqual(self.my_config.get_user_option('foo'), 'baz')
825
960
        # post-commit is ignored when bresent in branch data
826
961
        self.assertEqual('bzrlib.tests.test_config.post_commit',
827
962
                         my_config.post_commit())
828
 
        my_config.set_user_option('post_commit', 'rmtree_root', local=True)
 
963
        my_config.set_user_option('post_commit', 'rmtree_root',
 
964
                                  store=config.STORE_LOCATION)
829
965
        self.assertEqual('rmtree_root', my_config.post_commit())
830
966
 
831
967
    def test_config_precedence(self):