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 |
||
2900.1.1
by Vincent Ladeuil
|
214 |
erroneous_config = """[section] # line 1 |
215 |
good=good # line 2
|
|
216 |
[section] # line 3
|
|
217 |
whocares=notme # line 4
|
|
218 |
"""
|
|
219 |
class TestConfigObjErrors(TestCase): |
|
220 |
||
221 |
def test_duplicate_section_name_error_line(self): |
|
222 |
try: |
|
223 |
co = ConfigObj(StringIO(erroneous_config), raise_errors=True) |
|
224 |
except config.configobj.DuplicateError, e: |
|
225 |
self.assertEqual(3, e.line_number) |
|
226 |
else: |
|
227 |
self.fail('Error in config file not detected') |
|
228 |
||
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
229 |
class TestConfig(TestCase): |
230 |
||
231 |
def test_constructs(self): |
|
232 |
config.Config() |
|
233 |
||
234 |
def test_no_default_editor(self): |
|
235 |
self.assertRaises(NotImplementedError, config.Config().get_editor) |
|
236 |
||
237 |
def test_user_email(self): |
|
238 |
my_config = InstrumentedConfig() |
|
239 |
self.assertEqual('robert.collins@example.org', my_config.user_email()) |
|
240 |
self.assertEqual(['_get_user_id'], my_config._calls) |
|
241 |
||
242 |
def test_username(self): |
|
243 |
my_config = InstrumentedConfig() |
|
244 |
self.assertEqual('Robert Collins <robert.collins@example.org>', |
|
245 |
my_config.username()) |
|
246 |
self.assertEqual(['_get_user_id'], my_config._calls) |
|
1442.1.14
by Robert Collins
Create a default signature checking policy of CHECK_IF_POSSIBLE |
247 |
|
248 |
def test_signatures_default(self): |
|
249 |
my_config = config.Config() |
|
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
250 |
self.assertFalse(my_config.signature_needed()) |
1442.1.14
by Robert Collins
Create a default signature checking policy of CHECK_IF_POSSIBLE |
251 |
self.assertEqual(config.CHECK_IF_POSSIBLE, |
252 |
my_config.signature_checking()) |
|
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
253 |
self.assertEqual(config.SIGN_WHEN_REQUIRED, |
254 |
my_config.signing_policy()) |
|
1442.1.14
by Robert Collins
Create a default signature checking policy of CHECK_IF_POSSIBLE |
255 |
|
1442.1.15
by Robert Collins
make getting the signature checking policy a template method |
256 |
def test_signatures_template_method(self): |
257 |
my_config = InstrumentedConfig() |
|
258 |
self.assertEqual(config.CHECK_NEVER, my_config.signature_checking()) |
|
259 |
self.assertEqual(['_get_signature_checking'], my_config._calls) |
|
260 |
||
261 |
def test_signatures_template_method_none(self): |
|
262 |
my_config = InstrumentedConfig() |
|
263 |
my_config._signatures = None |
|
264 |
self.assertEqual(config.CHECK_IF_POSSIBLE, |
|
265 |
my_config.signature_checking()) |
|
266 |
self.assertEqual(['_get_signature_checking'], my_config._calls) |
|
267 |
||
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
268 |
def test_gpg_signing_command_default(self): |
269 |
my_config = config.Config() |
|
270 |
self.assertEqual('gpg', my_config.gpg_signing_command()) |
|
271 |
||
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
272 |
def test_get_user_option_default(self): |
273 |
my_config = config.Config() |
|
274 |
self.assertEqual(None, my_config.get_user_option('no_option')) |
|
275 |
||
1472
by Robert Collins
post commit hook, first pass implementation |
276 |
def test_post_commit_default(self): |
277 |
my_config = config.Config() |
|
278 |
self.assertEqual(None, my_config.post_commit()) |
|
279 |
||
1553.2.9
by Erik Bågfors
log_formatter => log_format for "named" formatters |
280 |
def test_log_format_default(self): |
1553.2.8
by Erik Bågfors
tests for config log_formatter |
281 |
my_config = config.Config() |
1553.2.9
by Erik Bågfors
log_formatter => log_format for "named" formatters |
282 |
self.assertEqual('long', my_config.log_format()) |
1553.2.8
by Erik Bågfors
tests for config log_formatter |
283 |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
284 |
|
1442.1.1
by Robert Collins
move config_dir into bzrlib.config |
285 |
class TestConfigPath(TestCase): |
286 |
||
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
287 |
def setUp(self): |
288 |
super(TestConfigPath, self).setUp() |
|
289 |
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 |
290 |
if sys.platform == 'win32': |
291 |
os.environ['BZR_HOME'] = \ |
|
292 |
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. |
293 |
|
1442.1.1
by Robert Collins
move config_dir into bzrlib.config |
294 |
def test_config_dir(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.config_dir(), |
|
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') |
1185.38.1
by John Arbash Meinel
Adding my win32 patch for moving the home directory. |
298 |
else: |
299 |
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. |
300 |
|
301 |
def test_config_filename(self): |
|
1185.38.1
by John Arbash Meinel
Adding my win32 patch for moving the home directory. |
302 |
if sys.platform == 'win32': |
303 |
self.assertEqual(config.config_filename(), |
|
1185.31.36
by John Arbash Meinel
Fixup test_config.py to handle new paths |
304 |
'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. |
305 |
else: |
306 |
self.assertEqual(config.config_filename(), |
|
307 |
'/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. |
308 |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
309 |
def test_branches_config_filename(self): |
1185.38.1
by John Arbash Meinel
Adding my win32 patch for moving the home directory. |
310 |
if sys.platform == 'win32': |
311 |
self.assertEqual(config.branches_config_filename(), |
|
1185.31.36
by John Arbash Meinel
Fixup test_config.py to handle new paths |
312 |
'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. |
313 |
else: |
314 |
self.assertEqual(config.branches_config_filename(), |
|
315 |
'/home/bogus/.bazaar/branches.conf') |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
316 |
|
1770.2.2
by Aaron Bentley
Rename branches.conf to locations.conf |
317 |
def test_locations_config_filename(self): |
318 |
if sys.platform == 'win32': |
|
319 |
self.assertEqual(config.locations_config_filename(), |
|
320 |
'C:/Documents and Settings/bogus/Application Data/bazaar/2.0/locations.conf') |
|
321 |
else: |
|
322 |
self.assertEqual(config.locations_config_filename(), |
|
323 |
'/home/bogus/.bazaar/locations.conf') |
|
324 |
||
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
325 |
class TestIniConfig(TestCase): |
326 |
||
327 |
def test_contructs(self): |
|
328 |
my_config = config.IniBasedConfig("nothing") |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
329 |
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
330 |
def test_from_fp(self): |
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
331 |
config_file = StringIO(sample_config_text.encode('utf-8')) |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
332 |
my_config = config.IniBasedConfig(None) |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
333 |
self.failUnless( |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
334 |
isinstance(my_config._get_parser(file=config_file), |
1474
by Robert Collins
Merge from Aaron Bentley. |
335 |
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. |
336 |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
337 |
def test_cached(self): |
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
338 |
config_file = StringIO(sample_config_text.encode('utf-8')) |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
339 |
my_config = config.IniBasedConfig(None) |
340 |
parser = my_config._get_parser(file=config_file) |
|
341 |
self.failUnless(my_config._get_parser() is parser) |
|
342 |
||
343 |
||
344 |
class TestGetConfig(TestCase): |
|
345 |
||
346 |
def test_constructs(self): |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
347 |
my_config = config.GlobalConfig() |
348 |
||
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
349 |
def test_calls_read_filenames(self): |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
350 |
# replace the class that is constructured, to check its parameters
|
1474
by Robert Collins
Merge from Aaron Bentley. |
351 |
oldparserclass = config.ConfigObj |
352 |
config.ConfigObj = InstrumentedConfigObj |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
353 |
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. |
354 |
try: |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
355 |
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. |
356 |
finally: |
1474
by Robert Collins
Merge from Aaron Bentley. |
357 |
config.ConfigObj = oldparserclass |
358 |
self.failUnless(isinstance(parser, InstrumentedConfigObj)) |
|
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
359 |
self.assertEqual(parser._calls, [('__init__', config.config_filename(), |
360 |
'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. |
361 |
|
362 |
||
1824.1.1
by Robert Collins
Add BranchConfig.has_explicit_nickname call. |
363 |
class TestBranchConfig(TestCaseWithTransport): |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
364 |
|
365 |
def test_constructs(self): |
|
366 |
branch = FakeBranch() |
|
367 |
my_config = config.BranchConfig(branch) |
|
368 |
self.assertRaises(TypeError, config.BranchConfig) |
|
369 |
||
370 |
def test_get_location_config(self): |
|
371 |
branch = FakeBranch() |
|
372 |
my_config = config.BranchConfig(branch) |
|
373 |
location_config = my_config._get_location_config() |
|
374 |
self.assertEqual(branch.base, location_config.location) |
|
375 |
self.failUnless(location_config is my_config._get_location_config()) |
|
376 |
||
1770.2.9
by Aaron Bentley
Add Branch.get_config, update BranchConfig() callers |
377 |
def test_get_config(self): |
378 |
"""The Branch.get_config method works properly"""
|
|
379 |
b = BzrDir.create_standalone_workingtree('.').branch |
|
380 |
my_config = b.get_config() |
|
381 |
self.assertIs(my_config.get_user_option('wacky'), None) |
|
382 |
my_config.set_user_option('wacky', 'unlikely') |
|
383 |
self.assertEqual(my_config.get_user_option('wacky'), 'unlikely') |
|
384 |
||
385 |
# Ensure we get the same thing if we start again
|
|
386 |
b2 = Branch.open('.') |
|
387 |
my_config2 = b2.get_config() |
|
388 |
self.assertEqual(my_config2.get_user_option('wacky'), 'unlikely') |
|
389 |
||
1824.1.1
by Robert Collins
Add BranchConfig.has_explicit_nickname call. |
390 |
def test_has_explicit_nickname(self): |
391 |
b = self.make_branch('.') |
|
392 |
self.assertFalse(b.get_config().has_explicit_nickname()) |
|
393 |
b.nick = 'foo' |
|
394 |
self.assertTrue(b.get_config().has_explicit_nickname()) |
|
395 |
||
1878.1.1
by John Arbash Meinel
Entries in locations.conf should prefer local paths if available (bug #53653) |
396 |
def test_config_url(self): |
397 |
"""The Branch.get_config will use section that uses a local url"""
|
|
398 |
branch = self.make_branch('branch') |
|
399 |
self.assertEqual('branch', branch.nick) |
|
400 |
||
401 |
locations = config.locations_config_filename() |
|
402 |
config.ensure_config_dir_exists() |
|
403 |
local_url = urlutils.local_path_to_url('branch') |
|
404 |
open(locations, 'wb').write('[%s]\nnickname = foobar' |
|
405 |
% (local_url,)) |
|
406 |
self.assertEqual('foobar', branch.nick) |
|
407 |
||
408 |
def test_config_local_path(self): |
|
409 |
"""The Branch.get_config will use a local system path"""
|
|
410 |
branch = self.make_branch('branch') |
|
411 |
self.assertEqual('branch', branch.nick) |
|
412 |
||
413 |
locations = config.locations_config_filename() |
|
414 |
config.ensure_config_dir_exists() |
|
415 |
open(locations, 'wb').write('[%s/branch]\nnickname = barry' |
|
416 |
% (osutils.getcwd().encode('utf8'),)) |
|
417 |
self.assertEqual('barry', branch.nick) |
|
418 |
||
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 |
419 |
def test_config_creates_local(self): |
420 |
"""Creating a new entry in config uses a local path."""
|
|
2230.3.6
by Aaron Bentley
work in progress bind stuff |
421 |
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 |
422 |
branch.set_push_location('http://foobar') |
423 |
locations = config.locations_config_filename() |
|
424 |
local_path = osutils.getcwd().encode('utf8') |
|
425 |
# Surprisingly ConfigObj doesn't create a trailing newline
|
|
426 |
self.check_file_contents(locations, |
|
2120.6.8
by James Henstridge
Change syntax for setting config option policies. Rather than |
427 |
'[%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 |
428 |
|
2120.5.4
by Alexander Belchenko
Whitebox test for Config.get_nickname (req. by Aaron Bentley) |
429 |
def test_autonick_urlencoded(self): |
430 |
b = self.make_branch('!repo') |
|
431 |
self.assertEqual('!repo', b.get_config().get_nickname()) |
|
432 |
||
1551.15.35
by Aaron Bentley
Warn when setting config values that will be masked (#122286) |
433 |
def test_warn_if_masked(self): |
434 |
_warning = trace.warning |
|
435 |
warnings = [] |
|
436 |
def warning(*args): |
|
437 |
warnings.append(args[0] % args[1:]) |
|
438 |
||
439 |
def set_option(store, warn_masked=True): |
|
440 |
warnings[:] = [] |
|
441 |
conf.set_user_option('example_option', repr(store), store=store, |
|
442 |
warn_masked=warn_masked) |
|
443 |
def assertWarning(warning): |
|
444 |
if warning is None: |
|
445 |
self.assertEqual(0, len(warnings)) |
|
446 |
else: |
|
447 |
self.assertEqual(1, len(warnings)) |
|
448 |
self.assertEqual(warning, warnings[0]) |
|
449 |
trace.warning = warning |
|
450 |
try: |
|
451 |
branch = self.make_branch('.') |
|
452 |
conf = branch.get_config() |
|
453 |
set_option(config.STORE_GLOBAL) |
|
454 |
assertWarning(None) |
|
455 |
set_option(config.STORE_BRANCH) |
|
456 |
assertWarning(None) |
|
457 |
set_option(config.STORE_GLOBAL) |
|
458 |
assertWarning('Value "4" is masked by "3" from branch.conf') |
|
459 |
set_option(config.STORE_GLOBAL, warn_masked=False) |
|
460 |
assertWarning(None) |
|
461 |
set_option(config.STORE_LOCATION) |
|
462 |
assertWarning(None) |
|
463 |
set_option(config.STORE_BRANCH) |
|
464 |
assertWarning('Value "3" is masked by "0" from locations.conf') |
|
465 |
set_option(config.STORE_BRANCH, warn_masked=False) |
|
466 |
assertWarning(None) |
|
467 |
finally: |
|
468 |
trace.warning = _warning |
|
469 |
||
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
470 |
|
1442.1.55
by Robert Collins
move environment preservation up to the root test case, making it available to all tests |
471 |
class TestGlobalConfigItems(TestCase): |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
472 |
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
473 |
def test_user_id(self): |
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
474 |
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 |
475 |
my_config = config.GlobalConfig() |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
476 |
my_config._parser = my_config._get_parser(file=config_file) |
1551.2.21
by Aaron Bentley
Formatted unicode config tests as ASCII |
477 |
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 |
478 |
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. |
479 |
|
480 |
def test_absent_user_id(self): |
|
481 |
config_file = StringIO("") |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
482 |
my_config = config.GlobalConfig() |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
483 |
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 |
484 |
self.assertEqual(None, my_config._get_user_id()) |
485 |
||
486 |
def test_configured_editor(self): |
|
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
487 |
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 |
488 |
my_config = config.GlobalConfig() |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
489 |
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 |
490 |
self.assertEqual("vim", my_config.get_editor()) |
491 |
||
1442.1.17
by Robert Collins
allow global overriding of signature policy to force checking, or (pointless but allowed) to set auto checking |
492 |
def test_signatures_always(self): |
493 |
config_file = StringIO(sample_always_signatures) |
|
494 |
my_config = config.GlobalConfig() |
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
495 |
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 |
496 |
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 |
497 |
my_config.signature_checking()) |
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
498 |
self.assertEqual(config.SIGN_ALWAYS, |
499 |
my_config.signing_policy()) |
|
1442.1.21
by Robert Collins
create signature_needed() call for commit to trigger creating signatures |
500 |
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 |
501 |
|
502 |
def test_signatures_if_possible(self): |
|
503 |
config_file = StringIO(sample_maybe_signatures) |
|
504 |
my_config = config.GlobalConfig() |
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
505 |
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 |
506 |
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 |
507 |
my_config.signature_checking()) |
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
508 |
self.assertEqual(config.SIGN_WHEN_REQUIRED, |
509 |
my_config.signing_policy()) |
|
1442.1.21
by Robert Collins
create signature_needed() call for commit to trigger creating signatures |
510 |
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 |
511 |
|
1442.1.16
by Robert Collins
allow global overriding of signature policy to never check |
512 |
def test_signatures_ignore(self): |
513 |
config_file = StringIO(sample_ignore_signatures) |
|
514 |
my_config = config.GlobalConfig() |
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
515 |
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 |
516 |
self.assertEqual(config.CHECK_ALWAYS, |
1442.1.16
by Robert Collins
allow global overriding of signature policy to never check |
517 |
my_config.signature_checking()) |
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
518 |
self.assertEqual(config.SIGN_NEVER, |
519 |
my_config.signing_policy()) |
|
1442.1.21
by Robert Collins
create signature_needed() call for commit to trigger creating signatures |
520 |
self.assertEqual(False, my_config.signature_needed()) |
1442.1.16
by Robert Collins
allow global overriding of signature policy to never check |
521 |
|
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
522 |
def _get_sample_config(self): |
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
523 |
config_file = StringIO(sample_config_text.encode('utf-8')) |
1534.7.154
by Aaron Bentley
Removed changes from bzr.ab 1529..1536 |
524 |
my_config = config.GlobalConfig() |
525 |
my_config._parser = my_config._get_parser(file=config_file) |
|
526 |
return my_config |
|
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
527 |
|
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
528 |
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. |
529 |
my_config = self._get_sample_config() |
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
530 |
self.assertEqual("gnome-gpg", my_config.gpg_signing_command()) |
531 |
self.assertEqual(False, my_config.signature_needed()) |
|
532 |
||
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
533 |
def _get_empty_config(self): |
534 |
config_file = StringIO("") |
|
535 |
my_config = config.GlobalConfig() |
|
536 |
my_config._parser = my_config._get_parser(file=config_file) |
|
537 |
return my_config |
|
538 |
||
1442.1.59
by Robert Collins
Add re-sign command to generate a digital signature on a single revision. |
539 |
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. |
540 |
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. |
541 |
self.assertEqual("gpg", my_config.gpg_signing_command()) |
542 |
||
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
543 |
def test_get_user_option_default(self): |
544 |
my_config = self._get_empty_config() |
|
545 |
self.assertEqual(None, my_config.get_user_option('no_option')) |
|
546 |
||
547 |
def test_get_user_option_global(self): |
|
548 |
my_config = self._get_sample_config() |
|
549 |
self.assertEqual("something", |
|
550 |
my_config.get_user_option('user_global_option')) |
|
1472
by Robert Collins
post commit hook, first pass implementation |
551 |
|
552 |
def test_post_commit_default(self): |
|
553 |
my_config = self._get_sample_config() |
|
554 |
self.assertEqual(None, my_config.post_commit()) |
|
555 |
||
1553.2.9
by Erik Bågfors
log_formatter => log_format for "named" formatters |
556 |
def test_configured_logformat(self): |
1553.2.8
by Erik Bågfors
tests for config log_formatter |
557 |
my_config = self._get_sample_config() |
1553.2.9
by Erik Bågfors
log_formatter => log_format for "named" formatters |
558 |
self.assertEqual("short", my_config.log_format()) |
1553.2.8
by Erik Bågfors
tests for config log_formatter |
559 |
|
1553.6.12
by Erik Bågfors
remove AliasConfig, based on input from abentley |
560 |
def test_get_alias(self): |
561 |
my_config = self._get_sample_config() |
|
562 |
self.assertEqual('help', my_config.get_alias('h')) |
|
563 |
||
564 |
def test_get_no_alias(self): |
|
565 |
my_config = self._get_sample_config() |
|
566 |
self.assertEqual(None, my_config.get_alias('foo')) |
|
567 |
||
568 |
def test_get_long_alias(self): |
|
569 |
my_config = self._get_sample_config() |
|
570 |
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. |
571 |
|
1704.2.18
by Martin Pool
Remove duplicated TestLocationConfig and update previously hidden tests. (#32587) |
572 |
|
573 |
class TestLocationConfig(TestCaseInTempDir): |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
574 |
|
575 |
def test_constructs(self): |
|
576 |
my_config = config.LocationConfig('http://example.com') |
|
577 |
self.assertRaises(TypeError, config.LocationConfig) |
|
578 |
||
579 |
def test_branch_calls_read_filenames(self): |
|
1474
by Robert Collins
Merge from Aaron Bentley. |
580 |
# This is testing the correct file names are provided.
|
581 |
# TODO: consolidate with the test for GlobalConfigs filename checks.
|
|
582 |
#
|
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
583 |
# replace the class that is constructured, to check its parameters
|
1474
by Robert Collins
Merge from Aaron Bentley. |
584 |
oldparserclass = config.ConfigObj |
585 |
config.ConfigObj = InstrumentedConfigObj |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
586 |
try: |
1770.2.2
by Aaron Bentley
Rename branches.conf to locations.conf |
587 |
my_config = config.LocationConfig('http://www.example.com') |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
588 |
parser = my_config._get_parser() |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
589 |
finally: |
1474
by Robert Collins
Merge from Aaron Bentley. |
590 |
config.ConfigObj = oldparserclass |
591 |
self.failUnless(isinstance(parser, InstrumentedConfigObj)) |
|
592 |
self.assertEqual(parser._calls, |
|
1770.2.2
by Aaron Bentley
Rename branches.conf to locations.conf |
593 |
[('__init__', config.locations_config_filename(), |
1704.2.18
by Martin Pool
Remove duplicated TestLocationConfig and update previously hidden tests. (#32587) |
594 |
'utf-8')]) |
1711.4.29
by John Arbash Meinel
Alexander Belchenko, fix test_config to use ensure_config_dir, rather than os.mkdir() |
595 |
config.ensure_config_dir_exists() |
596 |
#os.mkdir(config.config_dir())
|
|
1770.2.2
by Aaron Bentley
Rename branches.conf to locations.conf |
597 |
f = file(config.branches_config_filename(), 'wb') |
598 |
f.write('') |
|
599 |
f.close() |
|
600 |
oldparserclass = config.ConfigObj |
|
601 |
config.ConfigObj = InstrumentedConfigObj |
|
602 |
try: |
|
603 |
my_config = config.LocationConfig('http://www.example.com') |
|
604 |
parser = my_config._get_parser() |
|
605 |
finally: |
|
606 |
config.ConfigObj = oldparserclass |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
607 |
|
608 |
def test_get_global_config(self): |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
609 |
my_config = config.BranchConfig(FakeBranch('http://example.com')) |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
610 |
global_config = my_config._get_global_config() |
611 |
self.failUnless(isinstance(global_config, config.GlobalConfig)) |
|
612 |
self.failUnless(global_config is my_config._get_global_config()) |
|
613 |
||
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
614 |
def test__get_matching_sections_no_match(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
615 |
self.get_branch_config('/') |
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
616 |
self.assertEqual([], self.my_location_config._get_matching_sections()) |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
617 |
|
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
618 |
def test__get_matching_sections_exact(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
619 |
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 |
620 |
self.assertEqual([('http://www.example.com', '')], |
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
621 |
self.my_location_config._get_matching_sections()) |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
622 |
|
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
623 |
def test__get_matching_sections_suffix_does_not(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
624 |
self.get_branch_config('http://www.example.com-com') |
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
625 |
self.assertEqual([], self.my_location_config._get_matching_sections()) |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
626 |
|
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
627 |
def test__get_matching_sections_subdir_recursive(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
628 |
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 |
629 |
self.assertEqual([('http://www.example.com', 'com')], |
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
630 |
self.my_location_config._get_matching_sections()) |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
631 |
|
1993.3.5
by James Henstridge
add back recurse=False option to config file |
632 |
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 |
633 |
self.get_branch_config('http://www.example.com/ignoreparent') |
634 |
self.assertEqual([('http://www.example.com/ignoreparent', '')], |
|
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
635 |
self.my_location_config._get_matching_sections()) |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
636 |
|
1993.3.5
by James Henstridge
add back recurse=False option to config file |
637 |
def test__get_matching_sections_ignoreparent_subdir(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
638 |
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 |
639 |
'http://www.example.com/ignoreparent/childbranch') |
640 |
self.assertEqual([('http://www.example.com/ignoreparent', 'childbranch')], |
|
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_subdir_trailing_slash(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
644 |
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 |
645 |
self.assertEqual([('/b/', '')], |
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
646 |
self.my_location_config._get_matching_sections()) |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
647 |
|
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
648 |
def test__get_matching_sections_subdir_child(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
649 |
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 |
650 |
self.assertEqual([('/a/*', ''), ('/a/', 'foo')], |
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
651 |
self.my_location_config._get_matching_sections()) |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
652 |
|
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
653 |
def test__get_matching_sections_subdir_child_child(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
654 |
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 |
655 |
self.assertEqual([('/a/*', 'bar'), ('/a/', 'foo/bar')], |
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
656 |
self.my_location_config._get_matching_sections()) |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
657 |
|
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
658 |
def test__get_matching_sections_trailing_slash_with_children(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
659 |
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 |
660 |
self.assertEqual([('/a/', '')], |
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
661 |
self.my_location_config._get_matching_sections()) |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
662 |
|
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
663 |
def test__get_matching_sections_explicit_over_glob(self): |
664 |
# XXX: 2006-09-08 jamesh
|
|
665 |
# This test only passes because ord('c') > ord('*'). If there
|
|
666 |
# was a config section for '/a/?', it would get precedence
|
|
667 |
# over '/a/c'.
|
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
668 |
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 |
669 |
self.assertEqual([('/a/c', ''), ('/a/*', ''), ('/a/', 'c')], |
1993.3.1
by James Henstridge
first go at making location config lookup recursive |
670 |
self.my_location_config._get_matching_sections()) |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
671 |
|
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 |
672 |
def test__get_option_policy_normal(self): |
673 |
self.get_branch_config('http://www.example.com') |
|
674 |
self.assertEqual( |
|
675 |
self.my_location_config._get_config_policy( |
|
676 |
'http://www.example.com', 'normal_option'), |
|
677 |
config.POLICY_NONE) |
|
678 |
||
679 |
def test__get_option_policy_norecurse(self): |
|
680 |
self.get_branch_config('http://www.example.com') |
|
681 |
self.assertEqual( |
|
682 |
self.my_location_config._get_option_policy( |
|
683 |
'http://www.example.com', 'norecurse_option'), |
|
684 |
config.POLICY_NORECURSE) |
|
685 |
# Test old recurse=False setting:
|
|
686 |
self.assertEqual( |
|
687 |
self.my_location_config._get_option_policy( |
|
688 |
'http://www.example.com/norecurse', 'normal_option'), |
|
689 |
config.POLICY_NORECURSE) |
|
690 |
||
691 |
def test__get_option_policy_normal(self): |
|
692 |
self.get_branch_config('http://www.example.com') |
|
693 |
self.assertEqual( |
|
694 |
self.my_location_config._get_option_policy( |
|
695 |
'http://www.example.com', 'appendpath_option'), |
|
696 |
config.POLICY_APPENDPATH) |
|
697 |
||
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
698 |
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 |
699 |
self.get_branch_config('http://www.example.com/ignoreparent') |
1704.2.18
by Martin Pool
Remove duplicated TestLocationConfig and update previously hidden tests. (#32587) |
700 |
self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>', |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
701 |
self.my_config.username()) |
702 |
||
703 |
def test_location_not_listed(self): |
|
1704.2.18
by Martin Pool
Remove duplicated TestLocationConfig and update previously hidden tests. (#32587) |
704 |
"""Test that the global username is used when no location matches"""
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
705 |
self.get_branch_config('/home/robertc/sources') |
1704.2.18
by Martin Pool
Remove duplicated TestLocationConfig and update previously hidden tests. (#32587) |
706 |
self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>', |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
707 |
self.my_config.username()) |
708 |
||
1442.1.13
by Robert Collins
branches.conf is now able to override the users email |
709 |
def test_overriding_location(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
710 |
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 |
711 |
self.assertEqual('Robert Collins <robertc@example.org>', |
712 |
self.my_config.username()) |
|
1442.1.16
by Robert Collins
allow global overriding of signature policy to never check |
713 |
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
714 |
def test_signatures_not_set(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
715 |
self.get_branch_config('http://www.example.com', |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
716 |
global_config=sample_ignore_signatures) |
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
717 |
self.assertEqual(config.CHECK_ALWAYS, |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
718 |
self.my_config.signature_checking()) |
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
719 |
self.assertEqual(config.SIGN_NEVER, |
720 |
self.my_config.signing_policy()) |
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
721 |
|
722 |
def test_signatures_never(self): |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
723 |
self.get_branch_config('/a/c') |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
724 |
self.assertEqual(config.CHECK_NEVER, |
725 |
self.my_config.signature_checking()) |
|
726 |
||
1442.1.16
by Robert Collins
allow global overriding of signature policy to never check |
727 |
def test_signatures_when_available(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
728 |
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 |
729 |
self.assertEqual(config.CHECK_IF_POSSIBLE, |
730 |
self.my_config.signature_checking()) |
|
1442.1.13
by Robert Collins
branches.conf is now able to override the users email |
731 |
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
732 |
def test_signatures_always(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
733 |
self.get_branch_config('/b') |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
734 |
self.assertEqual(config.CHECK_ALWAYS, |
735 |
self.my_config.signature_checking()) |
|
736 |
||
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
737 |
def test_gpg_signing_command(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
738 |
self.get_branch_config('/b') |
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
739 |
self.assertEqual("gnome-gpg", self.my_config.gpg_signing_command()) |
740 |
||
741 |
def test_gpg_signing_command_missing(self): |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
742 |
self.get_branch_config('/a') |
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
743 |
self.assertEqual("false", self.my_config.gpg_signing_command()) |
744 |
||
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
745 |
def test_get_user_option_global(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
746 |
self.get_branch_config('/a') |
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
747 |
self.assertEqual('something', |
748 |
self.my_config.get_user_option('user_global_option')) |
|
749 |
||
750 |
def test_get_user_option_local(self): |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
751 |
self.get_branch_config('/a') |
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
752 |
self.assertEqual('local', |
753 |
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 |
754 |
|
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 |
755 |
def test_get_user_option_appendpath(self): |
756 |
# returned as is for the base path:
|
|
757 |
self.get_branch_config('http://www.example.com') |
|
758 |
self.assertEqual('append', |
|
759 |
self.my_config.get_user_option('appendpath_option')) |
|
760 |
# Extra path components get appended:
|
|
761 |
self.get_branch_config('http://www.example.com/a/b/c') |
|
762 |
self.assertEqual('append/a/b/c', |
|
763 |
self.my_config.get_user_option('appendpath_option')) |
|
764 |
# Overriden for http://www.example.com/dir, where it is a
|
|
765 |
# normal option:
|
|
766 |
self.get_branch_config('http://www.example.com/dir/a/b/c') |
|
767 |
self.assertEqual('normal', |
|
768 |
self.my_config.get_user_option('appendpath_option')) |
|
769 |
||
770 |
def test_get_user_option_norecurse(self): |
|
771 |
self.get_branch_config('http://www.example.com') |
|
772 |
self.assertEqual('norecurse', |
|
773 |
self.my_config.get_user_option('norecurse_option')) |
|
774 |
self.get_branch_config('http://www.example.com/dir') |
|
775 |
self.assertEqual(None, |
|
776 |
self.my_config.get_user_option('norecurse_option')) |
|
777 |
# http://www.example.com/norecurse is a recurse=False section
|
|
778 |
# that redefines normal_option. Subdirectories do not pick up
|
|
779 |
# this redefinition.
|
|
780 |
self.get_branch_config('http://www.example.com/norecurse') |
|
781 |
self.assertEqual('norecurse', |
|
782 |
self.my_config.get_user_option('normal_option')) |
|
783 |
self.get_branch_config('http://www.example.com/norecurse/subdir') |
|
784 |
self.assertEqual('normal', |
|
785 |
self.my_config.get_user_option('normal_option')) |
|
786 |
||
2120.6.4
by James Henstridge
add support for specifying policy when storing options |
787 |
def test_set_user_option_norecurse(self): |
788 |
self.get_branch_config('http://www.example.com') |
|
789 |
self.my_config.set_user_option('foo', 'bar', |
|
790 |
store=config.STORE_LOCATION_NORECURSE) |
|
791 |
self.assertEqual( |
|
792 |
self.my_location_config._get_option_policy( |
|
793 |
'http://www.example.com', 'foo'), |
|
794 |
config.POLICY_NORECURSE) |
|
795 |
||
796 |
def test_set_user_option_appendpath(self): |
|
797 |
self.get_branch_config('http://www.example.com') |
|
798 |
self.my_config.set_user_option('foo', 'bar', |
|
799 |
store=config.STORE_LOCATION_APPENDPATH) |
|
800 |
self.assertEqual( |
|
801 |
self.my_location_config._get_option_policy( |
|
802 |
'http://www.example.com', 'foo'), |
|
803 |
config.POLICY_APPENDPATH) |
|
804 |
||
805 |
def test_set_user_option_change_policy(self): |
|
806 |
self.get_branch_config('http://www.example.com') |
|
807 |
self.my_config.set_user_option('norecurse_option', 'normal', |
|
808 |
store=config.STORE_LOCATION) |
|
809 |
self.assertEqual( |
|
810 |
self.my_location_config._get_option_policy( |
|
811 |
'http://www.example.com', 'norecurse_option'), |
|
812 |
config.POLICY_NONE) |
|
813 |
||
814 |
def test_set_user_option_recurse_false_section(self): |
|
2120.6.9
by James Henstridge
Fixes for issues brought up in John's review |
815 |
# The following section has recurse=False set. The test is to
|
816 |
# make sure that a normal option can be added to the section,
|
|
817 |
# converting recurse=False to the norecurse policy.
|
|
2120.6.4
by James Henstridge
add support for specifying policy when storing options |
818 |
self.get_branch_config('http://www.example.com/norecurse') |
2120.6.11
by James Henstridge
s/0.13/0.14/ in deprecation warning |
819 |
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 |
820 |
'The section "http://www.example.com/norecurse" '
|
821 |
'has been converted to use policies.'], |
|
822 |
self.my_config.set_user_option, |
|
823 |
'foo', 'bar', store=config.STORE_LOCATION) |
|
2120.6.4
by James Henstridge
add support for specifying policy when storing options |
824 |
self.assertEqual( |
825 |
self.my_location_config._get_option_policy( |
|
826 |
'http://www.example.com/norecurse', 'foo'), |
|
827 |
config.POLICY_NONE) |
|
828 |
# The previously existing option is still norecurse:
|
|
829 |
self.assertEqual( |
|
830 |
self.my_location_config._get_option_policy( |
|
831 |
'http://www.example.com/norecurse', 'normal_option'), |
|
832 |
config.POLICY_NORECURSE) |
|
833 |
||
1472
by Robert Collins
post commit hook, first pass implementation |
834 |
def test_post_commit_default(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
835 |
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 |
836 |
self.assertEqual('bzrlib.tests.test_config.post_commit', |
1472
by Robert Collins
post commit hook, first pass implementation |
837 |
self.my_config.post_commit()) |
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
838 |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
839 |
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. |
840 |
if global_config is None: |
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
841 |
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. |
842 |
else: |
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
843 |
global_file = StringIO(global_config.encode('utf-8')) |
844 |
branches_file = StringIO(sample_branches_text.encode('utf-8')) |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
845 |
self.my_config = config.BranchConfig(FakeBranch(location)) |
846 |
# Force location config to use specified file
|
|
847 |
self.my_location_config = self.my_config._get_location_config() |
|
848 |
self.my_location_config._get_parser(branches_file) |
|
849 |
# 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. |
850 |
self.my_config._get_global_config()._get_parser(global_file) |
851 |
||
1490
by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1. |
852 |
def test_set_user_setting_sets_and_saves(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
853 |
self.get_branch_config('/a/c') |
1490
by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1. |
854 |
record = InstrumentedConfigObj("foo") |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
855 |
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 |
856 |
|
857 |
real_mkdir = os.mkdir |
|
858 |
self.created = False |
|
859 |
def checked_mkdir(path, mode=0777): |
|
860 |
self.log('making directory: %s', path) |
|
861 |
real_mkdir(path, mode) |
|
862 |
self.created = True |
|
863 |
||
864 |
os.mkdir = checked_mkdir |
|
865 |
try: |
|
2120.6.10
by James Henstridge
Catch another deprecation warning, and more cleanup |
866 |
self.callDeprecated(['The recurse option is deprecated as of ' |
2120.6.11
by James Henstridge
s/0.13/0.14/ in deprecation warning |
867 |
'0.14. The section "/a/c" has been '
|
2120.6.10
by James Henstridge
Catch another deprecation warning, and more cleanup |
868 |
'converted to use policies.'], |
869 |
self.my_config.set_user_option, |
|
870 |
'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 |
871 |
finally: |
872 |
os.mkdir = real_mkdir |
|
873 |
||
874 |
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. |
875 |
self.assertEqual([('__contains__', '/a/c'), |
876 |
('__contains__', '/a/c/'), |
|
877 |
('__setitem__', '/a/c', {}), |
|
878 |
('__getitem__', '/a/c'), |
|
879 |
('__setitem__', 'foo', 'bar'), |
|
2120.6.4
by James Henstridge
add support for specifying policy when storing options |
880 |
('__getitem__', '/a/c'), |
881 |
('as_bool', 'recurse'), |
|
882 |
('__getitem__', '/a/c'), |
|
883 |
('__delitem__', 'recurse'), |
|
884 |
('__getitem__', '/a/c'), |
|
885 |
('keys',), |
|
2120.6.8
by James Henstridge
Change syntax for setting config option policies. Rather than |
886 |
('__getitem__', '/a/c'), |
887 |
('__contains__', 'foo:policy'), |
|
1490
by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1. |
888 |
('write',)], |
889 |
record._calls[1:]) |
|
890 |
||
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
891 |
def test_set_user_setting_sets_and_saves2(self): |
892 |
self.get_branch_config('/a/c') |
|
893 |
self.assertIs(self.my_config.get_user_option('foo'), None) |
|
894 |
self.my_config.set_user_option('foo', 'bar') |
|
895 |
self.assertEqual( |
|
896 |
self.my_config.branch.control_files.files['branch.conf'], |
|
897 |
'foo = bar') |
|
898 |
self.assertEqual(self.my_config.get_user_option('foo'), 'bar') |
|
2120.6.4
by James Henstridge
add support for specifying policy when storing options |
899 |
self.my_config.set_user_option('foo', 'baz', |
900 |
store=config.STORE_LOCATION) |
|
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
901 |
self.assertEqual(self.my_config.get_user_option('foo'), 'baz') |
902 |
self.my_config.set_user_option('foo', 'qux') |
|
903 |
self.assertEqual(self.my_config.get_user_option('foo'), 'baz') |
|
904 |
||
1551.18.17
by Aaron Bentley
Introduce bzr_remote_path configuration variable |
905 |
def test_get_bzr_remote_path(self): |
906 |
my_config = config.LocationConfig('/a/c') |
|
907 |
self.assertEqual('bzr', my_config.get_bzr_remote_path()) |
|
908 |
my_config.set_user_option('bzr_remote_path', '/path-bzr') |
|
909 |
self.assertEqual('/path-bzr', my_config.get_bzr_remote_path()) |
|
910 |
os.environ['BZR_REMOTE_PATH'] = '/environ-bzr' |
|
911 |
self.assertEqual('/environ-bzr', my_config.get_bzr_remote_path()) |
|
912 |
||
1185.62.7
by John Arbash Meinel
Whitespace cleanup. |
913 |
|
1770.2.8
by Aaron Bentley
Add precedence test |
914 |
precedence_global = 'option = global' |
915 |
precedence_branch = 'option = branch' |
|
916 |
precedence_location = """ |
|
917 |
[http://]
|
|
918 |
recurse = true
|
|
919 |
option = recurse
|
|
920 |
[http://example.com/specific]
|
|
921 |
option = exact
|
|
922 |
"""
|
|
923 |
||
924 |
||
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
925 |
class TestBranchConfigItems(TestCaseInTempDir): |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
926 |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
927 |
def get_branch_config(self, global_config=None, location=None, |
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
928 |
location_config=None, branch_data_config=None): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
929 |
my_config = config.BranchConfig(FakeBranch(location)) |
930 |
if global_config is not None: |
|
931 |
global_file = StringIO(global_config.encode('utf-8')) |
|
932 |
my_config._get_global_config()._get_parser(global_file) |
|
933 |
self.my_location_config = my_config._get_location_config() |
|
934 |
if location_config is not None: |
|
935 |
location_file = StringIO(location_config.encode('utf-8')) |
|
936 |
self.my_location_config._get_parser(location_file) |
|
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
937 |
if branch_data_config is not None: |
938 |
my_config.branch.control_files.files['branch.conf'] = \ |
|
939 |
branch_data_config
|
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
940 |
return my_config |
941 |
||
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
942 |
def test_user_id(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
943 |
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 |
944 |
my_config = config.BranchConfig(branch) |
945 |
self.assertEqual("Robert Collins <robertc@example.net>", |
|
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
946 |
my_config.username()) |
1185.65.11
by Robert Collins
Disable inheritance for getting at LockableFiles, rather use composition. |
947 |
branch.control_files.email = "John" |
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
948 |
my_config.set_user_option('email', |
949 |
"Robert Collins <robertc@example.org>") |
|
950 |
self.assertEqual("John", my_config.username()) |
|
951 |
branch.control_files.email = None |
|
952 |
self.assertEqual("Robert Collins <robertc@example.org>", |
|
953 |
my_config.username()) |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
954 |
|
955 |
def test_not_set_in_branch(self): |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
956 |
my_config = self.get_branch_config(sample_config_text) |
957 |
my_config.branch.control_files.email = None |
|
1551.2.21
by Aaron Bentley
Formatted unicode config tests as ASCII |
958 |
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 |
959 |
my_config._get_user_id()) |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
960 |
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 |
961 |
self.assertEqual("John", my_config._get_user_id()) |
962 |
||
1861.4.1
by Matthieu Moy
BZREMAIL renamed to BZR_EMAIL. |
963 |
def test_BZR_EMAIL_OVERRIDES(self): |
964 |
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 |
965 |
branch = FakeBranch() |
966 |
my_config = config.BranchConfig(branch) |
|
967 |
self.assertEqual("Robert Collins <robertc@example.org>", |
|
968 |
my_config.username()) |
|
969 |
||
1442.1.19
by Robert Collins
BranchConfigs inherit signature_checking policy from their LocationConfig. |
970 |
def test_signatures_forced(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
971 |
my_config = self.get_branch_config( |
972 |
global_config=sample_always_signatures) |
|
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
973 |
self.assertEqual(config.CHECK_NEVER, my_config.signature_checking()) |
974 |
self.assertEqual(config.SIGN_ALWAYS, my_config.signing_policy()) |
|
975 |
self.assertTrue(my_config.signature_needed()) |
|
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
976 |
|
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
977 |
def test_signatures_forced_branch(self): |
978 |
my_config = self.get_branch_config( |
|
979 |
global_config=sample_ignore_signatures, |
|
980 |
branch_data_config=sample_always_signatures) |
|
981 |
self.assertEqual(config.CHECK_NEVER, my_config.signature_checking()) |
|
982 |
self.assertEqual(config.SIGN_ALWAYS, my_config.signing_policy()) |
|
983 |
self.assertTrue(my_config.signature_needed()) |
|
984 |
||
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
985 |
def test_gpg_signing_command(self): |
1770.2.10
by Aaron Bentley
Added test that branch_config can't influence gpg_signing_command |
986 |
my_config = self.get_branch_config( |
987 |
# branch data cannot set gpg_signing_command
|
|
988 |
branch_data_config="gpg_signing_command=pgp") |
|
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
989 |
config_file = StringIO(sample_config_text.encode('utf-8')) |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
990 |
my_config._get_global_config()._get_parser(config_file) |
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
991 |
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. |
992 |
|
993 |
def test_get_user_option_global(self): |
|
994 |
branch = FakeBranch() |
|
995 |
my_config = config.BranchConfig(branch) |
|
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
996 |
config_file = StringIO(sample_config_text.encode('utf-8')) |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
997 |
(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. |
998 |
self.assertEqual('something', |
999 |
my_config.get_user_option('user_global_option')) |
|
1472
by Robert Collins
post commit hook, first pass implementation |
1000 |
|
1001 |
def test_post_commit_default(self): |
|
1002 |
branch = FakeBranch() |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
1003 |
my_config = self.get_branch_config(sample_config_text, '/a/c', |
1004 |
sample_branches_text) |
|
1005 |
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 |
1006 |
self.assertEqual('bzrlib.tests.test_config.post_commit', |
1472
by Robert Collins
post commit hook, first pass implementation |
1007 |
my_config.post_commit()) |
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
1008 |
my_config.set_user_option('post_commit', 'rmtree_root') |
1009 |
# post-commit is ignored when bresent in branch data
|
|
1010 |
self.assertEqual('bzrlib.tests.test_config.post_commit', |
|
1011 |
my_config.post_commit()) |
|
2120.6.4
by James Henstridge
add support for specifying policy when storing options |
1012 |
my_config.set_user_option('post_commit', 'rmtree_root', |
1013 |
store=config.STORE_LOCATION) |
|
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
1014 |
self.assertEqual('rmtree_root', my_config.post_commit()) |
1185.33.31
by Martin Pool
Make annotate cope better with revisions committed without a valid |
1015 |
|
1770.2.8
by Aaron Bentley
Add precedence test |
1016 |
def test_config_precedence(self): |
1017 |
my_config = self.get_branch_config(global_config=precedence_global) |
|
1018 |
self.assertEqual(my_config.get_user_option('option'), 'global') |
|
1019 |
my_config = self.get_branch_config(global_config=precedence_global, |
|
1020 |
branch_data_config=precedence_branch) |
|
1021 |
self.assertEqual(my_config.get_user_option('option'), 'branch') |
|
1022 |
my_config = self.get_branch_config(global_config=precedence_global, |
|
1023 |
branch_data_config=precedence_branch, |
|
1024 |
location_config=precedence_location) |
|
1025 |
self.assertEqual(my_config.get_user_option('option'), 'recurse') |
|
1026 |
my_config = self.get_branch_config(global_config=precedence_global, |
|
1027 |
branch_data_config=precedence_branch, |
|
1028 |
location_config=precedence_location, |
|
1029 |
location='http://example.com/specific') |
|
1030 |
self.assertEqual(my_config.get_user_option('option'), 'exact') |
|
1031 |
||
2681.1.8
by Aaron Bentley
Add Thunderbird support to bzr send |
1032 |
def test_get_mail_client(self): |
1033 |
config = self.get_branch_config() |
|
1034 |
client = config.get_mail_client() |
|
2681.1.24
by Aaron Bentley
Handle default mail client by trying xdg-email, falling back to editor |
1035 |
self.assertIsInstance(client, mail_client.DefaultMail) |
1036 |
||
2790.2.2
by Keir Mierle
Change alphabetic ordering into two categories; one for specific clients the other for generic options. |
1037 |
# Specific clients
|
2681.1.21
by Aaron Bentley
Refactor prompt generation to make it testable, test it with unicode |
1038 |
config.set_user_option('mail_client', 'evolution') |
1039 |
client = config.get_mail_client() |
|
1040 |
self.assertIsInstance(client, mail_client.Evolution) |
|
1041 |
||
2681.5.1
by ghigo
Add KMail support to bzr send |
1042 |
config.set_user_option('mail_client', 'kmail') |
1043 |
client = config.get_mail_client() |
|
1044 |
self.assertIsInstance(client, mail_client.KMail) |
|
1045 |
||
2790.2.1
by Keir Mierle
Add Mutt as a supported client email program. Also rearranges various listings |
1046 |
config.set_user_option('mail_client', 'mutt') |
1047 |
client = config.get_mail_client() |
|
1048 |
self.assertIsInstance(client, mail_client.Mutt) |
|
1049 |
||
1050 |
config.set_user_option('mail_client', 'thunderbird') |
|
1051 |
client = config.get_mail_client() |
|
1052 |
self.assertIsInstance(client, mail_client.Thunderbird) |
|
1053 |
||
2790.2.2
by Keir Mierle
Change alphabetic ordering into two categories; one for specific clients the other for generic options. |
1054 |
# Generic options
|
1055 |
config.set_user_option('mail_client', 'default') |
|
1056 |
client = config.get_mail_client() |
|
1057 |
self.assertIsInstance(client, mail_client.DefaultMail) |
|
1058 |
||
1059 |
config.set_user_option('mail_client', 'editor') |
|
1060 |
client = config.get_mail_client() |
|
1061 |
self.assertIsInstance(client, mail_client.Editor) |
|
1062 |
||
1063 |
config.set_user_option('mail_client', 'mapi') |
|
1064 |
client = config.get_mail_client() |
|
1065 |
self.assertIsInstance(client, mail_client.MAPIClient) |
|
1066 |
||
2681.1.23
by Aaron Bentley
Add support for xdg-email |
1067 |
config.set_user_option('mail_client', 'xdg-email') |
1068 |
client = config.get_mail_client() |
|
1069 |
self.assertIsInstance(client, mail_client.XDGEmail) |
|
1070 |
||
2681.1.10
by Aaron Bentley
Clean up handling of unknown mail clients |
1071 |
config.set_user_option('mail_client', 'firebird') |
1072 |
self.assertRaises(errors.UnknownMailClient, config.get_mail_client) |
|
1073 |
||
1185.33.31
by Martin Pool
Make annotate cope better with revisions committed without a valid |
1074 |
|
1075 |
class TestMailAddressExtraction(TestCase): |
|
1076 |
||
1077 |
def test_extract_email_address(self): |
|
1078 |
self.assertEqual('jane@test.com', |
|
1079 |
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 |
1080 |
self.assertRaises(errors.NoEmailInUsername, |
1185.33.31
by Martin Pool
Make annotate cope better with revisions committed without a valid |
1081 |
config.extract_email_address, 'Jane Tester') |
2533.1.1
by James Westby
Fix TreeConfig to return values from sections. |
1082 |
|
2562.1.2
by John Arbash Meinel
Clean up whitespace |
1083 |
|
2533.1.1
by James Westby
Fix TreeConfig to return values from sections. |
1084 |
class TestTreeConfig(TestCaseWithTransport): |
1085 |
||
1086 |
def test_get_value(self): |
|
1087 |
"""Test that retreiving a value from a section is possible"""
|
|
1088 |
branch = self.make_branch('.') |
|
1089 |
tree_config = config.TreeConfig(branch) |
|
1090 |
tree_config.set_option('value', 'key', 'SECTION') |
|
1091 |
tree_config.set_option('value2', 'key2') |
|
1092 |
tree_config.set_option('value3-top', 'key3') |
|
1093 |
tree_config.set_option('value3-section', 'key3', 'SECTION') |
|
1094 |
value = tree_config.get_option('key', 'SECTION') |
|
1095 |
self.assertEqual(value, 'value') |
|
1096 |
value = tree_config.get_option('key2') |
|
1097 |
self.assertEqual(value, 'value2') |
|
1098 |
self.assertEqual(tree_config.get_option('non-existant'), None) |
|
1099 |
value = tree_config.get_option('non-existant', 'SECTION') |
|
1100 |
self.assertEqual(value, None) |
|
1101 |
value = tree_config.get_option('non-existant', default='default') |
|
1102 |
self.assertEqual(value, 'default') |
|
1103 |
self.assertEqual(tree_config.get_option('key2', 'NOSECTION'), None) |
|
1104 |
value = tree_config.get_option('key2', 'NOSECTION', default='default') |
|
1105 |
self.assertEqual(value, 'default') |
|
1106 |
value = tree_config.get_option('key3') |
|
1107 |
self.assertEqual(value, 'value3-top') |
|
1108 |
value = tree_config.get_option('key3', 'SECTION') |
|
1109 |
self.assertEqual(value, 'value3-section') |