1
# Copyright (C) 2008 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Test that all Tree's implement iter_search_rules."""
23
from bzrlib.tests.tree_implementations import TestCaseWithTree
26
class TestIterSearchRules(TestCaseWithTree):
28
def make_per_user_searcher(self, text):
29
"""Make a _RulesSearcher from a string"""
30
return rules._IniBasedRulesSearcher(text.splitlines(True))
32
def make_tree_with_rules(self, text):
33
tree = self.make_branch_and_tree('.')
35
self.fail("No method for in-tree rules agreed on yet.")
36
text_utf8 = text.encode('utf-8')
37
self.build_tree_contents([(rules.RULES_TREE_FILENAME, text_utf8)])
38
tree.add(rules.RULES_TREE_FILENAME)
39
tree.commit("add rules file")
40
result = self._convert_tree(tree)
42
self.addCleanup(result.unlock)
45
def test_iter_search_rules_no_tree(self):
46
per_user = self.make_per_user_searcher(
47
"[name ./a.txt]\nfoo=baz\n"
48
"[name *.txt]\nfoo=bar\na=True\n")
49
tree = self.make_tree_with_rules(None)
50
result = list(tree.iter_search_rules(['a.txt', 'dir/a.txt'],
51
_default_searcher=per_user))
52
self.assertEquals((('foo', 'baz'),), result[0])
53
self.assertEquals((('foo', 'bar'), ('a', 'True')), result[1])
55
def _disabled_test_iter_search_rules_just_tree(self):
56
per_user = self.make_per_user_searcher('')
57
tree = self.make_tree_with_rules(
63
result = list(tree.iter_search_rules(['a.txt', 'dir/a.txt'],
64
_default_searcher=per_user))
65
self.assertEquals((('foo', 'baz'),), result[0])
66
self.assertEquals((('foo', 'bar'), ('a', 'True')), result[1])
68
def _disabled_test_iter_search_rules_tree_and_per_user(self):
69
per_user = self.make_per_user_searcher(
70
"[name ./a.txt]\nfoo=baz\n"
71
"[name *.txt]\nfoo=bar\na=True\n")
72
tree = self.make_tree_with_rules(
75
result = list(tree.iter_search_rules(['a.txt', 'dir/a.txt'],
76
_default_searcher=per_user))
77
self.assertEquals((('foo', 'qwerty'),), result[0])
78
self.assertEquals((('foo', 'bar'), ('a', 'True')), result[1])