bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
1 |
# Copyright (C) 2008-2011, 2016 Canonical Ltd
|
|
3398.1.4
by Ian Clatworthy
add properties_filename() test |
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.4
by Ian Clatworthy
add properties_filename() test |
16 |
|
|
3398.1.15
by Ian Clatworthy
search branch.rules and bazaar.rules for preferences |
17 |
"""Tests for finding, parsing and searching rule-based preferences."""
|
|
3398.1.4
by Ian Clatworthy
add properties_filename() test |
18 |
|
19 |
import sys |
|
20 |
||
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
21 |
from breezy import ( |
|
3398.1.15
by Ian Clatworthy
search branch.rules and bazaar.rules for preferences |
22 |
rules, |
|
3398.1.4
by Ian Clatworthy
add properties_filename() test |
23 |
tests, |
24 |
)
|
|
25 |
||
26 |
||
|
6734.1.22
by Jelmer Vernooij
review comments. |
27 |
class TestErrors(tests.TestCase): |
|
6734.1.10
by Jelmer Vernooij
Move UnknownRules. |
28 |
|
29 |
def test_unknown_rules(self): |
|
30 |
err = rules.UnknownRules(['foo', 'bar']) |
|
31 |
self.assertEqual("Unknown rules detected: foo, bar.", str(err)) |
|
32 |
||
33 |
||
|
3398.1.15
by Ian Clatworthy
search branch.rules and bazaar.rules for preferences |
34 |
class TestIniBasedRulesSearcher(tests.TestCase): |
35 |
||
|
3398.1.33
by Ian Clatworthy
use a string, not lists, for test data |
36 |
def make_searcher(self, text): |
37 |
"""Make a _RulesSearcher from a string""" |
|
38 |
if text is None: |
|
39 |
lines = None |
|
40 |
else: |
|
41 |
lines = text.splitlines() |
|
42 |
return rules._IniBasedRulesSearcher(lines) |
|
|
3398.1.15
by Ian Clatworthy
search branch.rules and bazaar.rules for preferences |
43 |
|
|
3398.1.30
by Ian Clatworthy
test unknown rules detection |
44 |
def test_unknown_namespace(self): |
|
6734.1.10
by Jelmer Vernooij
Move UnknownRules. |
45 |
self.assertRaises(rules.UnknownRules, rules._IniBasedRulesSearcher, |
46 |
["[junk]", "foo=bar"]) |
|
|
3398.1.30
by Ian Clatworthy
test unknown rules detection |
47 |
|
|
3398.1.15
by Ian Clatworthy
search branch.rules and bazaar.rules for preferences |
48 |
def test_get_items_file_missing(self): |
49 |
rs = self.make_searcher(None) |
|
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
50 |
self.assertEqual((), rs.get_items('a.txt')) |
51 |
self.assertEqual((), rs.get_selected_items('a.txt', ['foo'])) |
|
52 |
self.assertEqual(None, rs.get_single_value('a.txt', 'foo')) |
|
|
3398.1.15
by Ian Clatworthy
search branch.rules and bazaar.rules for preferences |
53 |
|
54 |
def test_get_items_file_empty(self): |
|
|
3398.1.33
by Ian Clatworthy
use a string, not lists, for test data |
55 |
rs = self.make_searcher("") |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
56 |
self.assertEqual((), rs.get_items('a.txt')) |
57 |
self.assertEqual((), rs.get_selected_items('a.txt', ['foo'])) |
|
58 |
self.assertEqual(None, rs.get_single_value('a.txt', 'foo')) |
|
|
3398.1.15
by Ian Clatworthy
search branch.rules and bazaar.rules for preferences |
59 |
|
60 |
def test_get_items_from_extension_match(self): |
|
|
3398.1.33
by Ian Clatworthy
use a string, not lists, for test data |
61 |
rs = self.make_searcher("[name *.txt]\nfoo=bar\na=True\n") |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
62 |
self.assertEqual((), rs.get_items('a.py')) |
63 |
self.assertEqual((('foo', 'bar'), ('a', 'True')), |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
64 |
rs.get_items('a.txt')) |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
65 |
self.assertEqual((('foo', 'bar'), ('a', 'True')), |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
66 |
rs.get_items('dir/a.txt')) |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
67 |
self.assertEqual((('foo', 'bar'),), |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
68 |
rs.get_selected_items('a.txt', ['foo'])) |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
69 |
self.assertEqual('bar', rs.get_single_value('a.txt', 'foo')) |
|
3398.1.15
by Ian Clatworthy
search branch.rules and bazaar.rules for preferences |
70 |
|
|
3943.3.1
by Marius Kruger
add test and support for multi-glob rules |
71 |
def test_get_items_from_multiple_glob_match(self): |
|
4913.5.14
by Gordon Tyler
Reverted changes to test_rules since the original should work now. |
72 |
rs = self.make_searcher( |
73 |
"[name *.txt *.py 'x x' \"y y\"]\nfoo=bar\na=True\n") |
|
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
74 |
self.assertEqual((), rs.get_items('NEWS')) |
75 |
self.assertEqual((('foo', 'bar'), ('a', 'True')), |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
76 |
rs.get_items('a.py')) |
77 |
self.assertEqual((('foo', 'bar'), ('a', 'True')), |
|
78 |
rs.get_items('a.txt')) |
|
79 |
self.assertEqual((('foo', 'bar'), ('a', 'True')), |
|
80 |
rs.get_items('x x')) |
|
81 |
self.assertEqual((('foo', 'bar'), ('a', 'True')), |
|
82 |
rs.get_items('y y')) |
|
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
83 |
self.assertEqual('bar', rs.get_single_value('a.txt', 'foo')) |
|
3943.3.1
by Marius Kruger
add test and support for multi-glob rules |
84 |
|
|
3398.1.15
by Ian Clatworthy
search branch.rules and bazaar.rules for preferences |
85 |
def test_get_items_pathname_match(self): |
|
3398.1.33
by Ian Clatworthy
use a string, not lists, for test data |
86 |
rs = self.make_searcher("[name ./a.txt]\nfoo=baz\n") |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
87 |
self.assertEqual((('foo', 'baz'),), |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
88 |
rs.get_items('a.txt')) |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
89 |
self.assertEqual('baz', rs.get_single_value('a.txt', 'foo')) |
90 |
self.assertEqual((), rs.get_items('dir/a.txt')) |
|
91 |
self.assertEqual(None, rs.get_single_value('dir/a.txt', 'foo')) |
|
|
3398.1.15
by Ian Clatworthy
search branch.rules and bazaar.rules for preferences |
92 |
|
93 |
def test_get_items_match_first(self): |
|
|
3398.1.33
by Ian Clatworthy
use a string, not lists, for test data |
94 |
rs = self.make_searcher( |
95 |
"[name ./a.txt]\nfoo=baz\n" |
|
96 |
"[name *.txt]\nfoo=bar\na=True\n") |
|
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
97 |
self.assertEqual((('foo', 'baz'),), |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
98 |
rs.get_items('a.txt')) |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
99 |
self.assertEqual('baz', rs.get_single_value('a.txt', 'foo')) |
100 |
self.assertEqual((('foo', 'bar'), ('a', 'True')), |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
101 |
rs.get_items('dir/a.txt')) |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
102 |
self.assertEqual('bar', rs.get_single_value('dir/a.txt', 'foo')) |
|
3398.1.15
by Ian Clatworthy
search branch.rules and bazaar.rules for preferences |
103 |
|
104 |
||
|
3398.1.18
by Ian Clatworthy
add tests for _StackedRulesSearcher |
105 |
class TestStackedRulesSearcher(tests.TestCase): |
106 |
||
|
3398.1.33
by Ian Clatworthy
use a string, not lists, for test data |
107 |
def make_searcher(self, text1=None, text2=None): |
|
3398.1.18
by Ian Clatworthy
add tests for _StackedRulesSearcher |
108 |
"""Make a _StackedRulesSearcher with 0, 1 or 2 items""" |
109 |
searchers = [] |
|
|
3398.1.33
by Ian Clatworthy
use a string, not lists, for test data |
110 |
if text1 is not None: |
111 |
searchers.append(rules._IniBasedRulesSearcher( |
|
112 |
text1.splitlines())) |
|
113 |
if text2 is not None: |
|
114 |
searchers.append(rules._IniBasedRulesSearcher( |
|
115 |
text2.splitlines())) |
|
|
3398.1.18
by Ian Clatworthy
add tests for _StackedRulesSearcher |
116 |
return rules._StackedRulesSearcher(searchers) |
117 |
||
118 |
def test_stack_searching(self): |
|
119 |
rs = self.make_searcher( |
|
|
3398.1.33
by Ian Clatworthy
use a string, not lists, for test data |
120 |
"[name ./a.txt]\nfoo=baz\n", |
121 |
"[name *.txt]\nfoo=bar\na=True\n") |
|
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
122 |
self.assertEqual((('foo', 'baz'),), |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
123 |
rs.get_items('a.txt')) |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
124 |
self.assertEqual('baz', rs.get_single_value('a.txt', 'foo')) |
125 |
self.assertEqual(None, rs.get_single_value('a.txt', 'a')) |
|
126 |
self.assertEqual((('foo', 'bar'), ('a', 'True')), |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
127 |
rs.get_items('dir/a.txt')) |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
128 |
self.assertEqual('bar', rs.get_single_value('dir/a.txt', 'foo')) |
129 |
self.assertEqual('True', rs.get_single_value('dir/a.txt', 'a')) |
|
|
3398.1.18
by Ian Clatworthy
add tests for _StackedRulesSearcher |
130 |
|
131 |
||
|
3398.1.15
by Ian Clatworthy
search branch.rules and bazaar.rules for preferences |
132 |
class TestRulesPath(tests.TestCase): |
|
3398.1.4
by Ian Clatworthy
add properties_filename() test |
133 |
|
134 |
def setUp(self): |
|
|
3398.1.15
by Ian Clatworthy
search branch.rules and bazaar.rules for preferences |
135 |
super(TestRulesPath, self).setUp() |
|
5570.3.8
by Vincent Ladeuil
More use cases for overrideEnv. |
136 |
self.overrideEnv('HOME', '/home/bogus') |
|
3398.1.4
by Ian Clatworthy
add properties_filename() test |
137 |
if sys.platform == 'win32': |
|
5570.3.8
by Vincent Ladeuil
More use cases for overrideEnv. |
138 |
self.overrideEnv( |
|
6622.1.28
by Jelmer Vernooij
More renames; commands in output, environment variables. |
139 |
'BRZ_HOME', r'C:\Documents and Settings\bogus\Application Data') |
|
6622.1.33
by Jelmer Vernooij
Fix more tests (all?) |
140 |
self.brz_home = \ |
141 |
'C:/Documents and Settings/bogus/Application Data/breezy'
|
|
|
3398.1.4
by Ian Clatworthy
add properties_filename() test |
142 |
else: |
|
6622.1.33
by Jelmer Vernooij
Fix more tests (all?) |
143 |
self.brz_home = '/home/bogus/.config/breezy' |
|
3398.1.4
by Ian Clatworthy
add properties_filename() test |
144 |
|
|
7336.2.1
by Martin
Split non-ini config methods to bedding |
145 |
def test_rules_path(self): |
146 |
self.assertEqual(rules.rules_path(), self.brz_home + '/rules') |