~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_rules.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-05-28 00:25:32 UTC
  • mfrom: (5264.1.2 command-help-bug-177500)
  • Revision ID: pqm@pqm.ubuntu.com-20100528002532-9bzj1fajyxckd1rg
(lifeless) Stop raising at runtime when a command has no help,
 instead have a test in the test suite that checks all known command objects.
 (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008-2011 Canonical Ltd
 
1
# Copyright (C) 2008 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
19
20
import sys
20
21
 
21
22
from bzrlib import (
 
23
    config,
22
24
    errors,
23
25
    rules,
24
26
    tests,
25
27
    )
 
28
from bzrlib.util.configobj import configobj
26
29
 
27
30
 
28
31
class TestIniBasedRulesSearcher(tests.TestCase):
43
46
        rs = self.make_searcher(None)
44
47
        self.assertEquals((), rs.get_items('a.txt'))
45
48
        self.assertEquals((), rs.get_selected_items('a.txt', ['foo']))
46
 
        self.assertEquals(None, rs.get_single_value('a.txt', 'foo'))
47
49
 
48
50
    def test_get_items_file_empty(self):
49
51
        rs = self.make_searcher("")
50
52
        self.assertEquals((), rs.get_items('a.txt'))
51
53
        self.assertEquals((), rs.get_selected_items('a.txt', ['foo']))
52
 
        self.assertEquals(None, rs.get_single_value('a.txt', 'foo'))
53
54
 
54
55
    def test_get_items_from_extension_match(self):
55
56
        rs = self.make_searcher("[name *.txt]\nfoo=bar\na=True\n")
60
61
            rs.get_items('dir/a.txt'))
61
62
        self.assertEquals((('foo', 'bar'),),
62
63
            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'))
78
77
 
79
78
    def test_get_items_pathname_match(self):
80
79
        rs = self.make_searcher("[name ./a.txt]\nfoo=baz\n")
81
80
        self.assertEquals((('foo', 'baz'),),
82
81
            rs.get_items('a.txt'))
83
 
        self.assertEquals('baz', rs.get_single_value('a.txt', 'foo'))
84
82
        self.assertEquals((), rs.get_items('dir/a.txt'))
85
 
        self.assertEquals(None, rs.get_single_value('dir/a.txt', 'foo'))
86
83
 
87
84
    def test_get_items_match_first(self):
88
85
        rs = self.make_searcher(
90
87
            "[name *.txt]\nfoo=bar\na=True\n")
91
88
        self.assertEquals((('foo', 'baz'),),
92
89
            rs.get_items('a.txt'))
93
 
        self.assertEquals('baz', rs.get_single_value('a.txt', 'foo'))
94
90
        self.assertEquals((('foo', 'bar'), ('a', 'True')),
95
91
            rs.get_items('dir/a.txt'))
96
 
        self.assertEquals('bar', rs.get_single_value('dir/a.txt', 'foo'))
97
92
 
98
93
 
99
94
class TestStackedRulesSearcher(tests.TestCase):
115
110
            "[name *.txt]\nfoo=bar\na=True\n")
116
111
        self.assertEquals((('foo', 'baz'),),
117
112
            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'))
120
113
        self.assertEquals((('foo', 'bar'), ('a', 'True')),
121
114
            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'))
124
115
 
125
116
 
126
117
class TestRulesPath(tests.TestCase):
127
118
 
128
119
    def setUp(self):
129
120
        super(TestRulesPath, self).setUp()
130
 
        self.overrideEnv('HOME', '/home/bogus')
 
121
        os.environ['HOME'] = '/home/bogus'
131
122
        if sys.platform == 'win32':
132
 
            self.overrideEnv(
133
 
                'BZR_HOME', r'C:\Documents and Settings\bogus\Application Data')
 
123
            os.environ['BZR_HOME'] = \
 
124
                r'C:\Documents and Settings\bogus\Application Data'
134
125
            self.bzr_home = \
135
126
                'C:/Documents and Settings/bogus/Application Data/bazaar/2.0'
136
127
        else: