~bzr-pqm/bzr/bzr.dev

4763.2.4 by John Arbash Meinel
merge bzr.2.1 in preparation for NEWS entry.
1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
3398.1.24 by Ian Clatworthy
make iter_search_rules a tree method
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3398.1.24 by Ian Clatworthy
make iter_search_rules a tree method
16
17
"""Test that all Tree's implement iter_search_rules."""
18
19
from bzrlib import (
20
    rules,
21
    )
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
22
from bzrlib.tests.per_tree import TestCaseWithTree
3398.1.24 by Ian Clatworthy
make iter_search_rules a tree method
23
24
25
class TestIterSearchRules(TestCaseWithTree):
26
3398.1.33 by Ian Clatworthy
use a string, not lists, for test data
27
    def make_per_user_searcher(self, text):
28
        """Make a _RulesSearcher from a string"""
29
        return rules._IniBasedRulesSearcher(text.splitlines(True))
3398.1.24 by Ian Clatworthy
make iter_search_rules a tree method
30
31
    def make_tree_with_rules(self, text):
32
        tree = self.make_branch_and_tree('.')
33
        if text is not None:
3606.2.5 by Robert Collins
Cherry pick Robert's 'disable .bzrrules in-tree' patch
34
            self.fail("No method for in-tree rules agreed on yet.")
3398.1.24 by Ian Clatworthy
make iter_search_rules a tree method
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)
40
        result.lock_read()
41
        self.addCleanup(result.unlock)
42
        return result
43
44
    def test_iter_search_rules_no_tree(self):
3398.1.33 by Ian Clatworthy
use a string, not lists, for test data
45
        per_user = self.make_per_user_searcher(
46
            "[name ./a.txt]\nfoo=baz\n"
47
            "[name *.txt]\nfoo=bar\na=True\n")
3398.1.24 by Ian Clatworthy
make iter_search_rules a tree method
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])
53
3606.2.5 by Robert Collins
Cherry pick Robert's 'disable .bzrrules in-tree' patch
54
    def _disabled_test_iter_search_rules_just_tree(self):
3398.1.33 by Ian Clatworthy
use a string, not lists, for test data
55
        per_user = self.make_per_user_searcher('')
3398.1.24 by Ian Clatworthy
make iter_search_rules a tree method
56
        tree = self.make_tree_with_rules(
3398.1.33 by Ian Clatworthy
use a string, not lists, for test data
57
            "[name ./a.txt]\n"
3398.1.24 by Ian Clatworthy
make iter_search_rules a tree method
58
            "foo=baz\n"
3398.1.33 by Ian Clatworthy
use a string, not lists, for test data
59
            "[name *.txt]\n"
3398.1.24 by Ian Clatworthy
make iter_search_rules a tree method
60
            "foo=bar\n"
61
            "a=True\n")
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])
66
3606.2.5 by Robert Collins
Cherry pick Robert's 'disable .bzrrules in-tree' patch
67
    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
68
        per_user = self.make_per_user_searcher(
69
            "[name ./a.txt]\nfoo=baz\n"
70
            "[name *.txt]\nfoo=bar\na=True\n")
3398.1.24 by Ian Clatworthy
make iter_search_rules a tree method
71
        tree = self.make_tree_with_rules(
3398.1.33 by Ian Clatworthy
use a string, not lists, for test data
72
            "[name ./a.txt]\n"
3398.1.24 by Ian Clatworthy
make iter_search_rules a tree method
73
            "foo=qwerty\n")
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])