~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_rules.py

(vila) Make all transport put_bytes() raises TypeError when given unicode
 strings rather than bytes (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008 Canonical Ltd
 
1
# Copyright (C) 2008-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
16
16
 
17
17
"""Tests for finding, parsing and searching rule-based preferences."""
18
18
 
19
 
import os
20
19
import sys
21
20
 
22
21
from bzrlib import (
23
 
    config,
24
22
    errors,
25
23
    rules,
26
24
    tests,
27
25
    )
28
 
from bzrlib.util.configobj import configobj
29
26
 
30
27
 
31
28
class TestIniBasedRulesSearcher(tests.TestCase):
46
43
        rs = self.make_searcher(None)
47
44
        self.assertEquals((), rs.get_items('a.txt'))
48
45
        self.assertEquals((), rs.get_selected_items('a.txt', ['foo']))
 
46
        self.assertEquals(None, rs.get_single_value('a.txt', 'foo'))
49
47
 
50
48
    def test_get_items_file_empty(self):
51
49
        rs = self.make_searcher("")
52
50
        self.assertEquals((), rs.get_items('a.txt'))
53
51
        self.assertEquals((), rs.get_selected_items('a.txt', ['foo']))
 
52
        self.assertEquals(None, rs.get_single_value('a.txt', 'foo'))
54
53
 
55
54
    def test_get_items_from_extension_match(self):
56
55
        rs = self.make_searcher("[name *.txt]\nfoo=bar\na=True\n")
61
60
            rs.get_items('dir/a.txt'))
62
61
        self.assertEquals((('foo', 'bar'),),
63
62
            rs.get_selected_items('a.txt', ['foo']))
 
63
        self.assertEquals('bar', rs.get_single_value('a.txt', 'foo'))
64
64
 
65
65
    def test_get_items_from_multiple_glob_match(self):
66
66
        rs = self.make_searcher(
74
74
            rs.get_items('x x'))
75
75
        self.assertEquals((('foo', 'bar'), ('a', 'True')),
76
76
            rs.get_items('y y'))
 
77
        self.assertEquals('bar', rs.get_single_value('a.txt', 'foo'))
77
78
 
78
79
    def test_get_items_pathname_match(self):
79
80
        rs = self.make_searcher("[name ./a.txt]\nfoo=baz\n")
80
81
        self.assertEquals((('foo', 'baz'),),
81
82
            rs.get_items('a.txt'))
 
83
        self.assertEquals('baz', rs.get_single_value('a.txt', 'foo'))
82
84
        self.assertEquals((), rs.get_items('dir/a.txt'))
 
85
        self.assertEquals(None, rs.get_single_value('dir/a.txt', 'foo'))
83
86
 
84
87
    def test_get_items_match_first(self):
85
88
        rs = self.make_searcher(
87
90
            "[name *.txt]\nfoo=bar\na=True\n")
88
91
        self.assertEquals((('foo', 'baz'),),
89
92
            rs.get_items('a.txt'))
 
93
        self.assertEquals('baz', rs.get_single_value('a.txt', 'foo'))
90
94
        self.assertEquals((('foo', 'bar'), ('a', 'True')),
91
95
            rs.get_items('dir/a.txt'))
 
96
        self.assertEquals('bar', rs.get_single_value('dir/a.txt', 'foo'))
92
97
 
93
98
 
94
99
class TestStackedRulesSearcher(tests.TestCase):
110
115
            "[name *.txt]\nfoo=bar\na=True\n")
111
116
        self.assertEquals((('foo', 'baz'),),
112
117
            rs.get_items('a.txt'))
 
118
        self.assertEquals('baz', rs.get_single_value('a.txt', 'foo'))
 
119
        self.assertEquals(None, rs.get_single_value('a.txt', 'a'))
113
120
        self.assertEquals((('foo', 'bar'), ('a', 'True')),
114
121
            rs.get_items('dir/a.txt'))
 
122
        self.assertEquals('bar', rs.get_single_value('dir/a.txt', 'foo'))
 
123
        self.assertEquals('True', rs.get_single_value('dir/a.txt', 'a'))
115
124
 
116
125
 
117
126
class TestRulesPath(tests.TestCase):
118
127
 
119
128
    def setUp(self):
120
129
        super(TestRulesPath, self).setUp()
121
 
        os.environ['HOME'] = '/home/bogus'
 
130
        self.overrideEnv('HOME', '/home/bogus')
122
131
        if sys.platform == 'win32':
123
 
            os.environ['BZR_HOME'] = \
124
 
                r'C:\Documents and Settings\bogus\Application Data'
 
132
            self.overrideEnv(
 
133
                'BZR_HOME', r'C:\Documents and Settings\bogus\Application Data')
125
134
            self.bzr_home = \
126
135
                'C:/Documents and Settings/bogus/Application Data/bazaar/2.0'
127
136
        else: