~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_rules.py

  • Committer: Ian Clatworthy
  • Date: 2008-05-28 07:01:06 UTC
  • mto: (3515.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 3516.
  • Revision ID: ian.clatworthy@canonical.com-20080528070106-6w0oc8zat4bs29g1
make iter_search_rules a tree method

Show diffs side-by-side

added added

removed removed

Lines of Context:
106
106
    def test_rules_filename(self):
107
107
        self.assertEqual(rules.rules_filename(),
108
108
                         self.bzr_home + '/rules')
109
 
 
110
 
 
111
 
class TestIterSearchRules(tests.TestCaseInTempDir):
112
 
 
113
 
    def make_per_user_searcher(self, lines):
114
 
        """Make a _RulesSearcher from a list of strings"""
115
 
        return rules._IniBasedRulesSearcher(lines)
116
 
 
117
 
    def make_branch_with_rules(self, text):
118
 
        b = self.make_branch('.')
119
 
        control_files = b.control_files
120
 
        control_files.lock_write()
121
 
        try:
122
 
            control_files.put_utf8('branch.rules', text)
123
 
        finally:
124
 
            control_files.unlock()
125
 
        return b
126
 
 
127
 
    def test_iter_search_rules_no_branch(self):
128
 
        per_user = self.make_per_user_searcher([
129
 
            "[./a.txt]", "foo=baz",
130
 
            "[*.txt]", "foo=bar", "a=True"])
131
 
        result = list(rules.iter_search_rules(None, ['a.txt', 'dir/a.txt'],
132
 
            _default_searcher=per_user))
133
 
        self.assertEquals((('foo', 'baz'),), result[0])
134
 
        self.assertEquals((('foo', 'bar'), ('a', 'True')), result[1])
135
 
 
136
 
    def test_iter_search_rules_just_branch(self):
137
 
        per_user = self.make_per_user_searcher([])
138
 
        b = self.make_branch_with_rules(
139
 
            "[./a.txt]\n"
140
 
            "foo=baz\n"
141
 
            "[*.txt]\n"
142
 
            "foo=bar\n"
143
 
            "a=True\n")
144
 
        result = list(rules.iter_search_rules(b, ['a.txt', 'dir/a.txt'],
145
 
            _default_searcher=per_user))
146
 
        self.assertEquals((('foo', 'baz'),), result[0])
147
 
        self.assertEquals((('foo', 'bar'), ('a', 'True')), result[1])
148
 
 
149
 
    def test_iter_search_rules_branch_and_per_user(self):
150
 
        per_user = self.make_per_user_searcher([
151
 
            "[./a.txt]", "foo=baz",
152
 
            "[*.txt]", "foo=bar", "a=True"])
153
 
        b = self.make_branch_with_rules(
154
 
            "[./a.txt]\n"
155
 
            "foo=qwerty\n")
156
 
        result = list(rules.iter_search_rules(b, ['a.txt', 'dir/a.txt'],
157
 
            _default_searcher=per_user))
158
 
        self.assertEquals((('foo', 'qwerty'),), result[0])
159
 
        self.assertEquals((('foo', 'bar'), ('a', 'True')), result[1])