1704.2.18
by Martin Pool
Remove duplicated TestLocationConfig and update previously hidden tests. (#32587) |
1 |
# Copyright (C) 2005, 2006 by 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
|
|
26 |
import bzrlib.config as config |
|
1770.2.9
by Aaron Bentley
Add Branch.get_config, update BranchConfig() callers |
27 |
from bzrlib.branch import Branch |
28 |
from bzrlib.bzrdir import BzrDir |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
29 |
import bzrlib.errors as errors |
1185.31.25
by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py |
30 |
from bzrlib.tests import TestCase, TestCaseInTempDir |
1442.1.1
by Robert Collins
move config_dir into bzrlib.config |
31 |
|
32 |
||
1553.6.12
by Erik Bågfors
remove AliasConfig, based on input from abentley |
33 |
sample_long_alias="log -r-15..-1 --line" |
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
34 |
sample_config_text = ("[DEFAULT]\n" |
1551.2.21
by Aaron Bentley
Formatted unicode config tests as ASCII |
35 |
u"email=Erik B\u00e5gfors <erik@bagfors.nu>\n" |
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
36 |
"editor=vim\n" |
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
37 |
"gpg_signing_command=gnome-gpg\n" |
1553.2.9
by Erik Bågfors
log_formatter => log_format for "named" formatters |
38 |
"log_format=short\n" |
1553.6.12
by Erik Bågfors
remove AliasConfig, based on input from abentley |
39 |
"user_global_option=something\n" |
40 |
"[ALIASES]\n" |
|
41 |
"h=help\n" |
|
42 |
"ll=" + sample_long_alias + "\n") |
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
43 |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
44 |
|
1442.1.17
by Robert Collins
allow global overriding of signature policy to force checking, or (pointless but allowed) to set auto checking |
45 |
sample_always_signatures = ("[DEFAULT]\n" |
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
46 |
"check_signatures=ignore\n" |
47 |
"create_signatures=always") |
|
1442.1.17
by Robert Collins
allow global overriding of signature policy to force checking, or (pointless but allowed) to set auto checking |
48 |
|
49 |
||
1442.1.16
by Robert Collins
allow global overriding of signature policy to never check |
50 |
sample_ignore_signatures = ("[DEFAULT]\n" |
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
51 |
"check_signatures=require\n" |
52 |
"create_signatures=never") |
|
1442.1.16
by Robert Collins
allow global overriding of signature policy to never check |
53 |
|
54 |
||
1442.1.17
by Robert Collins
allow global overriding of signature policy to force checking, or (pointless but allowed) to set auto checking |
55 |
sample_maybe_signatures = ("[DEFAULT]\n" |
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
56 |
"check_signatures=ignore\n" |
57 |
"create_signatures=when-required") |
|
1442.1.17
by Robert Collins
allow global overriding of signature policy to force checking, or (pointless but allowed) to set auto checking |
58 |
|
59 |
||
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
60 |
sample_branches_text = ("[http://www.example.com]\n" |
61 |
"# Top level policy\n" |
|
62 |
"email=Robert Collins <robertc@example.org>\n" |
|
63 |
"[http://www.example.com/useglobal]\n" |
|
64 |
"# different project, forces global lookup\n" |
|
65 |
"recurse=false\n" |
|
66 |
"[/b/]\n" |
|
1442.1.21
by Robert Collins
create signature_needed() call for commit to trigger creating signatures |
67 |
"check_signatures=require\n" |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
68 |
"# test trailing / matching with no children\n" |
69 |
"[/a/]\n" |
|
1442.1.21
by Robert Collins
create signature_needed() call for commit to trigger creating signatures |
70 |
"check_signatures=check-available\n" |
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
71 |
"gpg_signing_command=false\n" |
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
72 |
"user_local_option=local\n" |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
73 |
"# test trailing / matching\n" |
74 |
"[/a/*]\n" |
|
75 |
"#subdirs will match but not the parent\n" |
|
76 |
"recurse=False\n" |
|
77 |
"[/a/c]\n" |
|
1442.1.21
by Robert Collins
create signature_needed() call for commit to trigger creating signatures |
78 |
"check_signatures=ignore\n" |
1185.31.25
by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py |
79 |
"post_commit=bzrlib.tests.test_config.post_commit\n" |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
80 |
"#testing explicit beats globs\n") |
81 |
||
1553.6.3
by Erik Bågfors
tests for AliasesConfig |
82 |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
83 |
|
1474
by Robert Collins
Merge from Aaron Bentley. |
84 |
class InstrumentedConfigObj(object): |
85 |
"""A config obj look-enough-alike to record calls made to it."""
|
|
86 |
||
1490
by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1. |
87 |
def __contains__(self, thing): |
88 |
self._calls.append(('__contains__', thing)) |
|
89 |
return False |
|
90 |
||
91 |
def __getitem__(self, key): |
|
92 |
self._calls.append(('__getitem__', key)) |
|
93 |
return self |
|
94 |
||
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
95 |
def __init__(self, input, encoding=None): |
96 |
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. |
97 |
|
1490
by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1. |
98 |
def __setitem__(self, key, value): |
99 |
self._calls.append(('__setitem__', key, value)) |
|
100 |
||
1551.2.49
by abentley
Made ConfigObj output binary-identical files on win32 and *nix |
101 |
def write(self, arg): |
1490
by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1. |
102 |
self._calls.append(('write',)) |
103 |
||
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
104 |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
105 |
class FakeBranch(object): |
106 |
||
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
107 |
def __init__(self, base=None, user_id=None): |
108 |
if base is None: |
|
109 |
self.base = "http://example.com/branches/demo" |
|
110 |
else: |
|
111 |
self.base = base |
|
112 |
self.control_files = FakeControlFiles(user_id=user_id) |
|
113 |
||
114 |
def lock_write(self): |
|
115 |
pass
|
|
116 |
||
117 |
def unlock(self): |
|
118 |
pass
|
|
1185.65.11
by Robert Collins
Disable inheritance for getting at LockableFiles, rather use composition. |
119 |
|
120 |
||
121 |
class FakeControlFiles(object): |
|
122 |
||
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
123 |
def __init__(self, user_id=None): |
124 |
self.email = user_id |
|
125 |
self.files = {} |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
126 |
|
1185.65.29
by Robert Collins
Implement final review suggestions. |
127 |
def get_utf8(self, filename): |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
128 |
if filename != 'email': |
129 |
raise NotImplementedError |
|
130 |
if self.email is not None: |
|
131 |
return StringIO(self.email) |
|
1185.31.45
by John Arbash Meinel
Refactoring Exceptions found some places where the wrong exception was caught. |
132 |
raise errors.NoSuchFile(filename) |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
133 |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
134 |
def get(self, filename): |
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
135 |
try: |
136 |
return StringIO(self.files[filename]) |
|
137 |
except KeyError: |
|
138 |
raise errors.NoSuchFile(filename) |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
139 |
|
140 |
def put(self, filename, fileobj): |
|
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
141 |
self.files[filename] = fileobj.read() |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
142 |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
143 |
|
144 |
class InstrumentedConfig(config.Config): |
|
145 |
"""An instrumented config that supplies stubs for template methods."""
|
|
146 |
||
147 |
def __init__(self): |
|
148 |
super(InstrumentedConfig, self).__init__() |
|
149 |
self._calls = [] |
|
1442.1.15
by Robert Collins
make getting the signature checking policy a template method |
150 |
self._signatures = config.CHECK_NEVER |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
151 |
|
152 |
def _get_user_id(self): |
|
153 |
self._calls.append('_get_user_id') |
|
154 |
return "Robert Collins <robert.collins@example.org>" |
|
155 |
||
1442.1.15
by Robert Collins
make getting the signature checking policy a template method |
156 |
def _get_signature_checking(self): |
157 |
self._calls.append('_get_signature_checking') |
|
158 |
return self._signatures |
|
159 |
||
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
160 |
|
1556.2.2
by Aaron Bentley
Fixed get_bool |
161 |
bool_config = """[DEFAULT] |
162 |
active = true
|
|
163 |
inactive = false
|
|
164 |
[UPPERCASE]
|
|
165 |
active = True
|
|
166 |
nonactive = False
|
|
167 |
"""
|
|
168 |
class TestConfigObj(TestCase): |
|
169 |
def test_get_bool(self): |
|
170 |
from bzrlib.config import ConfigObj |
|
171 |
co = ConfigObj(StringIO(bool_config)) |
|
172 |
self.assertIs(co.get_bool('DEFAULT', 'active'), True) |
|
173 |
self.assertIs(co.get_bool('DEFAULT', 'inactive'), False) |
|
174 |
self.assertIs(co.get_bool('UPPERCASE', 'active'), True) |
|
175 |
self.assertIs(co.get_bool('UPPERCASE', 'nonactive'), False) |
|
176 |
||
177 |
||
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
178 |
class TestConfig(TestCase): |
179 |
||
180 |
def test_constructs(self): |
|
181 |
config.Config() |
|
182 |
||
183 |
def test_no_default_editor(self): |
|
184 |
self.assertRaises(NotImplementedError, config.Config().get_editor) |
|
185 |
||
186 |
def test_user_email(self): |
|
187 |
my_config = InstrumentedConfig() |
|
188 |
self.assertEqual('robert.collins@example.org', my_config.user_email()) |
|
189 |
self.assertEqual(['_get_user_id'], my_config._calls) |
|
190 |
||
191 |
def test_username(self): |
|
192 |
my_config = InstrumentedConfig() |
|
193 |
self.assertEqual('Robert Collins <robert.collins@example.org>', |
|
194 |
my_config.username()) |
|
195 |
self.assertEqual(['_get_user_id'], my_config._calls) |
|
1442.1.14
by Robert Collins
Create a default signature checking policy of CHECK_IF_POSSIBLE |
196 |
|
197 |
def test_signatures_default(self): |
|
198 |
my_config = config.Config() |
|
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
199 |
self.assertFalse(my_config.signature_needed()) |
1442.1.14
by Robert Collins
Create a default signature checking policy of CHECK_IF_POSSIBLE |
200 |
self.assertEqual(config.CHECK_IF_POSSIBLE, |
201 |
my_config.signature_checking()) |
|
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
202 |
self.assertEqual(config.SIGN_WHEN_REQUIRED, |
203 |
my_config.signing_policy()) |
|
1442.1.14
by Robert Collins
Create a default signature checking policy of CHECK_IF_POSSIBLE |
204 |
|
1442.1.15
by Robert Collins
make getting the signature checking policy a template method |
205 |
def test_signatures_template_method(self): |
206 |
my_config = InstrumentedConfig() |
|
207 |
self.assertEqual(config.CHECK_NEVER, my_config.signature_checking()) |
|
208 |
self.assertEqual(['_get_signature_checking'], my_config._calls) |
|
209 |
||
210 |
def test_signatures_template_method_none(self): |
|
211 |
my_config = InstrumentedConfig() |
|
212 |
my_config._signatures = None |
|
213 |
self.assertEqual(config.CHECK_IF_POSSIBLE, |
|
214 |
my_config.signature_checking()) |
|
215 |
self.assertEqual(['_get_signature_checking'], my_config._calls) |
|
216 |
||
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
217 |
def test_gpg_signing_command_default(self): |
218 |
my_config = config.Config() |
|
219 |
self.assertEqual('gpg', my_config.gpg_signing_command()) |
|
220 |
||
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
221 |
def test_get_user_option_default(self): |
222 |
my_config = config.Config() |
|
223 |
self.assertEqual(None, my_config.get_user_option('no_option')) |
|
224 |
||
1472
by Robert Collins
post commit hook, first pass implementation |
225 |
def test_post_commit_default(self): |
226 |
my_config = config.Config() |
|
227 |
self.assertEqual(None, my_config.post_commit()) |
|
228 |
||
1553.2.9
by Erik Bågfors
log_formatter => log_format for "named" formatters |
229 |
def test_log_format_default(self): |
1553.2.8
by Erik Bågfors
tests for config log_formatter |
230 |
my_config = config.Config() |
1553.2.9
by Erik Bågfors
log_formatter => log_format for "named" formatters |
231 |
self.assertEqual('long', my_config.log_format()) |
1553.2.8
by Erik Bågfors
tests for config log_formatter |
232 |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
233 |
|
1442.1.1
by Robert Collins
move config_dir into bzrlib.config |
234 |
class TestConfigPath(TestCase): |
235 |
||
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
236 |
def setUp(self): |
237 |
super(TestConfigPath, self).setUp() |
|
1185.38.5
by John Arbash Meinel
Updating testconfig to handle missing environment variables |
238 |
self.old_home = os.environ.get('HOME', None) |
239 |
self.old_appdata = os.environ.get('APPDATA', None) |
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
240 |
os.environ['HOME'] = '/home/bogus' |
1185.38.1
by John Arbash Meinel
Adding my win32 patch for moving the home directory. |
241 |
os.environ['APPDATA'] = \ |
242 |
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. |
243 |
|
244 |
def tearDown(self): |
|
1185.38.5
by John Arbash Meinel
Updating testconfig to handle missing environment variables |
245 |
if self.old_home is None: |
246 |
del os.environ['HOME'] |
|
247 |
else: |
|
248 |
os.environ['HOME'] = self.old_home |
|
249 |
if self.old_appdata is None: |
|
250 |
del os.environ['APPDATA'] |
|
251 |
else: |
|
252 |
os.environ['APPDATA'] = self.old_appdata |
|
1442.1.55
by Robert Collins
move environment preservation up to the root test case, making it available to all tests |
253 |
super(TestConfigPath, self).tearDown() |
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
254 |
|
1442.1.1
by Robert Collins
move config_dir into bzrlib.config |
255 |
def test_config_dir(self): |
1185.38.1
by John Arbash Meinel
Adding my win32 patch for moving the home directory. |
256 |
if sys.platform == 'win32': |
257 |
self.assertEqual(config.config_dir(), |
|
1185.31.36
by John Arbash Meinel
Fixup test_config.py to handle new paths |
258 |
'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. |
259 |
else: |
260 |
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. |
261 |
|
262 |
def test_config_filename(self): |
|
1185.38.1
by John Arbash Meinel
Adding my win32 patch for moving the home directory. |
263 |
if sys.platform == 'win32': |
264 |
self.assertEqual(config.config_filename(), |
|
1185.31.36
by John Arbash Meinel
Fixup test_config.py to handle new paths |
265 |
'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. |
266 |
else: |
267 |
self.assertEqual(config.config_filename(), |
|
268 |
'/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. |
269 |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
270 |
def test_branches_config_filename(self): |
1185.38.1
by John Arbash Meinel
Adding my win32 patch for moving the home directory. |
271 |
if sys.platform == 'win32': |
272 |
self.assertEqual(config.branches_config_filename(), |
|
1185.31.36
by John Arbash Meinel
Fixup test_config.py to handle new paths |
273 |
'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. |
274 |
else: |
275 |
self.assertEqual(config.branches_config_filename(), |
|
276 |
'/home/bogus/.bazaar/branches.conf') |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
277 |
|
1770.2.2
by Aaron Bentley
Rename branches.conf to locations.conf |
278 |
def test_locations_config_filename(self): |
279 |
if sys.platform == 'win32': |
|
280 |
self.assertEqual(config.locations_config_filename(), |
|
281 |
'C:/Documents and Settings/bogus/Application Data/bazaar/2.0/locations.conf') |
|
282 |
else: |
|
283 |
self.assertEqual(config.locations_config_filename(), |
|
284 |
'/home/bogus/.bazaar/locations.conf') |
|
285 |
||
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
286 |
class TestIniConfig(TestCase): |
287 |
||
288 |
def test_contructs(self): |
|
289 |
my_config = config.IniBasedConfig("nothing") |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
290 |
|
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
291 |
def test_from_fp(self): |
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
292 |
config_file = StringIO(sample_config_text.encode('utf-8')) |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
293 |
my_config = config.IniBasedConfig(None) |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
294 |
self.failUnless( |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
295 |
isinstance(my_config._get_parser(file=config_file), |
1474
by Robert Collins
Merge from Aaron Bentley. |
296 |
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. |
297 |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
298 |
def test_cached(self): |
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
299 |
config_file = StringIO(sample_config_text.encode('utf-8')) |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
300 |
my_config = config.IniBasedConfig(None) |
301 |
parser = my_config._get_parser(file=config_file) |
|
302 |
self.failUnless(my_config._get_parser() is parser) |
|
303 |
||
304 |
||
305 |
class TestGetConfig(TestCase): |
|
306 |
||
307 |
def test_constructs(self): |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
308 |
my_config = config.GlobalConfig() |
309 |
||
1442.1.2
by Robert Collins
create a config module - there is enough config logic to make this worthwhile, and start testing config processing. |
310 |
def test_calls_read_filenames(self): |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
311 |
# replace the class that is constructured, to check its parameters
|
1474
by Robert Collins
Merge from Aaron Bentley. |
312 |
oldparserclass = config.ConfigObj |
313 |
config.ConfigObj = InstrumentedConfigObj |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
314 |
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. |
315 |
try: |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
316 |
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. |
317 |
finally: |
1474
by Robert Collins
Merge from Aaron Bentley. |
318 |
config.ConfigObj = oldparserclass |
319 |
self.failUnless(isinstance(parser, InstrumentedConfigObj)) |
|
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
320 |
self.assertEqual(parser._calls, [('__init__', config.config_filename(), |
321 |
'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. |
322 |
|
323 |
||
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
324 |
class TestBranchConfig(TestCaseInTempDir): |
325 |
||
326 |
def test_constructs(self): |
|
327 |
branch = FakeBranch() |
|
328 |
my_config = config.BranchConfig(branch) |
|
329 |
self.assertRaises(TypeError, config.BranchConfig) |
|
330 |
||
331 |
def test_get_location_config(self): |
|
332 |
branch = FakeBranch() |
|
333 |
my_config = config.BranchConfig(branch) |
|
334 |
location_config = my_config._get_location_config() |
|
335 |
self.assertEqual(branch.base, location_config.location) |
|
336 |
self.failUnless(location_config is my_config._get_location_config()) |
|
337 |
||
1770.2.9
by Aaron Bentley
Add Branch.get_config, update BranchConfig() callers |
338 |
def test_get_config(self): |
339 |
"""The Branch.get_config method works properly"""
|
|
340 |
b = BzrDir.create_standalone_workingtree('.').branch |
|
341 |
my_config = b.get_config() |
|
342 |
self.assertIs(my_config.get_user_option('wacky'), None) |
|
343 |
my_config.set_user_option('wacky', 'unlikely') |
|
344 |
self.assertEqual(my_config.get_user_option('wacky'), 'unlikely') |
|
345 |
||
346 |
# Ensure we get the same thing if we start again
|
|
347 |
b2 = Branch.open('.') |
|
348 |
my_config2 = b2.get_config() |
|
349 |
self.assertEqual(my_config2.get_user_option('wacky'), 'unlikely') |
|
350 |
||
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
351 |
|
1442.1.55
by Robert Collins
move environment preservation up to the root test case, making it available to all tests |
352 |
class TestGlobalConfigItems(TestCase): |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
353 |
|
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 |
def test_user_id(self): |
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
355 |
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 |
356 |
my_config = config.GlobalConfig() |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
357 |
my_config._parser = my_config._get_parser(file=config_file) |
1551.2.21
by Aaron Bentley
Formatted unicode config tests as ASCII |
358 |
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 |
359 |
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. |
360 |
|
361 |
def test_absent_user_id(self): |
|
362 |
config_file = StringIO("") |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
363 |
my_config = config.GlobalConfig() |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
364 |
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 |
365 |
self.assertEqual(None, my_config._get_user_id()) |
366 |
||
367 |
def test_configured_editor(self): |
|
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
368 |
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 |
369 |
my_config = config.GlobalConfig() |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
370 |
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 |
371 |
self.assertEqual("vim", my_config.get_editor()) |
372 |
||
1442.1.17
by Robert Collins
allow global overriding of signature policy to force checking, or (pointless but allowed) to set auto checking |
373 |
def test_signatures_always(self): |
374 |
config_file = StringIO(sample_always_signatures) |
|
375 |
my_config = config.GlobalConfig() |
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
376 |
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 |
377 |
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 |
378 |
my_config.signature_checking()) |
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
379 |
self.assertEqual(config.SIGN_ALWAYS, |
380 |
my_config.signing_policy()) |
|
1442.1.21
by Robert Collins
create signature_needed() call for commit to trigger creating signatures |
381 |
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 |
382 |
|
383 |
def test_signatures_if_possible(self): |
|
384 |
config_file = StringIO(sample_maybe_signatures) |
|
385 |
my_config = config.GlobalConfig() |
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
386 |
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 |
387 |
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 |
388 |
my_config.signature_checking()) |
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
389 |
self.assertEqual(config.SIGN_WHEN_REQUIRED, |
390 |
my_config.signing_policy()) |
|
1442.1.21
by Robert Collins
create signature_needed() call for commit to trigger creating signatures |
391 |
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 |
392 |
|
1442.1.16
by Robert Collins
allow global overriding of signature policy to never check |
393 |
def test_signatures_ignore(self): |
394 |
config_file = StringIO(sample_ignore_signatures) |
|
395 |
my_config = config.GlobalConfig() |
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
396 |
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 |
397 |
self.assertEqual(config.CHECK_ALWAYS, |
1442.1.16
by Robert Collins
allow global overriding of signature policy to never check |
398 |
my_config.signature_checking()) |
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
399 |
self.assertEqual(config.SIGN_NEVER, |
400 |
my_config.signing_policy()) |
|
1442.1.21
by Robert Collins
create signature_needed() call for commit to trigger creating signatures |
401 |
self.assertEqual(False, my_config.signature_needed()) |
1442.1.16
by Robert Collins
allow global overriding of signature policy to never check |
402 |
|
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
403 |
def _get_sample_config(self): |
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
404 |
config_file = StringIO(sample_config_text.encode('utf-8')) |
1534.7.154
by Aaron Bentley
Removed changes from bzr.ab 1529..1536 |
405 |
my_config = config.GlobalConfig() |
406 |
my_config._parser = my_config._get_parser(file=config_file) |
|
407 |
return my_config |
|
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
408 |
|
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
409 |
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. |
410 |
my_config = self._get_sample_config() |
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
411 |
self.assertEqual("gnome-gpg", my_config.gpg_signing_command()) |
412 |
self.assertEqual(False, my_config.signature_needed()) |
|
413 |
||
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
414 |
def _get_empty_config(self): |
415 |
config_file = StringIO("") |
|
416 |
my_config = config.GlobalConfig() |
|
417 |
my_config._parser = my_config._get_parser(file=config_file) |
|
418 |
return my_config |
|
419 |
||
1442.1.59
by Robert Collins
Add re-sign command to generate a digital signature on a single revision. |
420 |
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. |
421 |
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. |
422 |
self.assertEqual("gpg", my_config.gpg_signing_command()) |
423 |
||
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
424 |
def test_get_user_option_default(self): |
425 |
my_config = self._get_empty_config() |
|
426 |
self.assertEqual(None, my_config.get_user_option('no_option')) |
|
427 |
||
428 |
def test_get_user_option_global(self): |
|
429 |
my_config = self._get_sample_config() |
|
430 |
self.assertEqual("something", |
|
431 |
my_config.get_user_option('user_global_option')) |
|
1472
by Robert Collins
post commit hook, first pass implementation |
432 |
|
433 |
def test_post_commit_default(self): |
|
434 |
my_config = self._get_sample_config() |
|
435 |
self.assertEqual(None, my_config.post_commit()) |
|
436 |
||
1553.2.9
by Erik Bågfors
log_formatter => log_format for "named" formatters |
437 |
def test_configured_logformat(self): |
1553.2.8
by Erik Bågfors
tests for config log_formatter |
438 |
my_config = self._get_sample_config() |
1553.2.9
by Erik Bågfors
log_formatter => log_format for "named" formatters |
439 |
self.assertEqual("short", my_config.log_format()) |
1553.2.8
by Erik Bågfors
tests for config log_formatter |
440 |
|
1553.6.12
by Erik Bågfors
remove AliasConfig, based on input from abentley |
441 |
def test_get_alias(self): |
442 |
my_config = self._get_sample_config() |
|
443 |
self.assertEqual('help', my_config.get_alias('h')) |
|
444 |
||
445 |
def test_get_no_alias(self): |
|
446 |
my_config = self._get_sample_config() |
|
447 |
self.assertEqual(None, my_config.get_alias('foo')) |
|
448 |
||
449 |
def test_get_long_alias(self): |
|
450 |
my_config = self._get_sample_config() |
|
451 |
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. |
452 |
|
1704.2.18
by Martin Pool
Remove duplicated TestLocationConfig and update previously hidden tests. (#32587) |
453 |
|
454 |
class TestLocationConfig(TestCaseInTempDir): |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
455 |
|
456 |
def test_constructs(self): |
|
457 |
my_config = config.LocationConfig('http://example.com') |
|
458 |
self.assertRaises(TypeError, config.LocationConfig) |
|
459 |
||
460 |
def test_branch_calls_read_filenames(self): |
|
1474
by Robert Collins
Merge from Aaron Bentley. |
461 |
# This is testing the correct file names are provided.
|
462 |
# TODO: consolidate with the test for GlobalConfigs filename checks.
|
|
463 |
#
|
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
464 |
# replace the class that is constructured, to check its parameters
|
1474
by Robert Collins
Merge from Aaron Bentley. |
465 |
oldparserclass = config.ConfigObj |
466 |
config.ConfigObj = InstrumentedConfigObj |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
467 |
try: |
1770.2.2
by Aaron Bentley
Rename branches.conf to locations.conf |
468 |
my_config = config.LocationConfig('http://www.example.com') |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
469 |
parser = my_config._get_parser() |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
470 |
finally: |
1474
by Robert Collins
Merge from Aaron Bentley. |
471 |
config.ConfigObj = oldparserclass |
472 |
self.failUnless(isinstance(parser, InstrumentedConfigObj)) |
|
473 |
self.assertEqual(parser._calls, |
|
1770.2.2
by Aaron Bentley
Rename branches.conf to locations.conf |
474 |
[('__init__', config.locations_config_filename(), |
1704.2.18
by Martin Pool
Remove duplicated TestLocationConfig and update previously hidden tests. (#32587) |
475 |
'utf-8')]) |
1711.4.29
by John Arbash Meinel
Alexander Belchenko, fix test_config to use ensure_config_dir, rather than os.mkdir() |
476 |
config.ensure_config_dir_exists() |
477 |
#os.mkdir(config.config_dir())
|
|
1770.2.2
by Aaron Bentley
Rename branches.conf to locations.conf |
478 |
f = file(config.branches_config_filename(), 'wb') |
479 |
f.write('') |
|
480 |
f.close() |
|
481 |
oldparserclass = config.ConfigObj |
|
482 |
config.ConfigObj = InstrumentedConfigObj |
|
483 |
try: |
|
484 |
my_config = config.LocationConfig('http://www.example.com') |
|
485 |
parser = my_config._get_parser() |
|
486 |
finally: |
|
487 |
config.ConfigObj = oldparserclass |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
488 |
|
489 |
def test_get_global_config(self): |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
490 |
my_config = config.BranchConfig(FakeBranch('http://example.com')) |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
491 |
global_config = my_config._get_global_config() |
492 |
self.failUnless(isinstance(global_config, config.GlobalConfig)) |
|
493 |
self.failUnless(global_config is my_config._get_global_config()) |
|
494 |
||
495 |
def test__get_section_no_match(self): |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
496 |
self.get_branch_config('/') |
497 |
self.assertEqual(None, self.my_location_config._get_section()) |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
498 |
|
499 |
def test__get_section_exact(self): |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
500 |
self.get_branch_config('http://www.example.com') |
1442.1.9
by Robert Collins
exact section test passes |
501 |
self.assertEqual('http://www.example.com', |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
502 |
self.my_location_config._get_section()) |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
503 |
|
504 |
def test__get_section_suffix_does_not(self): |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
505 |
self.get_branch_config('http://www.example.com-com') |
506 |
self.assertEqual(None, self.my_location_config._get_section()) |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
507 |
|
508 |
def test__get_section_subdir_recursive(self): |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
509 |
self.get_branch_config('http://www.example.com/com') |
1442.1.11
by Robert Collins
LocationConfig lookups for non matching prefixes pass tests |
510 |
self.assertEqual('http://www.example.com', |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
511 |
self.my_location_config._get_section()) |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
512 |
|
513 |
def test__get_section_subdir_matches(self): |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
514 |
self.get_branch_config('http://www.example.com/useglobal') |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
515 |
self.assertEqual('http://www.example.com/useglobal', |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
516 |
self.my_location_config._get_section()) |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
517 |
|
518 |
def test__get_section_subdir_nonrecursive(self): |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
519 |
self.get_branch_config( |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
520 |
'http://www.example.com/useglobal/childbranch') |
1442.1.11
by Robert Collins
LocationConfig lookups for non matching prefixes pass tests |
521 |
self.assertEqual('http://www.example.com', |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
522 |
self.my_location_config._get_section()) |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
523 |
|
524 |
def test__get_section_subdir_trailing_slash(self): |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
525 |
self.get_branch_config('/b') |
526 |
self.assertEqual('/b/', self.my_location_config._get_section()) |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
527 |
|
528 |
def test__get_section_subdir_child(self): |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
529 |
self.get_branch_config('/a/foo') |
530 |
self.assertEqual('/a/*', self.my_location_config._get_section()) |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
531 |
|
532 |
def test__get_section_subdir_child_child(self): |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
533 |
self.get_branch_config('/a/foo/bar') |
534 |
self.assertEqual('/a/', self.my_location_config._get_section()) |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
535 |
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
536 |
def test__get_section_trailing_slash_with_children(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
537 |
self.get_branch_config('/a/') |
538 |
self.assertEqual('/a/', self.my_location_config._get_section()) |
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
539 |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
540 |
def test__get_section_explicit_over_glob(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
541 |
self.get_branch_config('/a/c') |
542 |
self.assertEqual('/a/c', self.my_location_config._get_section()) |
|
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
543 |
|
544 |
||
545 |
def test_location_without_username(self): |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
546 |
self.get_branch_config('http://www.example.com/useglobal') |
1704.2.18
by Martin Pool
Remove duplicated TestLocationConfig and update previously hidden tests. (#32587) |
547 |
self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>', |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
548 |
self.my_config.username()) |
549 |
||
550 |
def test_location_not_listed(self): |
|
1704.2.18
by Martin Pool
Remove duplicated TestLocationConfig and update previously hidden tests. (#32587) |
551 |
"""Test that the global username is used when no location matches"""
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
552 |
self.get_branch_config('/home/robertc/sources') |
1704.2.18
by Martin Pool
Remove duplicated TestLocationConfig and update previously hidden tests. (#32587) |
553 |
self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>', |
1442.1.8
by Robert Collins
preparing some tests for LocationConfig |
554 |
self.my_config.username()) |
555 |
||
1442.1.13
by Robert Collins
branches.conf is now able to override the users email |
556 |
def test_overriding_location(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
557 |
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 |
558 |
self.assertEqual('Robert Collins <robertc@example.org>', |
559 |
self.my_config.username()) |
|
1442.1.16
by Robert Collins
allow global overriding of signature policy to never check |
560 |
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
561 |
def test_signatures_not_set(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
562 |
self.get_branch_config('http://www.example.com', |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
563 |
global_config=sample_ignore_signatures) |
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
564 |
self.assertEqual(config.CHECK_ALWAYS, |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
565 |
self.my_config.signature_checking()) |
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
566 |
self.assertEqual(config.SIGN_NEVER, |
567 |
self.my_config.signing_policy()) |
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
568 |
|
569 |
def test_signatures_never(self): |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
570 |
self.get_branch_config('/a/c') |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
571 |
self.assertEqual(config.CHECK_NEVER, |
572 |
self.my_config.signature_checking()) |
|
573 |
||
1442.1.16
by Robert Collins
allow global overriding of signature policy to never check |
574 |
def test_signatures_when_available(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
575 |
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 |
576 |
self.assertEqual(config.CHECK_IF_POSSIBLE, |
577 |
self.my_config.signature_checking()) |
|
1442.1.13
by Robert Collins
branches.conf is now able to override the users email |
578 |
|
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
579 |
def test_signatures_always(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
580 |
self.get_branch_config('/b') |
1442.1.18
by Robert Collins
permit per branch location overriding of signature checking policy |
581 |
self.assertEqual(config.CHECK_ALWAYS, |
582 |
self.my_config.signature_checking()) |
|
583 |
||
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
584 |
def test_gpg_signing_command(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
585 |
self.get_branch_config('/b') |
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
586 |
self.assertEqual("gnome-gpg", self.my_config.gpg_signing_command()) |
587 |
||
588 |
def test_gpg_signing_command_missing(self): |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
589 |
self.get_branch_config('/a') |
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
590 |
self.assertEqual("false", self.my_config.gpg_signing_command()) |
591 |
||
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
592 |
def test_get_user_option_global(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
593 |
self.get_branch_config('/a') |
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
594 |
self.assertEqual('something', |
595 |
self.my_config.get_user_option('user_global_option')) |
|
596 |
||
597 |
def test_get_user_option_local(self): |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
598 |
self.get_branch_config('/a') |
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
599 |
self.assertEqual('local', |
600 |
self.my_config.get_user_option('user_local_option')) |
|
1472
by Robert Collins
post commit hook, first pass implementation |
601 |
|
602 |
def test_post_commit_default(self): |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
603 |
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 |
604 |
self.assertEqual('bzrlib.tests.test_config.post_commit', |
1472
by Robert Collins
post commit hook, first pass implementation |
605 |
self.my_config.post_commit()) |
1442.1.69
by Robert Collins
config.Config has a 'get_user_option' call that accepts an option name. |
606 |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
607 |
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. |
608 |
if global_config is None: |
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
609 |
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. |
610 |
else: |
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
611 |
global_file = StringIO(global_config.encode('utf-8')) |
612 |
branches_file = StringIO(sample_branches_text.encode('utf-8')) |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
613 |
self.my_config = config.BranchConfig(FakeBranch(location)) |
614 |
# Force location config to use specified file
|
|
615 |
self.my_location_config = self.my_config._get_location_config() |
|
616 |
self.my_location_config._get_parser(branches_file) |
|
617 |
# 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. |
618 |
self.my_config._get_global_config()._get_parser(global_file) |
619 |
||
1490
by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1. |
620 |
def test_set_user_setting_sets_and_saves(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
621 |
self.get_branch_config('/a/c') |
1490
by Robert Collins
Implement a 'bzr push' command, with saved locations; update diff to return 1. |
622 |
record = InstrumentedConfigObj("foo") |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
623 |
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 |
624 |
|
625 |
real_mkdir = os.mkdir |
|
626 |
self.created = False |
|
627 |
def checked_mkdir(path, mode=0777): |
|
628 |
self.log('making directory: %s', path) |
|
629 |
real_mkdir(path, mode) |
|
630 |
self.created = True |
|
631 |
||
632 |
os.mkdir = checked_mkdir |
|
633 |
try: |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
634 |
self.my_config.set_user_option('foo', 'bar', local=True) |
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 |
635 |
finally: |
636 |
os.mkdir = real_mkdir |
|
637 |
||
638 |
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. |
639 |
self.assertEqual([('__contains__', '/a/c'), |
640 |
('__contains__', '/a/c/'), |
|
641 |
('__setitem__', '/a/c', {}), |
|
642 |
('__getitem__', '/a/c'), |
|
643 |
('__setitem__', 'foo', 'bar'), |
|
644 |
('write',)], |
|
645 |
record._calls[1:]) |
|
646 |
||
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
647 |
def test_set_user_setting_sets_and_saves2(self): |
648 |
self.get_branch_config('/a/c') |
|
649 |
self.assertIs(self.my_config.get_user_option('foo'), None) |
|
650 |
self.my_config.set_user_option('foo', 'bar') |
|
651 |
self.assertEqual( |
|
652 |
self.my_config.branch.control_files.files['branch.conf'], |
|
653 |
'foo = bar') |
|
654 |
self.assertEqual(self.my_config.get_user_option('foo'), 'bar') |
|
655 |
self.my_config.set_user_option('foo', 'baz', local=True) |
|
656 |
self.assertEqual(self.my_config.get_user_option('foo'), 'baz') |
|
657 |
self.my_config.set_user_option('foo', 'qux') |
|
658 |
self.assertEqual(self.my_config.get_user_option('foo'), 'baz') |
|
659 |
||
1185.62.7
by John Arbash Meinel
Whitespace cleanup. |
660 |
|
1770.2.8
by Aaron Bentley
Add precedence test |
661 |
precedence_global = 'option = global' |
662 |
precedence_branch = 'option = branch' |
|
663 |
precedence_location = """ |
|
664 |
[http://]
|
|
665 |
recurse = true
|
|
666 |
option = recurse
|
|
667 |
[http://example.com/specific]
|
|
668 |
option = exact
|
|
669 |
"""
|
|
670 |
||
671 |
||
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
672 |
class TestBranchConfigItems(TestCaseInTempDir): |
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
673 |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
674 |
def get_branch_config(self, global_config=None, location=None, |
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
675 |
location_config=None, branch_data_config=None): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
676 |
my_config = config.BranchConfig(FakeBranch(location)) |
677 |
if global_config is not None: |
|
678 |
global_file = StringIO(global_config.encode('utf-8')) |
|
679 |
my_config._get_global_config()._get_parser(global_file) |
|
680 |
self.my_location_config = my_config._get_location_config() |
|
681 |
if location_config is not None: |
|
682 |
location_file = StringIO(location_config.encode('utf-8')) |
|
683 |
self.my_location_config._get_parser(location_file) |
|
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
684 |
if branch_data_config is not None: |
685 |
my_config.branch.control_files.files['branch.conf'] = \ |
|
686 |
branch_data_config
|
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
687 |
return my_config |
688 |
||
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
689 |
def test_user_id(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
690 |
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 |
691 |
my_config = config.BranchConfig(branch) |
692 |
self.assertEqual("Robert Collins <robertc@example.net>", |
|
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
693 |
my_config.username()) |
1185.65.11
by Robert Collins
Disable inheritance for getting at LockableFiles, rather use composition. |
694 |
branch.control_files.email = "John" |
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
695 |
my_config.set_user_option('email', |
696 |
"Robert Collins <robertc@example.org>") |
|
697 |
self.assertEqual("John", my_config.username()) |
|
698 |
branch.control_files.email = None |
|
699 |
self.assertEqual("Robert Collins <robertc@example.org>", |
|
700 |
my_config.username()) |
|
1442.1.6
by Robert Collins
first stage major overhaul of configs, giving use BranchConfigs, LocationConfigs and GlobalConfigs |
701 |
|
702 |
def test_not_set_in_branch(self): |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
703 |
my_config = self.get_branch_config(sample_config_text) |
704 |
my_config.branch.control_files.email = None |
|
1551.2.21
by Aaron Bentley
Formatted unicode config tests as ASCII |
705 |
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 |
706 |
my_config._get_user_id()) |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
707 |
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 |
708 |
self.assertEqual("John", my_config._get_user_id()) |
709 |
||
710 |
def test_BZREMAIL_OVERRIDES(self): |
|
711 |
os.environ['BZREMAIL'] = "Robert Collins <robertc@example.org>" |
|
712 |
branch = FakeBranch() |
|
713 |
my_config = config.BranchConfig(branch) |
|
714 |
self.assertEqual("Robert Collins <robertc@example.org>", |
|
715 |
my_config.username()) |
|
716 |
||
1442.1.19
by Robert Collins
BranchConfigs inherit signature_checking policy from their LocationConfig. |
717 |
def test_signatures_forced(self): |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
718 |
my_config = self.get_branch_config( |
719 |
global_config=sample_always_signatures) |
|
1770.2.1
by Aaron Bentley
Use create_signature for signing policy, deprecate check_signatures for this |
720 |
self.assertEqual(config.CHECK_NEVER, my_config.signature_checking()) |
721 |
self.assertEqual(config.SIGN_ALWAYS, my_config.signing_policy()) |
|
722 |
self.assertTrue(my_config.signature_needed()) |
|
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
723 |
|
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
724 |
def test_signatures_forced_branch(self): |
725 |
my_config = self.get_branch_config( |
|
726 |
global_config=sample_ignore_signatures, |
|
727 |
branch_data_config=sample_always_signatures) |
|
728 |
self.assertEqual(config.CHECK_NEVER, my_config.signature_checking()) |
|
729 |
self.assertEqual(config.SIGN_ALWAYS, my_config.signing_policy()) |
|
730 |
self.assertTrue(my_config.signature_needed()) |
|
731 |
||
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
732 |
def test_gpg_signing_command(self): |
1770.2.10
by Aaron Bentley
Added test that branch_config can't influence gpg_signing_command |
733 |
my_config = self.get_branch_config( |
734 |
# branch data cannot set gpg_signing_command
|
|
735 |
branch_data_config="gpg_signing_command=pgp") |
|
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
736 |
config_file = StringIO(sample_config_text.encode('utf-8')) |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
737 |
my_config._get_global_config()._get_parser(config_file) |
1442.1.56
by Robert Collins
gpg_signing_command configuration item |
738 |
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. |
739 |
|
740 |
def test_get_user_option_global(self): |
|
741 |
branch = FakeBranch() |
|
742 |
my_config = config.BranchConfig(branch) |
|
1551.2.20
by Aaron Bentley
Treated config files as utf-8 |
743 |
config_file = StringIO(sample_config_text.encode('utf-8')) |
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
744 |
(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. |
745 |
self.assertEqual('something', |
746 |
my_config.get_user_option('user_global_option')) |
|
1472
by Robert Collins
post commit hook, first pass implementation |
747 |
|
748 |
def test_post_commit_default(self): |
|
749 |
branch = FakeBranch() |
|
1770.2.5
by Aaron Bentley
Integrate branch.conf into BranchConfig |
750 |
my_config = self.get_branch_config(sample_config_text, '/a/c', |
751 |
sample_branches_text) |
|
752 |
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 |
753 |
self.assertEqual('bzrlib.tests.test_config.post_commit', |
1472
by Robert Collins
post commit hook, first pass implementation |
754 |
my_config.post_commit()) |
1770.2.6
by Aaron Bentley
Ensure branch.conf works properly |
755 |
my_config.set_user_option('post_commit', 'rmtree_root') |
756 |
# post-commit is ignored when bresent in branch data
|
|
757 |
self.assertEqual('bzrlib.tests.test_config.post_commit', |
|
758 |
my_config.post_commit()) |
|
759 |
my_config.set_user_option('post_commit', 'rmtree_root', local=True) |
|
760 |
self.assertEqual('rmtree_root', my_config.post_commit()) |
|
1185.33.31
by Martin Pool
Make annotate cope better with revisions committed without a valid |
761 |
|
1770.2.8
by Aaron Bentley
Add precedence test |
762 |
def test_config_precedence(self): |
763 |
my_config = self.get_branch_config(global_config=precedence_global) |
|
764 |
self.assertEqual(my_config.get_user_option('option'), 'global') |
|
765 |
my_config = self.get_branch_config(global_config=precedence_global, |
|
766 |
branch_data_config=precedence_branch) |
|
767 |
self.assertEqual(my_config.get_user_option('option'), 'branch') |
|
768 |
my_config = self.get_branch_config(global_config=precedence_global, |
|
769 |
branch_data_config=precedence_branch, |
|
770 |
location_config=precedence_location) |
|
771 |
self.assertEqual(my_config.get_user_option('option'), 'recurse') |
|
772 |
my_config = self.get_branch_config(global_config=precedence_global, |
|
773 |
branch_data_config=precedence_branch, |
|
774 |
location_config=precedence_location, |
|
775 |
location='http://example.com/specific') |
|
776 |
self.assertEqual(my_config.get_user_option('option'), 'exact') |
|
777 |
||
1185.33.31
by Martin Pool
Make annotate cope better with revisions committed without a valid |
778 |
|
779 |
class TestMailAddressExtraction(TestCase): |
|
780 |
||
781 |
def test_extract_email_address(self): |
|
782 |
self.assertEqual('jane@test.com', |
|
783 |
config.extract_email_address('Jane <jane@test.com>')) |
|
784 |
self.assertRaises(errors.BzrError, |
|
785 |
config.extract_email_address, 'Jane Tester') |