~ubuntu-branches/ubuntu/karmic/bzr/karmic-proposed

« back to all changes in this revision

Viewing changes to bzrlib/tests/tree_implementations/test_iter_search_rules.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2008-08-25 19:06:49 UTC
  • mfrom: (1.1.44 upstream)
  • Revision ID: james.westby@ubuntu.com-20080825190649-pq87jonr4uvs7s0y
Tags: 1.6-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
28
    def make_per_user_searcher(self, text):
 
29
        """Make a _RulesSearcher from a string"""
 
30
        return rules._IniBasedRulesSearcher(text.splitlines(True))
 
31
 
 
32
    def make_tree_with_rules(self, text):
 
33
        tree = self.make_branch_and_tree('.')
 
34
        if text is not None:
 
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)
 
41
        result.lock_read()
 
42
        self.addCleanup(result.unlock)
 
43
        return result
 
44
 
 
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])
 
54
 
 
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(
 
58
            "[name ./a.txt]\n"
 
59
            "foo=baz\n"
 
60
            "[name *.txt]\n"
 
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
 
 
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(
 
73
            "[name ./a.txt]\n"
 
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])