2052.3.2
by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical |
1 |
# Copyright (C) 2005, 2006 Canonical Ltd
|
1442.1.1
by Robert Collins
move config_dir into bzrlib.config |
2 |
# Authors: Robert Collins <robert.collins@canonical.com>
|
3 |
#
|
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17 |
||
18 |
"""Tests for finding and reading the bzr config file[s]."""
|
|
19 |
# import system imports here
|
|
1474
by Robert Collins
Merge from Aaron Bentley. |
20 |
from bzrlib.util.configobj.configobj import ConfigObj, ConfigObjError |
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
21 |
from cStringIO import StringIO |
1442.1.1
by Robert Collins
move config_dir into bzrlib.config |
22 |
import os |
23 |
import sys |
|
24 |
||
25 |
#import bzrlib specific imports here
|
|
1878.1.3
by John Arbash Meinel
some test cleanups |
26 |
from bzrlib import ( |
27 |
config, |
|
28 |
errors, |
|
29 |
osutils, |
|
2681.1.8
by Aaron Bentley
Add Thunderbird support to bzr send |
30 |
mail_client, |
1878.1.3
by John Arbash Meinel
some test cleanups |
31 |
urlutils, |
1551.15.35
by Aaron Bentley
Warn when setting config values that will be masked (#122286) |
32 |
trace, |
1878.1.3
by John Arbash Meinel
some test cleanups |
33 |
)
|
1770.2.9
by Aaron Bentley
Add Branch.get_config, update BranchConfig() callers |
34 |
from bzrlib.branch import Branch |
35 |
from bzrlib.bzrdir import BzrDir |
|
1824.1.1
by Robert Collins
Add BranchConfig.has_explicit_nickname call. |
36 |
from bzrlib.tests import TestCase, TestCaseInTempDir, TestCaseWithTransport |
1442.1.1
by Robert Collins
move config_dir into bzrlib.config |
37 |
|
38 |
||
1553.6.12
by Erik Bågfors
remove AliasConfig, based on input from abentley |
39 |
sample_long_alias="log -r-15..-1 --line" |
2120.6.2
by James Henstridge
remove get_matching_sections() norecurse tests, since that feature is handled in the config policy code now |
40 |
sample_config_text = u""" |
41 |
[DEFAULT]
|
|
42 |
email=Erik B\u00e5gfors <erik@bagfors.nu> |
|
43 |
editor=vim
|
|
44 |
gpg_signing_command=gnome-gpg
|
|
45 |
log_format=short
|
|
46 |
user_global_option=something
|
|
47 |
[ALIASES]
|
|
48 |
h=help
|
|
49 |
ll=""" + sample_long_alias + "\n" |
|
50 |
||
51 |
||
52 |
sample_always_signatures = """ |
|
53 |
[DEFAULT]
|
|
54 |
check_signatures=ignore
|
|
55 |
create_signatures=always
|
|
56 |
"""
|
|
57 |
||
58 |
sample_ignore_signatures = """ |
|
59 |
[DEFAULT]
|
|
60 |
check_signatures=require
|
|
61 |
create_signatures=never
|
|
62 |
"""
|
|
63 |
||
64 |
sample_maybe_signatures = """ |
|
65 |
[DEFAULT]
|
|
66 |
check_signatures=ignore
|
|
67 |
create_signatures=when-required
|
|
68 |
"""
|
|
69 |
||
70 |
sample_branches_text = """ |
|
71 |
[http://www.example.com]
|
|
72 |
# Top level policy
|
|
73 |
email=Robert Collins <robertc@example.org>
|
|
2120.6.3
by James Henstridge
add some more tests for getting policy options, and behaviour of get_user_option in the presence of config policies |
74 |
normal_option = normal
|
75 |
appendpath_option = append
|
|
2120.6.8
by James Henstridge
Change syntax for setting config option policies. Rather than |
76 |
appendpath_option:policy = appendpath
|
2120.6.3
by James Henstridge
add some more tests for getting policy options, and behaviour of get_user_option in the presence of config policies |
77 |
norecurse_option = norecurse
|
2120.6.8
by James Henstridge
Change syntax for setting config option policies. Rather than |
78 |
norecurse_option:policy = norecurse
|
2120.6.2
by James Henstridge
remove get_matching_sections() norecurse tests, since that feature is handled in the config policy code now |
79 |
[http://www.example.com/ignoreparent]
|
80 |
# different project: ignore parent dir config
|
|
81 |
ignore_parents=true
|
|
82 |
[http://www.example.com/norecurse]
|
|
83 |
# configuration items that only apply to this dir
|
|
84 |
recurse=false
|
|
2120.6.3
by James Henstridge
add some more tests for getting policy options, and behaviour of get_user_option in the presence of config policies |
85 |
normal_option = norecurse
|
86 |
[http://www.example.com/dir]
|
|
87 |
appendpath_option = normal
|
|
2120.6.2
by James Henstridge
remove get_matching_sections() norecurse tests, since that feature is handled in the config policy code now |
88 |
[/b/]
|
89 |
check_signatures=require
|
|
90 |
# test trailing / matching with no children
|
|
91 |
[/a/]
|
|
92 |
check_signatures=check-available
|
|
93 |
gpg_signing_command=false
|
|
94 |
user_local_option=local
|
|
95 |
# test trailing / matching
|
|
96 |
[/a/*]
|
|
97 |
#subdirs will match but not the parent
|
|
98 |
[/a/c]
|
|
99 |
check_signatures=ignore
|
|
100 |
post_commit=bzrlib.tests.test_config.post_commit
|
|
101 |
#testing explicit beats globs
|
|
102 |
"""
|
|
1553.6.3
by Erik Bågfors
tests for AliasesConfig |
103 |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
104 |
|
1474
by Robert Collins
Merge from Aaron Bentley. |
105 |
class InstrumentedConfigObj(object): |
106 |
"""A config obj look-enough-alike to record calls made to it."""
|
|
107 |
||
1490
by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1. |
108 |
def __contains__(self, thing): |
109 |
self._calls.append(('__contains__', thing)) |
|
110 |
return False |
|
111 |
||
112 |
def __getitem__(self, key): |
|
113 |
self._calls.append(('__getitem__', key)) |
|
114 |
return self |
|
115 |
||
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
116 |
def __init__(self, input, encoding=None): |
117 |
self._calls = [('__init__', input, encoding)] |
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
118 |
|
1490
by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1. |
119 |
def __setitem__(self, key, value): |
120 |
self._calls.append(('__setitem__', key, value)) |
|
121 |
||
2120.6.4
by James Henstridge
add support for specifying policy when storing options |
122 |
def __delitem__(self, key): |
123 |
self._calls.append(('__delitem__', key)) |
|
124 |
||
125 |
def keys(self): |
|
126 |
self._calls.append(('keys',)) |
|
127 |
return [] |
|
128 |
||
1551.2.49
by abentley
Made ConfigObj output binary-identical files on win32 and *nix |
129 |
def write(self, arg): |
1490
by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1. |
130 |
self._calls.append(('write',)) |
131 |
||
2120.6.4
by James Henstridge
add support for specifying policy when storing options |
132 |
def as_bool(self, value): |
133 |
self._calls.append(('as_bool', value)) |
|
134 |
return False |
|
135 |
||
136 |
def get_value(self, section, name): |
|
137 |
self._calls.append(('get_value', section, name)) |
|
138 |
return None |
|
139 |
||
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
140 |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
141 |
class FakeBranch(object): |
142 |
||
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
143 |
def __init__(self, base=None, user_id=None): |
144 |
if base is None: |
|
145 |
self.base = "http://example.com/branches/demo" |
|
146 |
else: |
|
147 |
self.base = base |
|
148 |
self.control_files = FakeControlFiles(user_id=user_id) |
|
149 |
||
150 |
def lock_write(self): |
|
151 |
pass
|
|
152 |
||
153 |
def unlock(self): |
|
154 |
pass
|
|
1185.65.11
by Robert Collins
Disable inheritance for getting at LockableFiles, rather use composition. |
155 |
|
156 |
||
157 |
class FakeControlFiles(object): |
|
158 |
||
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
159 |
def __init__(self, user_id=None): |
160 |
self.email = user_id |
|
161 |
self.files = {} |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
162 |
|
1185.65.29
by Robert Collins
Implement final review suggestions. |
163 |
def get_utf8(self, filename): |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
164 |
if filename != 'email': |
165 |
raise NotImplementedError |
|
166 |
if self.email is not None: |
|
167 |
return StringIO(self.email) |
|
1185.31.45
by John Arbash Meinel
Refactoring Exceptions found some places where the wrong exception was caught. |
168 |
raise errors.NoSuchFile(filename) |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
169 |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
170 |
def get(self, filename): |
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
171 |
try: |
172 |
return StringIO(self.files[filename]) |
|
173 |
except KeyError: |
|
174 |
raise errors.NoSuchFile(filename) |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
175 |
|
176 |
def put(self, filename, fileobj): |
|
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
177 |
self.files[filename] = fileobj.read() |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
178 |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
179 |
|
180 |
class InstrumentedConfig(config.Config): |
|
181 |
"""An instrumented config that supplies stubs for template methods."""
|
|
182 |
||
183 |
def __init__(self): |
|
184 |
super(InstrumentedConfig, self).__init__() |
|
185 |
self._calls = [] |
|
1442.1.15
by Robert Collins
make getting the signature checking policy a template method |
186 |
self._signatures = config.CHECK_NEVER |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
187 |
|
188 |
def _get_user_id(self): |
|
189 |
self._calls.append('_get_user_id') |
|
190 |
return "Robert Collins <robert.collins@example.org>" |
|
191 |
||
1442.1.15
by Robert Collins
make getting the signature checking policy a template method |
192 |
def _get_signature_checking(self): |
193 |
self._calls.append('_get_signature_checking') |
|
194 |
return self._signatures |
|
195 |
||
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
196 |
|
1556.2.2
by Aaron Bentley
Fixed get_bool |
197 |
bool_config = """[DEFAULT] |
198 |
active = true
|
|
199 |
inactive = false
|
|
200 |
[UPPERCASE]
|
|
201 |
active = True
|
|
202 |
nonactive = False
|
|
203 |
"""
|
|
204 |
class TestConfigObj(TestCase): |
|
205 |
def test_get_bool(self): |
|
206 |
from bzrlib.config import ConfigObj |
|
207 |
co = ConfigObj(StringIO(bool_config)) |
|
208 |
self.assertIs(co.get_bool('DEFAULT', 'active'), True) |
|
209 |
self.assertIs(co.get_bool('DEFAULT', 'inactive'), False) |
|
210 |
self.assertIs(co.get_bool('UPPERCASE', 'active'), True) |
|
211 |
self.assertIs(co.get_bool('UPPERCASE', 'nonactive'), False) |
|
212 |
||
213 |
||
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
214 |
class TestConfig(TestCase): |
215 |
||
216 |
def test_constructs(self): |
|
217 |
config.Config() |
|
218 |
||
219 |
def test_no_default_editor(self): |
|
220 |
self.assertRaises(NotImplementedError, config.Config().get_editor) |
|
221 |
||
222 |
def test_user_email(self): |
|
223 |
my_config = InstrumentedConfig() |
|
224 |
self.assertEqual('robert.collins@example.org', my_config.user_email()) |
|
225 |
self.assertEqual(['_get_user_id'], my_config._calls) |
|
226 |
||
227 |
def test_username(self): |
|
228 |
my_config = InstrumentedConfig() |
|
229 |
self.assertEqual('Robert Collins <robert.collins@example.org>', |
|
230 |
my_config.username()) |
|
231 |
self.assertEqual(['_get_user_id'], my_config._calls) |
|
1442.1.14
by Robert Collins
Create a default signature checking policy of CHECK_IF_POSSIBLE |
232 |
|
233 |
def test_signatures_default(self): |
|
234 |
my_config = config.Config() |
|
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
235 |
self.assertFalse(my_config.signature_needed()) |
1442.1.14
by Robert Collins
Create a default signature checking policy of CHECK_IF_POSSIBLE |
236 |
self.assertEqual(config.CHECK_IF_POSSIBLE, |
237 |
my_config.signature_checking()) |
|
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
238 |
self.assertEqual(config.SIGN_WHEN_REQUIRED, |
239 |
my_config.signing_policy()) |
|
1442.1.14
by Robert Collins
Create a default signature checking policy of CHECK_IF_POSSIBLE |
240 |
|
1442.1.15
by Robert Collins
make getting the signature checking policy a template method |
241 |
def test_signatures_template_method(self): |
242 |
my_config = InstrumentedConfig() |
|
243 |
self.assertEqual(config.CHECK_NEVER, my_config.signature_checking()) |
|
244 |
self.assertEqual(['_get_signature_checking'], my_config._calls) |
|
245 |
||
246 |
def test_signatures_template_method_none(self): |
|
247 |
my_config = InstrumentedConfig() |
|
248 |
my_config._signatures = None |
|
249 |
self.assertEqual(config.CHECK_IF_POSSIBLE, |
|
250 |
my_config.signature_checking()) |
|
251 |
self.assertEqual(['_get_signature_checking'], my_config._calls) |
|
252 |
||
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
253 |
def test_gpg_signing_command_default(self): |
254 |
my_config = config.Config() |
|
255 |
self.assertEqual('gpg', my_config.gpg_signing_command()) |
|
256 |
||
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
257 |
def test_get_user_option_default(self): |
258 |
my_config = config.Config() |
|
259 |
self.assertEqual(None, my_config.get_user_option('no_option')) |
|
260 |
||
1472
by Robert Collins
post commit hook, first pass implementation |
261 |
def test_post_commit_default(self): |
262 |
my_config = config.Config() |
|
263 |
self.assertEqual(None, my_config.post_commit()) |
|
264 |
||
1553.2.9
by Erik Bågfors
log_formatter => log_format for "named" formatters |
265 |
def test_log_format_default(self): |
1553.2.8
by Erik Bågfors
tests for config log_formatter |
266 |
my_config = config.Config() |
1553.2.9
by Erik Bågfors
log_formatter => log_format for "named" formatters |
267 |
self.assertEqual('long', my_config.log_format()) |
1553.2.8
by Erik Bågfors
tests for config log_formatter |
268 |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
269 |
|
1442.1.1
by Robert Collins
move config_dir into bzrlib.config |
270 |
class TestConfigPath(TestCase): |
271 |
||
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
272 |
def setUp(self): |
273 |
super(TestConfigPath, self).setUp() |
|
274 |
os.environ['HOME'] = '/home/bogus' |
|
2309.2.6
by Alexander Belchenko
bzr now use Win32 API to determine Application Data location, and don't rely solely on $APPDATA |
275 |
if sys.platform == 'win32': |
276 |
os.environ['BZR_HOME'] = \ |
|
277 |
r'C:\Documents and Settings\bogus\Application Data' |
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
278 |
|
1442.1.1
by Robert Collins
move config_dir into bzrlib.config |
279 |
def test_config_dir(self): |
1185.38.1
by John Arbash Meinel
Adding my win32 patch for moving the home directory. |
280 |
if sys.platform == 'win32': |
281 |
self.assertEqual(config.config_dir(), |
|
1185.31.36
by John Arbash Meinel
Fixup test_config.py to handle new paths |
282 |
'C:/Documents and Settings/bogus/Application Data/bazaar/2.0') |
1185.38.1
by John Arbash Meinel
Adding my win32 patch for moving the home directory. |
283 |
else: |
284 |
self.assertEqual(config.config_dir(), '/home/bogus/.bazaar') |
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
285 |
|
286 |
def test_config_filename(self): |
|
1185.38.1
by John Arbash Meinel
Adding my win32 patch for moving the home directory. |
287 |
if sys.platform == 'win32': |
288 |
self.assertEqual(config.config_filename(), |
|
1185.31.36
by John Arbash Meinel
Fixup test_config.py to handle new paths |
289 |
'C:/Documents and Settings/bogus/Application Data/bazaar/2.0/bazaar.conf') |
1185.38.1
by John Arbash Meinel
Adding my win32 patch for moving the home directory. |
290 |
else: |
291 |
self.assertEqual(config.config_filename(), |
|
292 |
'/home/bogus/.bazaar/bazaar.conf') |
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
293 |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
294 |
def test_branches_config_filename(self): |
1185.38.1
by John Arbash Meinel
Adding my win32 patch for moving the home directory. |
295 |
if sys.platform == 'win32': |
296 |
self.assertEqual(config.branches_config_filename(), |
|
1185.31.36
by John Arbash Meinel
Fixup test_config.py to handle new paths |
297 |
'C:/Documents and Settings/bogus/Application Data/bazaar/2.0/branches.conf') |
1185.38.1
by John Arbash Meinel
Adding my win32 patch for moving the home directory. |
298 |
else: |
299 |
self.assertEqual(config.branches_config_filename(), |
|
300 |
'/home/bogus/.bazaar/branches.conf') |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
301 |
|
1770.2.2
by Aaron Bentley
Rename branches.conf to locations.conf |
302 |
def test_locations_config_filename(self): |
303 |
if sys.platform == 'win32': |
|
304 |
self.assertEqual(config.locations_config_filename(), |
|
305 |
'C:/Documents and Settings/bogus/Application Data/bazaar/2.0/locations.conf') |
|
306 |
else: |
|
307 |
self.assertEqual(config.locations_config_filename(), |
|
308 |
'/home/bogus/.bazaar/locations.conf') |
|
309 |
||
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
310 |
class TestIniConfig(TestCase): |
311 |
||
312 |
def test_contructs(self): |
|
313 |
my_config = config.IniBasedConfig("nothing") |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
314 |
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
315 |
def test_from_fp(self): |
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
316 |
config_file = StringIO(sample_config_text.encode('utf-8')) |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
317 |
my_config = config.IniBasedConfig(None) |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
318 |
self.failUnless( |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
319 |
isinstance(my_config._get_parser(file=config_file), |
1474
by Robert Collins
Merge from Aaron Bentley. |
320 |
ConfigObj)) |
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
321 |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
322 |
def test_cached(self): |
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
323 |
config_file = StringIO(sample_config_text.encode('utf-8')) |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
324 |
my_config = config.IniBasedConfig(None) |
325 |
parser = my_config._get_parser(file=config_file) |
|
326 |
self.failUnless(my_config._get_parser() is parser) |
|
327 |
||
328 |
||
329 |
class TestGetConfig(TestCase): |
|
330 |
||
331 |
def test_constructs(self): |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
332 |
my_config = config.GlobalConfig() |
333 |
||
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
334 |
def test_calls_read_filenames(self): |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
335 |
# replace the class that is constructured, to check its parameters
|
1474
by Robert Collins
Merge from Aaron Bentley. |
336 |
oldparserclass = config.ConfigObj |
337 |
config.ConfigObj = InstrumentedConfigObj |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
338 |
my_config = config.GlobalConfig() |
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
339 |
try: |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
340 |
parser = my_config._get_parser() |
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
341 |
finally: |
1474
by Robert Collins
Merge from Aaron Bentley. |
342 |
config.ConfigObj = oldparserclass |
343 |
self.failUnless(isinstance(parser, InstrumentedConfigObj)) |
|
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
344 |
self.assertEqual(parser._calls, [('__init__', config.config_filename(), |
345 |
'utf-8')]) |
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
346 |
|
347 |
||
1824.1.1
by Robert Collins
Add BranchConfig.has_explicit_nickname call. |
348 |
class TestBranchConfig(TestCaseWithTransport): |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
349 |
|
350 |
def test_constructs(self): |
|
351 |
branch = FakeBranch() |
|
352 |
my_config = config.BranchConfig(branch) |
|
353 |
self.assertRaises(TypeError, config.BranchConfig) |
|
354 |
||
355 |
def test_get_location_config(self): |
|
356 |
branch = FakeBranch() |
|
357 |
my_config = config.BranchConfig(branch) |
|
358 |
location_config = my_config._get_location_config() |
|
359 |
self.assertEqual(branch.base, location_config.location) |
|
360 |
self.failUnless(location_config is my_config._get_location_config()) |
|
361 |
||
1770.2.9
by Aaron Bentley
Add Branch.get_config, update BranchConfig() callers |
362 |
def test_get_config(self): |
363 |
"""The Branch.get_config method works properly"""
|
|
364 |
b = BzrDir.create_standalone_workingtree('.').branch |
|
365 |
my_config = b.get_config() |
|
366 |
self.assertIs(my_config.get_user_option('wacky'), None) |
|
367 |
my_config.set_user_option('wacky', 'unlikely') |
|
368 |
self.assertEqual(my_config.get_user_option('wacky'), 'unlikely') |
|
369 |
||
370 |
# Ensure we get the same thing if we start again
|
|
371 |
b2 = Branch.open('.') |
|
372 |
my_config2 = b2.get_config() |
|
373 |
self.assertEqual(my_config2.get_user_option('wacky'), 'unlikely') |
|
374 |
||
1824.1.1
by Robert Collins
Add BranchConfig.has_explicit_nickname call. |
375 |
def test_has_explicit_nickname(self): |
376 |
b = self.make_branch('.') |
|
377 |
self.assertFalse(b.get_config().has_explicit_nickname()) |
|
378 |
b.nick = 'foo' |
|
379 |
self.assertTrue(b.get_config().has_explicit_nickname()) |
|
380 |
||
1878.1.1
by John Arbash Meinel
Entries in locations.conf should prefer local paths if available (bug #53653) |
381 |
def test_config_url(self): |
382 |
"""The Branch.get_config will use section that uses a local url"""
|
|
383 |
branch = self.make_branch('branch') |
|
384 |
self.assertEqual('branch', branch.nick) |
|
385 |
||
386 |
locations = config.locations_config_filename() |
|
387 |
config.ensure_config_dir_exists() |
|
388 |
local_url = urlutils.local_path_to_url('branch') |
|
389 |
open(locations, 'wb').write('[%s]\nnickname = foobar' |
|
390 |
% (local_url,)) |
|
391 |
self.assertEqual('foobar', branch.nick) |
|
392 |
||
393 |
def test_config_local_path(self): |
|
394 |
"""The Branch.get_config will use a local system path"""
|
|
395 |
branch = self.make_branch('branch') |
|
396 |
self.assertEqual('branch', branch.nick) |
|
397 |
||
398 |
locations = config.locations_config_filename() |
|
399 |
config.ensure_config_dir_exists() |
|
400 |
open(locations, 'wb').write('[%s/branch]\nnickname = barry' |
|
401 |
% (osutils.getcwd().encode('utf8'),)) |
|
402 |
self.assertEqual('barry', branch.nick) |
|
403 |
||
1878.1.2
by John Arbash Meinel
Add a test that new locations.conf entries are created with a local path, rather than a URL |
404 |
def test_config_creates_local(self): |
405 |
"""Creating a new entry in config uses a local path."""
|
|
2230.3.6
by Aaron Bentley
work in progress bind stuff |
406 |
branch = self.make_branch('branch', format='knit') |
1878.1.2
by John Arbash Meinel
Add a test that new locations.conf entries are created with a local path, rather than a URL |
407 |
branch.set_push_location('http://foobar') |
408 |
locations = config.locations_config_filename() |
|
409 |
local_path = osutils.getcwd().encode('utf8') |
|
410 |
# Surprisingly ConfigObj doesn't create a trailing newline
|
|
411 |
self.check_file_contents(locations, |
|
2120.6.8
by James Henstridge
Change syntax for setting config option policies. Rather than |
412 |
'[%s/branch]\npush_location = http://foobar\npush_location:policy = norecurse' % (local_path,)) |
1878.1.2
by John Arbash Meinel
Add a test that new locations.conf entries are created with a local path, rather than a URL |
413 |
|
2120.5.4
by Alexander Belchenko
Whitebox test for Config.get_nickname (req. by Aaron Bentley) |
414 |
def test_autonick_urlencoded(self): |
415 |
b = self.make_branch('!repo') |
|
416 |
self.assertEqual('!repo', b.get_config().get_nickname()) |
|
417 |
||
1551.15.35
by Aaron Bentley
Warn when setting config values that will be masked (#122286) |
418 |
def test_warn_if_masked(self): |
419 |
_warning = trace.warning |
|
420 |
warnings = [] |
|
421 |
def warning(*args): |
|
422 |
warnings.append(args[0] % args[1:]) |
|
423 |
||
424 |
def set_option(store, warn_masked=True): |
|
425 |
warnings[:] = [] |
|
426 |
conf.set_user_option('example_option', repr(store), store=store, |
|
427 |
warn_masked=warn_masked) |
|
428 |
def assertWarning(warning): |
|
429 |
if warning is None: |
|
430 |
self.assertEqual(0, len(warnings)) |
|
431 |
else: |
|
432 |
self.assertEqual(1, len(warnings)) |
|
433 |
self.assertEqual(warning, warnings[0]) |
|
434 |
trace.warning = warning |
|
435 |
try: |
|
436 |
branch = self.make_branch('.') |
|
437 |
conf = branch.get_config() |
|
438 |
set_option(config.STORE_GLOBAL) |
|
439 |
assertWarning(None) |
|
440 |
set_option(config.STORE_BRANCH) |
|
441 |
assertWarning(None) |
|
442 |
set_option(config.STORE_GLOBAL) |
|
443 |
assertWarning('Value "4" is masked by "3" from branch.conf') |
|
444 |
set_option(config.STORE_GLOBAL, warn_masked=False) |
|
445 |
assertWarning(None) |
|
446 |
set_option(config.STORE_LOCATION) |
|
447 |
assertWarning(None) |
|
448 |
set_option(config.STORE_BRANCH) |
|
449 |
assertWarning('Value "3" is masked by "0" from locations.conf') |
|
450 |
set_option(config.STORE_BRANCH, warn_masked=False) |
|
451 |
assertWarning(None) |
|
452 |
finally: |
|
453 |
trace.warning = _warning |
|
454 |
||
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
455 |
|
1442.1.55
by Robert Collins
move environment preservation up to the root test case, making it available to all tests |
456 |
class TestGlobalConfigItems(TestCase): |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
457 |
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
458 |
def test_user_id(self): |
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
459 |
config_file = StringIO(sample_config_text.encode('utf-8')) |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
460 |
my_config = config.GlobalConfig() |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
461 |
my_config._parser = my_config._get_parser(file=config_file) |
1551.2.21
by Aaron Bentley
Formatted unicode config tests as ASCII |
462 |
self.assertEqual(u"Erik B\u00e5gfors <erik@bagfors.nu>", |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
463 |
my_config._get_user_id()) |
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
464 |
|
465 |
def test_absent_user_id(self): |
|
466 |
config_file = StringIO("") |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
467 |
my_config = config.GlobalConfig() |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
468 |
my_config._parser = my_config._get_parser(file=config_file) |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
469 |
self.assertEqual(None, my_config._get_user_id()) |
470 |
||
471 |
def test_configured_editor(self): |
|
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
472 |
config_file = StringIO(sample_config_text.encode('utf-8')) |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
473 |
my_config = config.GlobalConfig() |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
474 |
my_config._parser = my_config._get_parser(file=config_file) |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
475 |
self.assertEqual("vim", my_config.get_editor()) |
476 |
||
1442.1.17
by Robert Collins
allow global overriding of signature policy to force checking, or (pointless but allowed) to set auto checking |
477 |
def test_signatures_always(self): |
478 |
config_file = StringIO(sample_always_signatures) |
|
479 |
my_config = config.GlobalConfig() |
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
480 |
my_config._parser = my_config._get_parser(file=config_file) |
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
481 |
self.assertEqual(config.CHECK_NEVER, |
1442.1.17
by Robert Collins
allow global overriding of signature policy to force checking, or (pointless but allowed) to set auto checking |
482 |
my_config.signature_checking()) |
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
483 |
self.assertEqual(config.SIGN_ALWAYS, |
484 |
my_config.signing_policy()) |
|
1442.1.21
by Robert Collins
create signature_needed() call for commit to trigger creating signatures |
485 |
self.assertEqual(True, my_config.signature_needed()) |
1442.1.17
by Robert Collins
allow global overriding of signature policy to force checking, or (pointless but allowed) to set auto checking |
486 |
|
487 |
def test_signatures_if_possible(self): |
|
488 |
config_file = StringIO(sample_maybe_signatures) |
|
489 |
my_config = config.GlobalConfig() |
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
490 |
my_config._parser = my_config._get_parser(file=config_file) |
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
491 |
self.assertEqual(config.CHECK_NEVER, |
1442.1.17
by Robert Collins
allow global overriding of signature policy to force checking, or (pointless but allowed) to set auto checking |
492 |
my_config.signature_checking()) |
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
493 |
self.assertEqual(config.SIGN_WHEN_REQUIRED, |
494 |
my_config.signing_policy()) |
|
1442.1.21
by Robert Collins
create signature_needed() call for commit to trigger creating signatures |
495 |
self.assertEqual(False, my_config.signature_needed()) |
1442.1.17
by Robert Collins
allow global overriding of signature policy to force checking, or (pointless but allowed) to set auto checking |
496 |
|
1442.1.16
by Robert Collins
allow global overriding of signature policy to never check |
497 |
def test_signatures_ignore(self): |
498 |
config_file = StringIO(sample_ignore_signatures) |
|
499 |
my_config = config.GlobalConfig() |
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
500 |
my_config._parser = my_config._get_parser(file=config_file) |
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
501 |
self.assertEqual(config.CHECK_ALWAYS, |
1442.1.16
by Robert Collins
allow global overriding of signature policy to never check |
502 |
my_config.signature_checking()) |
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
503 |
self.assertEqual(config.SIGN_NEVER, |
504 |
my_config.signing_policy()) |
|
1442.1.21
by Robert Collins
create signature_needed() call for commit to trigger creating signatures |
505 |
self.assertEqual(False, my_config.signature_needed()) |
1442.1.16
by Robert Collins
allow global overriding of signature policy to never check |
506 |
|
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
507 |
def _get_sample_config(self): |
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
508 |
config_file = StringIO(sample_config_text.encode('utf-8')) |
1534.7.154
by Aaron Bentley
Removed changes from bzr.ab 1529..1536 |
509 |
my_config = config.GlobalConfig() |
510 |
my_config._parser = my_config._get_parser(file=config_file) |
|
511 |
return my_config |
|
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
512 |
|
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
513 |
def test_gpg_signing_command(self): |
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
514 |
my_config = self._get_sample_config() |
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
515 |
self.assertEqual("gnome-gpg", my_config.gpg_signing_command()) |
516 |
self.assertEqual(False, my_config.signature_needed()) |
|
517 |
||
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
518 |
def _get_empty_config(self): |
519 |
config_file = StringIO("") |
|
520 |
my_config = config.GlobalConfig() |
|
521 |
my_config._parser = my_config._get_parser(file=config_file) |
|
522 |
return my_config |
|
523 |
||
1442.1.59
by Robert Collins
Add re-sign command to generate a digital signature on a single revision. |
524 |
def test_gpg_signing_command_unset(self): |
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
525 |
my_config = self._get_empty_config() |
1442.1.59
by Robert Collins
Add re-sign command to generate a digital signature on a single revision. |
526 |
self.assertEqual("gpg", my_config.gpg_signing_command()) |
527 |
||
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
528 |
def test_get_user_option_default(self): |
529 |
my_config = self._get_empty_config() |
|
530 |
self.assertEqual(None, my_config.get_user_option('no_option')) |
|
531 |
||
532 |
def test_get_user_option_global(self): |
|
533 |
my_config = self._get_sample_config() |
|
534 |
self.assertEqual("something", |
|
535 |
my_config.get_user_option('user_global_option')) |
|
1472
by Robert Collins
post commit hook, first pass implementation |
536 |
|
537 |
def test_post_commit_default(self): |
|
538 |
my_config = self._get_sample_config() |
|
539 |
self.assertEqual(None, my_config.post_commit()) |
|
540 |
||
1553.2.9
by Erik Bågfors
log_formatter => log_format for "named" formatters |
541 |
def test_configured_logformat(self): |
1553.2.8
by Erik Bågfors
tests for config log_formatter |
542 |
my_config = self._get_sample_config() |
1553.2.9
by Erik Bågfors
log_formatter => log_format for "named" formatters |
543 |
self.assertEqual("short", my_config.log_format()) |
1553.2.8
by Erik Bågfors
tests for config log_formatter |
544 |
|
1553.6.12
by Erik Bågfors
remove AliasConfig, based on input from abentley |
545 |
def test_get_alias(self): |
546 |
my_config = self._get_sample_config() |
|
547 |
self.assertEqual('help', my_config.get_alias('h')) |
|
548 |
||
549 |
def test_get_no_alias(self): |
|
550 |
my_config = self._get_sample_config() |
|
551 |
self.assertEqual(None, my_config.get_alias('foo')) |
|
552 |
||
553 |
def test_get_long_alias(self): |
|
554 |
my_config = self._get_sample_config() |
|
555 |
self.assertEqual(sample_long_alias, my_config.get_alias('ll')) |
|
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
556 |
|
1704.2.18
by Martin Pool
Remove duplicated TestLocationConfig and update previously hidden tests. (#32587) |
557 |
|
558 |
class TestLocationConfig(TestCaseInTempDir): |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
559 |
|
560 |
def test_constructs(self): |
|
561 |
my_config = config.LocationConfig('http://example.com') |
|
562 |
self.assertRaises(TypeError, config.LocationConfig) |
|
563 |
||
564 |
def test_branch_calls_read_filenames(self): |
|
1474
by Robert Collins
Merge from Aaron Bentley. |
565 |
# This is testing the correct file names are provided.
|
566 |
# TODO: consolidate with the test for GlobalConfigs filename checks.
|
|
567 |
#
|
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
568 |
# replace the class that is constructured, to check its parameters
|
1474
by Robert Collins
Merge from Aaron Bentley. |
569 |
oldparserclass = config.ConfigObj |
570 |
config.ConfigObj = InstrumentedConfigObj |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
571 |
try: |
1770.2.2
by Aaron Bentley
Rename branches.conf to locations.conf |
572 |
my_config = config.LocationConfig('http://www.example.com') |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
573 |
parser = my_config._get_parser() |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
574 |
finally: |
1474
by Robert Collins
Merge from Aaron Bentley. |
575 |
config.ConfigObj = oldparserclass |
576 |
self.failUnless(isinstance(parser, InstrumentedConfigObj)) |
|
577 |
self.assertEqual(parser._calls, |
|
1770.2.2
by Aaron Bentley
Rename branches.conf to locations.conf |
578 |
[('__init__', config.locations_config_filename(), |
1704.2.18
by Martin Pool
Remove duplicated TestLocationConfig and update previously hidden tests. (#32587) |
579 |
'utf-8')]) |
1711.4.29
by John Arbash Meinel
Alexander Belchenko, fix test_config to use ensure_config_dir, rather than os.mkdir() |
580 |
config.ensure_config_dir_exists() |
581 |
#os.mkdir(config.config_dir())
|
|
1770.2.2
by Aaron Bentley
Rename branches.conf to locations.conf |
582 |
f = file(config.branches_config_filename(), 'wb') |
583 |
f.write('') |
|
584 |
f.close() |
|
585 |
oldparserclass = config.ConfigObj |
|
586 |
config.ConfigObj = InstrumentedConfigObj |
|
587 |
try: |
|
588 |
my_config = config.LocationConfig('http://www.example.com') |
|
589 |
parser = my_config._get_parser() |
|
590 |
finally: |
|
591 |
config.ConfigObj = oldparserclass |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
592 |
|
593 |
def test_get_global_config(self): |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
594 |
my_config = config.BranchConfig(FakeBranch('http://example.com')) |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
595 |
global_config = my_config._get_global_config() |
596 |
self.failUnless(isinstance(global_config, config.GlobalConfig)) |
|
597 |
self.failUnless(global_config is my_config._get_global_config()) |
|
598 |
||
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
599 |
def test__get_matching_sections_no_match(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
600 |
self.get_branch_config('/') |
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
601 |
self.assertEqual([], self.my_location_config._get_matching_sections()) |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
602 |
|
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
603 |
def test__get_matching_sections_exact(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
604 |
self.get_branch_config('http://www.example.com') |
1993.3.3
by James Henstridge
make _get_matching_sections() return (section, extra_path) tuples, and adjust other code to match |
605 |
self.assertEqual([('http://www.example.com', '')], |
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
606 |
self.my_location_config._get_matching_sections()) |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
607 |
|
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
608 |
def test__get_matching_sections_suffix_does_not(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
609 |
self.get_branch_config('http://www.example.com-com') |
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
610 |
self.assertEqual([], self.my_location_config._get_matching_sections()) |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
611 |
|
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
612 |
def test__get_matching_sections_subdir_recursive(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
613 |
self.get_branch_config('http://www.example.com/com') |
1993.3.3
by James Henstridge
make _get_matching_sections() return (section, extra_path) tuples, and adjust other code to match |
614 |
self.assertEqual([('http://www.example.com', 'com')], |
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
615 |
self.my_location_config._get_matching_sections()) |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
616 |
|
1993.3.5
by James Henstridge
add back recurse=False option to config file |
617 |
def test__get_matching_sections_ignoreparent(self): |
1993.3.3
by James Henstridge
make _get_matching_sections() return (section, extra_path) tuples, and adjust other code to match |
618 |
self.get_branch_config('http://www.example.com/ignoreparent') |
619 |
self.assertEqual([('http://www.example.com/ignoreparent', '')], |
|
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
620 |
self.my_location_config._get_matching_sections()) |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
621 |
|
1993.3.5
by James Henstridge
add back recurse=False option to config file |
622 |
def test__get_matching_sections_ignoreparent_subdir(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
623 |
self.get_branch_config( |
1993.3.3
by James Henstridge
make _get_matching_sections() return (section, extra_path) tuples, and adjust other code to match |
624 |
'http://www.example.com/ignoreparent/childbranch') |
625 |
self.assertEqual([('http://www.example.com/ignoreparent', 'childbranch')], |
|
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
626 |
self.my_location_config._get_matching_sections()) |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
627 |
|
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
628 |
def test__get_matching_sections_subdir_trailing_slash(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
629 |
self.get_branch_config('/b') |
1993.3.3
by James Henstridge
make _get_matching_sections() return (section, extra_path) tuples, and adjust other code to match |
630 |
self.assertEqual([('/b/', '')], |
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
631 |
self.my_location_config._get_matching_sections()) |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
632 |
|
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
633 |
def test__get_matching_sections_subdir_child(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
634 |
self.get_branch_config('/a/foo') |
1993.3.3
by James Henstridge
make _get_matching_sections() return (section, extra_path) tuples, and adjust other code to match |
635 |
self.assertEqual([('/a/*', ''), ('/a/', 'foo')], |
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
636 |
self.my_location_config._get_matching_sections()) |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
637 |
|
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
638 |
def test__get_matching_sections_subdir_child_child(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
639 |
self.get_branch_config('/a/foo/bar') |
1993.3.3
by James Henstridge
make _get_matching_sections() return (section, extra_path) tuples, and adjust other code to match |
640 |
self.assertEqual([('/a/*', 'bar'), ('/a/', 'foo/bar')], |
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
641 |
self.my_location_config._get_matching_sections()) |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
642 |
|
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
643 |
def test__get_matching_sections_trailing_slash_with_children(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
644 |
self.get_branch_config('/a/') |
1993.3.3
by James Henstridge
make _get_matching_sections() return (section, extra_path) tuples, and adjust other code to match |
645 |
self.assertEqual([('/a/', '')], |
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
646 |
self.my_location_config._get_matching_sections()) |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
647 |
|
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
648 |
def test__get_matching_sections_explicit_over_glob(self): |
649 |
# XXX: 2006-09-08 jamesh
|
|
650 |
# This test only passes because ord('c') > ord('*'). If there
|
|
651 |
# was a config section for '/a/?', it would get precedence
|
|
652 |
# over '/a/c'.
|
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
653 |
self.get_branch_config('/a/c') |
1993.3.3
by James Henstridge
make _get_matching_sections() return (section, extra_path) tuples, and adjust other code to match |
654 |
self.assertEqual([('/a/c', ''), ('/a/*', ''), ('/a/', 'c')], |
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
655 |
self.my_location_config._get_matching_sections()) |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
656 |
|
2120.6.3
by James Henstridge
add some more tests for getting policy options, and behaviour of get_user_option in the presence of config policies |
657 |
def test__get_option_policy_normal(self): |
658 |
self.get_branch_config('http://www.example.com') |
|
659 |
self.assertEqual( |
|
660 |
self.my_location_config._get_config_policy( |
|
661 |
'http://www.example.com', 'normal_option'), |
|
662 |
config.POLICY_NONE) |
|
663 |
||
664 |
def test__get_option_policy_norecurse(self): |
|
665 |
self.get_branch_config('http://www.example.com') |
|
666 |
self.assertEqual( |
|
667 |
self.my_location_config._get_option_policy( |
|
668 |
'http://www.example.com', 'norecurse_option'), |
|
669 |
config.POLICY_NORECURSE) |
|
670 |
# Test old recurse=False setting:
|
|
671 |
self.assertEqual( |
|
672 |
self.my_location_config._get_option_policy( |
|
673 |
'http://www.example.com/norecurse', 'normal_option'), |
|
674 |
config.POLICY_NORECURSE) |
|
675 |
||
676 |
def test__get_option_policy_normal(self): |
|
677 |
self.get_branch_config('http://www.example.com') |
|
678 |
self.assertEqual( |
|
679 |
self.my_location_config._get_option_policy( |
|
680 |
'http://www.example.com', 'appendpath_option'), |
|
681 |
config.POLICY_APPENDPATH) |
|
682 |
||
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
683 |
def test_location_without_username(self): |
1993.3.3
by James Henstridge
make _get_matching_sections() return (section, extra_path) tuples, and adjust other code to match |
684 |
self.get_branch_config('http://www.example.com/ignoreparent') |
1704.2.18
by Martin Pool
Remove duplicated TestLocationConfig and update previously hidden tests. (#32587) |
685 |
self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>', |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
686 |
self.my_config.username()) |
687 |
||
688 |
def test_location_not_listed(self): |
|
1704.2.18
by Martin Pool
Remove duplicated TestLocationConfig and update previously hidden tests. (#32587) |
689 |
"""Test that the global username is used when no location matches"""
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
690 |
self.get_branch_config('/home/robertc/sources') |
1704.2.18
by Martin Pool
Remove duplicated TestLocationConfig and update previously hidden tests. (#32587) |
691 |
self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>', |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
692 |
self.my_config.username()) |
693 |
||
1442.1.13
by Robert Collins
branches.conf is now able to override the users email |
694 |
def test_overriding_location(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
695 |
self.get_branch_config('http://www.example.com/foo') |
1442.1.13
by Robert Collins
branches.conf is now able to override the users email |
696 |
self.assertEqual('Robert Collins <robertc@example.org>', |
697 |
self.my_config.username()) |
|
1442.1.16
by Robert Collins
allow global overriding of signature policy to never check |
698 |
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
699 |
def test_signatures_not_set(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
700 |
self.get_branch_config('http://www.example.com', |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
701 |
global_config=sample_ignore_signatures) |
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
702 |
self.assertEqual(config.CHECK_ALWAYS, |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
703 |
self.my_config.signature_checking()) |
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
704 |
self.assertEqual(config.SIGN_NEVER, |
705 |
self.my_config.signing_policy()) |
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
706 |
|
707 |
def test_signatures_never(self): |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
708 |
self.get_branch_config('/a/c') |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
709 |
self.assertEqual(config.CHECK_NEVER, |
710 |
self.my_config.signature_checking()) |
|
711 |
||
1442.1.16
by Robert Collins
allow global overriding of signature policy to never check |
712 |
def test_signatures_when_available(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
713 |
self.get_branch_config('/a/', global_config=sample_ignore_signatures) |
1442.1.16
by Robert Collins
allow global overriding of signature policy to never check |
714 |
self.assertEqual(config.CHECK_IF_POSSIBLE, |
715 |
self.my_config.signature_checking()) |
|
1442.1.13
by Robert Collins
branches.conf is now able to override the users email |
716 |
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
717 |
def test_signatures_always(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
718 |
self.get_branch_config('/b') |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
719 |
self.assertEqual(config.CHECK_ALWAYS, |
720 |
self.my_config.signature_checking()) |
|
721 |
||
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
722 |
def test_gpg_signing_command(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
723 |
self.get_branch_config('/b') |
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
724 |
self.assertEqual("gnome-gpg", self.my_config.gpg_signing_command()) |
725 |
||
726 |
def test_gpg_signing_command_missing(self): |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
727 |
self.get_branch_config('/a') |
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
728 |
self.assertEqual("false", self.my_config.gpg_signing_command()) |
729 |
||
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
730 |
def test_get_user_option_global(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
731 |
self.get_branch_config('/a') |
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
732 |
self.assertEqual('something', |
733 |
self.my_config.get_user_option('user_global_option')) |
|
734 |
||
735 |
def test_get_user_option_local(self): |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
736 |
self.get_branch_config('/a') |
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
737 |
self.assertEqual('local', |
738 |
self.my_config.get_user_option('user_local_option')) |
|
1993.3.3
by James Henstridge
make _get_matching_sections() return (section, extra_path) tuples, and adjust other code to match |
739 |
|
2120.6.3
by James Henstridge
add some more tests for getting policy options, and behaviour of get_user_option in the presence of config policies |
740 |
def test_get_user_option_appendpath(self): |
741 |
# returned as is for the base path:
|
|
742 |
self.get_branch_config('http://www.example.com') |
|
743 |
self.assertEqual('append', |
|
744 |
self.my_config.get_user_option('appendpath_option')) |
|
745 |
# Extra path components get appended:
|
|
746 |
self.get_branch_config('http://www.example.com/a/b/c') |
|
747 |
self.assertEqual('append/a/b/c', |
|
748 |
self.my_config.get_user_option('appendpath_option')) |
|
749 |
# Overriden for http://www.example.com/dir, where it is a
|
|
750 |
# normal option:
|
|
751 |
self.get_branch_config('http://www.example.com/dir/a/b/c') |
|
752 |
self.assertEqual('normal', |
|
753 |
self.my_config.get_user_option('appendpath_option')) |
|
754 |
||
755 |
def test_get_user_option_norecurse(self): |
|
756 |
self.get_branch_config('http://www.example.com') |
|
757 |
self.assertEqual('norecurse', |
|
758 |
self.my_config.get_user_option('norecurse_option')) |
|
759 |
self.get_branch_config('http://www.example.com/dir') |
|
760 |
self.assertEqual(None, |
|
761 |
self.my_config.get_user_option('norecurse_option')) |
|
762 |
# http://www.example.com/norecurse is a recurse=False section
|
|
763 |
# that redefines normal_option. Subdirectories do not pick up
|
|
764 |
# this redefinition.
|
|
765 |
self.get_branch_config('http://www.example.com/norecurse') |
|
766 |
self.assertEqual('norecurse', |
|
767 |
self.my_config.get_user_option('normal_option')) |
|
768 |
self.get_branch_config('http://www.example.com/norecurse/subdir') |
|
769 |
self.assertEqual('normal', |
|
770 |
self.my_config.get_user_option('normal_option')) |
|
771 |
||
2120.6.4
by James Henstridge
add support for specifying policy when storing options |
772 |
def test_set_user_option_norecurse(self): |
773 |
self.get_branch_config('http://www.example.com') |
|
774 |
self.my_config.set_user_option('foo', 'bar', |
|
775 |
store=config.STORE_LOCATION_NORECURSE) |
|
776 |
self.assertEqual( |
|
777 |
self.my_location_config._get_option_policy( |
|
778 |
'http://www.example.com', 'foo'), |
|
779 |
config.POLICY_NORECURSE) |
|
780 |
||
781 |
def test_set_user_option_appendpath(self): |
|
782 |
self.get_branch_config('http://www.example.com') |
|
783 |
self.my_config.set_user_option('foo', 'bar', |
|
784 |
store=config.STORE_LOCATION_APPENDPATH) |
|
785 |
self.assertEqual( |
|
786 |
self.my_location_config._get_option_policy( |
|
787 |
'http://www.example.com', 'foo'), |
|
788 |
config.POLICY_APPENDPATH) |
|
789 |
||
790 |
def test_set_user_option_change_policy(self): |
|
791 |
self.get_branch_config('http://www.example.com') |
|
792 |
self.my_config.set_user_option('norecurse_option', 'normal', |
|
793 |
store=config.STORE_LOCATION) |
|
794 |
self.assertEqual( |
|
795 |
self.my_location_config._get_option_policy( |
|
796 |
'http://www.example.com', 'norecurse_option'), |
|
797 |
config.POLICY_NONE) |
|
798 |
||
799 |
def test_set_user_option_recurse_false_section(self): |
|
2120.6.9
by James Henstridge
Fixes for issues brought up in John's review |
800 |
# The following section has recurse=False set. The test is to
|
801 |
# make sure that a normal option can be added to the section,
|
|
802 |
# converting recurse=False to the norecurse policy.
|
|
2120.6.4
by James Henstridge
add support for specifying policy when storing options |
803 |
self.get_branch_config('http://www.example.com/norecurse') |
2120.6.11
by James Henstridge
s/0.13/0.14/ in deprecation warning |
804 |
self.callDeprecated(['The recurse option is deprecated as of 0.14. ' |
2120.6.9
by James Henstridge
Fixes for issues brought up in John's review |
805 |
'The section "http://www.example.com/norecurse" '
|
806 |
'has been converted to use policies.'], |
|
807 |
self.my_config.set_user_option, |
|
808 |
'foo', 'bar', store=config.STORE_LOCATION) |
|
2120.6.4
by James Henstridge
add support for specifying policy when storing options |
809 |
self.assertEqual( |
810 |
self.my_location_config._get_option_policy( |
|
811 |
'http://www.example.com/norecurse', 'foo'), |
|
812 |
config.POLICY_NONE) |
|
813 |
# The previously existing option is still norecurse:
|
|
814 |
self.assertEqual( |
|
815 |
self.my_location_config._get_option_policy( |
|
816 |
'http://www.example.com/norecurse', 'normal_option'), |
|
817 |
config.POLICY_NORECURSE) |
|
818 |
||
1472
by Robert Collins
post commit hook, first pass implementation |
819 |
def test_post_commit_default(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
820 |
self.get_branch_config('/a/c') |
1185.31.25
by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py |
821 |
self.assertEqual('bzrlib.tests.test_config.post_commit', |
1472
by Robert Collins
post commit hook, first pass implementation |
822 |
self.my_config.post_commit()) |
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
823 |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
824 |
def get_branch_config(self, location, global_config=None): |
1502
by Robert Collins
Bugfix the config test suite to not create .bazaar in the dir where it is run. |
825 |
if global_config is None: |
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
826 |
global_file = StringIO(sample_config_text.encode('utf-8')) |
1502
by Robert Collins
Bugfix the config test suite to not create .bazaar in the dir where it is run. |
827 |
else: |
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
828 |
global_file = StringIO(global_config.encode('utf-8')) |
829 |
branches_file = StringIO(sample_branches_text.encode('utf-8')) |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
830 |
self.my_config = config.BranchConfig(FakeBranch(location)) |
831 |
# Force location config to use specified file
|
|
832 |
self.my_location_config = self.my_config._get_location_config() |
|
833 |
self.my_location_config._get_parser(branches_file) |
|
834 |
# Force global config to use specified file
|
|
1502
by Robert Collins
Bugfix the config test suite to not create .bazaar in the dir where it is run. |
835 |
self.my_config._get_global_config()._get_parser(global_file) |
836 |
||
1490
by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1. |
837 |
def test_set_user_setting_sets_and_saves(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
838 |
self.get_branch_config('/a/c') |
1490
by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1. |
839 |
record = InstrumentedConfigObj("foo") |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
840 |
self.my_location_config._parser = record |
1185.62.6
by John Arbash Meinel
Updated test_set_user_setting_sets_and_saves to remove the print statement, and make sure it is doing the right thing |
841 |
|
842 |
real_mkdir = os.mkdir |
|
843 |
self.created = False |
|
844 |
def checked_mkdir(path, mode=0777): |
|
845 |
self.log('making directory: %s', path) |
|
846 |
real_mkdir(path, mode) |
|
847 |
self.created = True |
|
848 |
||
849 |
os.mkdir = checked_mkdir |
|
850 |
try: |
|
2120.6.10
by James Henstridge
Catch another deprecation warning, and more cleanup |
851 |
self.callDeprecated(['The recurse option is deprecated as of ' |
2120.6.11
by James Henstridge
s/0.13/0.14/ in deprecation warning |
852 |
'0.14. The section "/a/c" has been '
|
2120.6.10
by James Henstridge
Catch another deprecation warning, and more cleanup |
853 |
'converted to use policies.'], |
854 |
self.my_config.set_user_option, |
|
855 |
'foo', 'bar', store=config.STORE_LOCATION) |
|
1185.62.6
by John Arbash Meinel
Updated test_set_user_setting_sets_and_saves to remove the print statement, and make sure it is doing the right thing |
856 |
finally: |
857 |
os.mkdir = real_mkdir |
|
858 |
||
859 |
self.failUnless(self.created, 'Failed to create ~/.bazaar') |
|
1490
by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1. |
860 |
self.assertEqual([('__contains__', '/a/c'), |
861 |
('__contains__', '/a/c/'), |
|
862 |
('__setitem__', '/a/c', {}), |
|
863 |
('__getitem__', '/a/c'), |
|
864 |
('__setitem__', 'foo', 'bar'), |
|
2120.6.4
by James Henstridge
add support for specifying policy when storing options |
865 |
('__getitem__', '/a/c'), |
866 |
('as_bool', 'recurse'), |
|
867 |
('__getitem__', '/a/c'), |
|
868 |
('__delitem__', 'recurse'), |
|
869 |
('__getitem__', '/a/c'), |
|
870 |
('keys',), |
|
2120.6.8
by James Henstridge
Change syntax for setting config option policies. Rather than |
871 |
('__getitem__', '/a/c'), |
872 |
('__contains__', 'foo:policy'), |
|
1490
by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1. |
873 |
('write',)], |
874 |
record._calls[1:]) |
|
875 |
||
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
876 |
def test_set_user_setting_sets_and_saves2(self): |
877 |
self.get_branch_config('/a/c') |
|
878 |
self.assertIs(self.my_config.get_user_option('foo'), None) |
|
879 |
self.my_config.set_user_option('foo', 'bar') |
|
880 |
self.assertEqual( |
|
881 |
self.my_config.branch.control_files.files['branch.conf'], |
|
882 |
'foo = bar') |
|
883 |
self.assertEqual(self.my_config.get_user_option('foo'), 'bar') |
|
2120.6.4
by James Henstridge
add support for specifying policy when storing options |
884 |
self.my_config.set_user_option('foo', 'baz', |
885 |
store=config.STORE_LOCATION) |
|
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
886 |
self.assertEqual(self.my_config.get_user_option('foo'), 'baz') |
887 |
self.my_config.set_user_option('foo', 'qux') |
|
888 |
self.assertEqual(self.my_config.get_user_option('foo'), 'baz') |
|
889 |
||
1185.62.7
by John Arbash Meinel
Whitespace cleanup. |
890 |
|
1770.2.8
by Aaron Bentley
Add precedence test |
891 |
precedence_global = 'option = global' |
892 |
precedence_branch = 'option = branch' |
|
893 |
precedence_location = """ |
|
894 |
[http://]
|
|
895 |
recurse = true
|
|
896 |
option = recurse
|
|
897 |
[http://example.com/specific]
|
|
898 |
option = exact
|
|
899 |
"""
|
|
900 |
||
901 |
||
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
902 |
class TestBranchConfigItems(TestCaseInTempDir): |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
903 |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
904 |
def get_branch_config(self, global_config=None, location=None, |
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
905 |
location_config=None, branch_data_config=None): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
906 |
my_config = config.BranchConfig(FakeBranch(location)) |
907 |
if global_config is not None: |
|
908 |
global_file = StringIO(global_config.encode('utf-8')) |
|
909 |
my_config._get_global_config()._get_parser(global_file) |
|
910 |
self.my_location_config = my_config._get_location_config() |
|
911 |
if location_config is not None: |
|
912 |
location_file = StringIO(location_config.encode('utf-8')) |
|
913 |
self.my_location_config._get_parser(location_file) |
|
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
914 |
if branch_data_config is not None: |
915 |
my_config.branch.control_files.files['branch.conf'] = \ |
|
916 |
branch_data_config
|
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
917 |
return my_config |
918 |
||
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
919 |
def test_user_id(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
920 |
branch = FakeBranch(user_id='Robert Collins <robertc@example.net>') |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
921 |
my_config = config.BranchConfig(branch) |
922 |
self.assertEqual("Robert Collins <robertc@example.net>", |
|
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
923 |
my_config.username()) |
1185.65.11
by Robert Collins
Disable inheritance for getting at LockableFiles, rather use composition. |
924 |
branch.control_files.email = "John" |
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
925 |
my_config.set_user_option('email', |
926 |
"Robert Collins <robertc@example.org>") |
|
927 |
self.assertEqual("John", my_config.username()) |
|
928 |
branch.control_files.email = None |
|
929 |
self.assertEqual("Robert Collins <robertc@example.org>", |
|
930 |
my_config.username()) |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
931 |
|
932 |
def test_not_set_in_branch(self): |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
933 |
my_config = self.get_branch_config(sample_config_text) |
934 |
my_config.branch.control_files.email = None |
|
1551.2.21
by Aaron Bentley
Formatted unicode config tests as ASCII |
935 |
self.assertEqual(u"Erik B\u00e5gfors <erik@bagfors.nu>", |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
936 |
my_config._get_user_id()) |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
937 |
my_config.branch.control_files.email = "John" |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
938 |
self.assertEqual("John", my_config._get_user_id()) |
939 |
||
1861.4.1
by Matthieu Moy
BZREMAIL renamed to BZR_EMAIL. |
940 |
def test_BZR_EMAIL_OVERRIDES(self): |
941 |
os.environ['BZR_EMAIL'] = "Robert Collins <robertc@example.org>" |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
942 |
branch = FakeBranch() |
943 |
my_config = config.BranchConfig(branch) |
|
944 |
self.assertEqual("Robert Collins <robertc@example.org>", |
|
945 |
my_config.username()) |
|
946 |
||
1442.1.19
by Robert Collins
BranchConfigs inherit signature_checking policy from their LocationConfig. |
947 |
def test_signatures_forced(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
948 |
my_config = self.get_branch_config( |
949 |
global_config=sample_always_signatures) |
|
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
950 |
self.assertEqual(config.CHECK_NEVER, my_config.signature_checking()) |
951 |
self.assertEqual(config.SIGN_ALWAYS, my_config.signing_policy()) |
|
952 |
self.assertTrue(my_config.signature_needed()) |
|
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
953 |
|
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
954 |
def test_signatures_forced_branch(self): |
955 |
my_config = self.get_branch_config( |
|
956 |
global_config=sample_ignore_signatures, |
|
957 |
branch_data_config=sample_always_signatures) |
|
958 |
self.assertEqual(config.CHECK_NEVER, my_config.signature_checking()) |
|
959 |
self.assertEqual(config.SIGN_ALWAYS, my_config.signing_policy()) |
|
960 |
self.assertTrue(my_config.signature_needed()) |
|
961 |
||
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
962 |
def test_gpg_signing_command(self): |
1770.2.10
by Aaron Bentley
Added test that branch_config can't influence gpg_signing_command |
963 |
my_config = self.get_branch_config( |
964 |
# branch data cannot set gpg_signing_command
|
|
965 |
branch_data_config="gpg_signing_command=pgp") |
|
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
966 |
config_file = StringIO(sample_config_text.encode('utf-8')) |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
967 |
my_config._get_global_config()._get_parser(config_file) |
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
968 |
self.assertEqual('gnome-gpg', my_config.gpg_signing_command()) |
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
969 |
|
970 |
def test_get_user_option_global(self): |
|
971 |
branch = FakeBranch() |
|
972 |
my_config = config.BranchConfig(branch) |
|
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
973 |
config_file = StringIO(sample_config_text.encode('utf-8')) |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
974 |
(my_config._get_global_config()._get_parser(config_file)) |
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
975 |
self.assertEqual('something', |
976 |
my_config.get_user_option('user_global_option')) |
|
1472
by Robert Collins
post commit hook, first pass implementation |
977 |
|
978 |
def test_post_commit_default(self): |
|
979 |
branch = FakeBranch() |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
980 |
my_config = self.get_branch_config(sample_config_text, '/a/c', |
981 |
sample_branches_text) |
|
982 |
self.assertEqual(my_config.branch.base, '/a/c') |
|
1185.31.25
by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py |
983 |
self.assertEqual('bzrlib.tests.test_config.post_commit', |
1472
by Robert Collins
post commit hook, first pass implementation |
984 |
my_config.post_commit()) |
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
985 |
my_config.set_user_option('post_commit', 'rmtree_root') |
986 |
# post-commit is ignored when bresent in branch data
|
|
987 |
self.assertEqual('bzrlib.tests.test_config.post_commit', |
|
988 |
my_config.post_commit()) |
|
2120.6.4
by James Henstridge
add support for specifying policy when storing options |
989 |
my_config.set_user_option('post_commit', 'rmtree_root', |
990 |
store=config.STORE_LOCATION) |
|
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
991 |
self.assertEqual('rmtree_root', my_config.post_commit()) |
1185.33.31
by Martin Pool
Make annotate cope better with revisions committed without a valid |
992 |
|
1770.2.8
by Aaron Bentley
Add precedence test |
993 |
def test_config_precedence(self): |
994 |
my_config = self.get_branch_config(global_config=precedence_global) |
|
995 |
self.assertEqual(my_config.get_user_option('option'), 'global') |
|
996 |
my_config = self.get_branch_config(global_config=precedence_global, |
|
997 |
branch_data_config=precedence_branch) |
|
998 |
self.assertEqual(my_config.get_user_option('option'), 'branch') |
|
999 |
my_config = self.get_branch_config(global_config=precedence_global, |
|
1000 |
branch_data_config=precedence_branch, |
|
1001 |
location_config=precedence_location) |
|
1002 |
self.assertEqual(my_config.get_user_option('option'), 'recurse') |
|
1003 |
my_config = self.get_branch_config(global_config=precedence_global, |
|
1004 |
branch_data_config=precedence_branch, |
|
1005 |
location_config=precedence_location, |
|
1006 |
location='http://example.com/specific') |
|
1007 |
self.assertEqual(my_config.get_user_option('option'), 'exact') |
|
1008 |
||
2681.1.8
by Aaron Bentley
Add Thunderbird support to bzr send |
1009 |
def test_get_mail_client(self): |
1010 |
config = self.get_branch_config() |
|
1011 |
client = config.get_mail_client() |
|
2681.1.24
by Aaron Bentley
Handle default mail client by trying xdg-email, falling back to editor |
1012 |
self.assertIsInstance(client, mail_client.DefaultMail) |
1013 |
||
2790.2.2
by Keir Mierle
Change alphabetic ordering into two categories; one for specific clients the other for generic options. |
1014 |
# Specific clients
|
2681.1.21
by Aaron Bentley
Refactor prompt generation to make it testable, test it with unicode |
1015 |
config.set_user_option('mail_client', 'evolution') |
1016 |
client = config.get_mail_client() |
|
1017 |
self.assertIsInstance(client, mail_client.Evolution) |
|
1018 |
||
2681.5.1
by ghigo
Add KMail support to bzr send |
1019 |
config.set_user_option('mail_client', 'kmail') |
1020 |
client = config.get_mail_client() |
|
1021 |
self.assertIsInstance(client, mail_client.KMail) |
|
1022 |
||
2790.2.1
by Keir Mierle
Add Mutt as a supported client email program. Also rearranges various listings |
1023 |
config.set_user_option('mail_client', 'mutt') |
1024 |
client = config.get_mail_client() |
|
1025 |
self.assertIsInstance(client, mail_client.Mutt) |
|
1026 |
||
1027 |
config.set_user_option('mail_client', 'thunderbird') |
|
1028 |
client = config.get_mail_client() |
|
1029 |
self.assertIsInstance(client, mail_client.Thunderbird) |
|
1030 |
||
2790.2.2
by Keir Mierle
Change alphabetic ordering into two categories; one for specific clients the other for generic options. |
1031 |
# Generic options
|
1032 |
config.set_user_option('mail_client', 'default') |
|
1033 |
client = config.get_mail_client() |
|
1034 |
self.assertIsInstance(client, mail_client.DefaultMail) |
|
1035 |
||
1036 |
config.set_user_option('mail_client', 'editor') |
|
1037 |
client = config.get_mail_client() |
|
1038 |
self.assertIsInstance(client, mail_client.Editor) |
|
1039 |
||
1040 |
config.set_user_option('mail_client', 'mapi') |
|
1041 |
client = config.get_mail_client() |
|
1042 |
self.assertIsInstance(client, mail_client.MAPIClient) |
|
1043 |
||
2681.1.23
by Aaron Bentley
Add support for xdg-email |
1044 |
config.set_user_option('mail_client', 'xdg-email') |
1045 |
client = config.get_mail_client() |
|
1046 |
self.assertIsInstance(client, mail_client.XDGEmail) |
|
1047 |
||
2681.1.10
by Aaron Bentley
Clean up handling of unknown mail clients |
1048 |
config.set_user_option('mail_client', 'firebird') |
1049 |
self.assertRaises(errors.UnknownMailClient, config.get_mail_client) |
|
1050 |
||
1185.33.31
by Martin Pool
Make annotate cope better with revisions committed without a valid |
1051 |
|
1052 |
class TestMailAddressExtraction(TestCase): |
|
1053 |
||
1054 |
def test_extract_email_address(self): |
|
1055 |
self.assertEqual('jane@test.com', |
|
1056 |
config.extract_email_address('Jane <jane@test.com>')) |
|
2055.2.2
by John Arbash Meinel
Switch extract_email_address() to use a more specific exception |
1057 |
self.assertRaises(errors.NoEmailInUsername, |
1185.33.31
by Martin Pool
Make annotate cope better with revisions committed without a valid |
1058 |
config.extract_email_address, 'Jane Tester') |
2533.1.1
by James Westby
Fix TreeConfig to return values from sections. |
1059 |
|
2562.1.2
by John Arbash Meinel
Clean up whitespace |
1060 |
|
2533.1.1
by James Westby
Fix TreeConfig to return values from sections. |
1061 |
class TestTreeConfig(TestCaseWithTransport): |
1062 |
||
1063 |
def test_get_value(self): |
|
1064 |
"""Test that retreiving a value from a section is possible"""
|
|
1065 |
branch = self.make_branch('.') |
|
1066 |
tree_config = config.TreeConfig(branch) |
|
1067 |
tree_config.set_option('value', 'key', 'SECTION') |
|
1068 |
tree_config.set_option('value2', 'key2') |
|
1069 |
tree_config.set_option('value3-top', 'key3') |
|
1070 |
tree_config.set_option('value3-section', 'key3', 'SECTION') |
|
1071 |
value = tree_config.get_option('key', 'SECTION') |
|
1072 |
self.assertEqual(value, 'value') |
|
1073 |
value = tree_config.get_option('key2') |
|
1074 |
self.assertEqual(value, 'value2') |
|
1075 |
self.assertEqual(tree_config.get_option('non-existant'), None) |
|
1076 |
value = tree_config.get_option('non-existant', 'SECTION') |
|
1077 |
self.assertEqual(value, None) |
|
1078 |
value = tree_config.get_option('non-existant', default='default') |
|
1079 |
self.assertEqual(value, 'default') |
|
1080 |
self.assertEqual(tree_config.get_option('key2', 'NOSECTION'), None) |
|
1081 |
value = tree_config.get_option('key2', 'NOSECTION', default='default') |
|
1082 |
self.assertEqual(value, 'default') |
|
1083 |
value = tree_config.get_option('key3') |
|
1084 |
self.assertEqual(value, 'value3-top') |
|
1085 |
value = tree_config.get_option('key3', 'SECTION') |
|
1086 |
self.assertEqual(value, 'value3-section') |