~bzr-pqm/bzr/bzr.dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

"""Test that all Tree's implement iter_search_rules."""

from bzrlib import (
    rules,
    )
from bzrlib.tests.per_tree import TestCaseWithTree


class TestIterSearchRules(TestCaseWithTree):

    def make_per_user_searcher(self, text):
        """Make a _RulesSearcher from a string"""
        return rules._IniBasedRulesSearcher(text.splitlines(True))

    def make_tree_with_rules(self, text):
        tree = self.make_branch_and_tree('.')
        if text is not None:
            self.fail("No method for in-tree rules agreed on yet.")
            text_utf8 = text.encode('utf-8')
            self.build_tree_contents([(rules.RULES_TREE_FILENAME, text_utf8)])
            tree.add(rules.RULES_TREE_FILENAME)
            tree.commit("add rules file")
        result = self._convert_tree(tree)
        result.lock_read()
        self.addCleanup(result.unlock)
        return result

    def test_iter_search_rules_no_tree(self):
        per_user = self.make_per_user_searcher(
            "[name ./a.txt]\nfoo=baz\n"
            "[name *.txt]\nfoo=bar\na=True\n")
        tree = self.make_tree_with_rules(None)
        result = list(tree.iter_search_rules(['a.txt', 'dir/a.txt'],
            _default_searcher=per_user))
        self.assertEquals((('foo', 'baz'),), result[0])
        self.assertEquals((('foo', 'bar'), ('a', 'True')), result[1])

    def _disabled_test_iter_search_rules_just_tree(self):
        per_user = self.make_per_user_searcher('')
        tree = self.make_tree_with_rules(
            "[name ./a.txt]\n"
            "foo=baz\n"
            "[name *.txt]\n"
            "foo=bar\n"
            "a=True\n")
        result = list(tree.iter_search_rules(['a.txt', 'dir/a.txt'],
            _default_searcher=per_user))
        self.assertEquals((('foo', 'baz'),), result[0])
        self.assertEquals((('foo', 'bar'), ('a', 'True')), result[1])

    def _disabled_test_iter_search_rules_tree_and_per_user(self):
        per_user = self.make_per_user_searcher(
            "[name ./a.txt]\nfoo=baz\n"
            "[name *.txt]\nfoo=bar\na=True\n")
        tree = self.make_tree_with_rules(
            "[name ./a.txt]\n"
            "foo=qwerty\n")
        result = list(tree.iter_search_rules(['a.txt', 'dir/a.txt'],
            _default_searcher=per_user))
        self.assertEquals((('foo', 'qwerty'),), result[0])
        self.assertEquals((('foo', 'bar'), ('a', 'True')), result[1])