bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
3398.1.24
by Ian Clatworthy
make iter_search_rules a tree method |
1 |
# Copyright (C) 2008 Canonical Ltd
|
2 |
#
|
|
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.
|
|
7 |
#
|
|
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.
|
|
12 |
#
|
|
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
|
|
16 |
||
17 |
"""Test that all Tree's implement iter_search_rules."""
|
|
18 |
||
19 |
from bzrlib import ( |
|
20 |
rules, |
|
21 |
tests, |
|
22 |
)
|
|
23 |
from bzrlib.tests.tree_implementations import TestCaseWithTree |
|
24 |
||
25 |
||
26 |
class TestIterSearchRules(TestCaseWithTree): |
|
27 |
||
|
3398.1.33
by Ian Clatworthy
use a string, not lists, for test data |
28 |
def make_per_user_searcher(self, text): |
29 |
"""Make a _RulesSearcher from a string""" |
|
30 |
return rules._IniBasedRulesSearcher(text.splitlines(True)) |
|
|
3398.1.24
by Ian Clatworthy
make iter_search_rules a tree method |
31 |
|
32 |
def make_tree_with_rules(self, text): |
|
33 |
tree = self.make_branch_and_tree('.') |
|
34 |
if text is not None: |
|
|
3606.2.5
by Robert Collins
Cherry pick Robert's 'disable .bzrrules in-tree' patch |
35 |
self.fail("No method for in-tree rules agreed on yet.") |
|
3398.1.24
by Ian Clatworthy
make iter_search_rules a tree method |
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) |
|
41 |
result.lock_read() |
|
42 |
self.addCleanup(result.unlock) |
|
43 |
return result |
|
44 |
||
45 |
def test_iter_search_rules_no_tree(self): |
|
|
3398.1.33
by Ian Clatworthy
use a string, not lists, for test data |
46 |
per_user = self.make_per_user_searcher( |
47 |
"[name ./a.txt]\nfoo=baz\n" |
|
48 |
"[name *.txt]\nfoo=bar\na=True\n") |
|
|
3398.1.24
by Ian Clatworthy
make iter_search_rules a tree method |
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]) |
|
54 |
||
|
3606.2.5
by Robert Collins
Cherry pick Robert's 'disable .bzrrules in-tree' patch |
55 |
def _disabled_test_iter_search_rules_just_tree(self): |
|
3398.1.33
by Ian Clatworthy
use a string, not lists, for test data |
56 |
per_user = self.make_per_user_searcher('') |
|
3398.1.24
by Ian Clatworthy
make iter_search_rules a tree method |
57 |
tree = self.make_tree_with_rules( |
|
3398.1.33
by Ian Clatworthy
use a string, not lists, for test data |
58 |
"[name ./a.txt]\n" |
|
3398.1.24
by Ian Clatworthy
make iter_search_rules a tree method |
59 |
"foo=baz\n" |
|
3398.1.33
by Ian Clatworthy
use a string, not lists, for test data |
60 |
"[name *.txt]\n" |
|
3398.1.24
by Ian Clatworthy
make iter_search_rules a tree method |
61 |
"foo=bar\n" |
62 |
"a=True\n") |
|
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]) |
|
67 |
||
|
3606.2.5
by Robert Collins
Cherry pick Robert's 'disable .bzrrules in-tree' patch |
68 |
def _disabled_test_iter_search_rules_tree_and_per_user(self): |
|
3398.1.33
by Ian Clatworthy
use a string, not lists, for test data |
69 |
per_user = self.make_per_user_searcher( |
70 |
"[name ./a.txt]\nfoo=baz\n" |
|
71 |
"[name *.txt]\nfoo=bar\na=True\n") |
|
|
3398.1.24
by Ian Clatworthy
make iter_search_rules a tree method |
72 |
tree = self.make_tree_with_rules( |
|
3398.1.33
by Ian Clatworthy
use a string, not lists, for test data |
73 |
"[name ./a.txt]\n" |
|
3398.1.24
by Ian Clatworthy
make iter_search_rules a tree method |
74 |
"foo=qwerty\n") |
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]) |