1
# Copyright (C) 2008, 2009, 2010 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Test that all Tree's implement iter_search_rules."""
22
from bzrlib.tests.per_tree import TestCaseWithTree
25
class TestIterSearchRules(TestCaseWithTree):
27
def make_per_user_searcher(self, text):
28
"""Make a _RulesSearcher from a string"""
29
return rules._IniBasedRulesSearcher(text.splitlines(True))
31
def make_tree_with_rules(self, text):
32
tree = self.make_branch_and_tree('.')
34
self.fail("No method for in-tree rules agreed on yet.")
35
text_utf8 = text.encode('utf-8')
36
self.build_tree_contents([(rules.RULES_TREE_FILENAME, text_utf8)])
37
tree.add(rules.RULES_TREE_FILENAME)
38
tree.commit("add rules file")
39
result = self._convert_tree(tree)
41
self.addCleanup(result.unlock)
44
def test_iter_search_rules_no_tree(self):
45
per_user = self.make_per_user_searcher(
46
"[name ./a.txt]\nfoo=baz\n"
47
"[name *.txt]\nfoo=bar\na=True\n")
48
tree = self.make_tree_with_rules(None)
49
result = list(tree.iter_search_rules(['a.txt', 'dir/a.txt'],
50
_default_searcher=per_user))
51
self.assertEquals((('foo', 'baz'),), result[0])
52
self.assertEquals((('foo', 'bar'), ('a', 'True')), result[1])
54
def _disabled_test_iter_search_rules_just_tree(self):
55
per_user = self.make_per_user_searcher('')
56
tree = self.make_tree_with_rules(
62
result = list(tree.iter_search_rules(['a.txt', 'dir/a.txt'],
63
_default_searcher=per_user))
64
self.assertEquals((('foo', 'baz'),), result[0])
65
self.assertEquals((('foo', 'bar'), ('a', 'True')), result[1])
67
def _disabled_test_iter_search_rules_tree_and_per_user(self):
68
per_user = self.make_per_user_searcher(
69
"[name ./a.txt]\nfoo=baz\n"
70
"[name *.txt]\nfoo=bar\na=True\n")
71
tree = self.make_tree_with_rules(
74
result = list(tree.iter_search_rules(['a.txt', 'dir/a.txt'],
75
_default_searcher=per_user))
76
self.assertEquals((('foo', 'qwerty'),), result[0])
77
self.assertEquals((('foo', 'bar'), ('a', 'True')), result[1])