165
165
self.assertEqual(config.branches_config_filename(),
166
166
'/home/bogus/.bazaar/branches.conf')
169
class TestGetConfig(TestCase):
171
def test_constructs(self):
172
my_config = config.GlobalConfig()
168
class TestIniConfig(TestCase):
170
def test_contructs(self):
171
my_config = config.IniBasedConfig("nothing")
174
173
def test_from_fp(self):
175
174
config_file = StringIO(sample_config_text)
176
my_config = config.GlobalConfig()
175
my_config = config.IniBasedConfig(None)
178
isinstance(my_config._get_config_parser(file=config_file),
177
isinstance(my_config._get_parser(file=config_file),
181
180
def test_cached(self):
182
181
config_file = StringIO(sample_config_text)
182
my_config = config.IniBasedConfig(None)
183
parser = my_config._get_parser(file=config_file)
184
self.failUnless(my_config._get_parser() is parser)
188
class TestGetConfig(TestCase):
190
def test_constructs(self):
183
191
my_config = config.GlobalConfig()
184
parser = my_config._get_config_parser(file=config_file)
185
self.failUnless(my_config._get_config_parser() is parser)
187
193
def test_calls_read_filenames(self):
188
194
# replace the class that is constructured, to check its parameters
190
196
config.ConfigParser = InstrumentedConfigParser
191
197
my_config = config.GlobalConfig()
193
parser = my_config._get_config_parser()
199
parser = my_config._get_parser()
195
201
config.ConfigParser = oldparserclass
196
202
self.failUnless(isinstance(parser, InstrumentedConfigParser))
241
247
def test_user_id(self):
242
248
config_file = StringIO(sample_config_text)
243
249
my_config = config.GlobalConfig()
244
my_config._parser = my_config._get_config_parser(file=config_file)
250
my_config._parser = my_config._get_parser(file=config_file)
245
251
self.assertEqual("Robert Collins <robertc@example.com>",
246
252
my_config._get_user_id())
248
254
def test_absent_user_id(self):
249
255
config_file = StringIO("")
250
256
my_config = config.GlobalConfig()
251
my_config._parser = my_config._get_config_parser(file=config_file)
257
my_config._parser = my_config._get_parser(file=config_file)
252
258
self.assertEqual(None, my_config._get_user_id())
254
260
def test_configured_editor(self):
255
261
config_file = StringIO(sample_config_text)
256
262
my_config = config.GlobalConfig()
257
my_config._parser = my_config._get_config_parser(file=config_file)
263
my_config._parser = my_config._get_parser(file=config_file)
258
264
self.assertEqual("vim", my_config.get_editor())
260
266
def test_signatures_always(self):
261
267
config_file = StringIO(sample_always_signatures)
262
268
my_config = config.GlobalConfig()
263
my_config._parser = my_config._get_config_parser(file=config_file)
269
my_config._parser = my_config._get_parser(file=config_file)
264
270
self.assertEqual(config.CHECK_ALWAYS,
265
271
my_config.signature_checking())
267
273
def test_signatures_if_possible(self):
268
274
config_file = StringIO(sample_maybe_signatures)
269
275
my_config = config.GlobalConfig()
270
my_config._parser = my_config._get_config_parser(file=config_file)
276
my_config._parser = my_config._get_parser(file=config_file)
271
277
self.assertEqual(config.CHECK_IF_POSSIBLE,
272
278
my_config.signature_checking())
274
280
def test_signatures_ignore(self):
275
281
config_file = StringIO(sample_ignore_signatures)
276
282
my_config = config.GlobalConfig()
277
my_config._parser = my_config._get_config_parser(file=config_file)
283
my_config._parser = my_config._get_parser(file=config_file)
278
284
self.assertEqual(config.CHECK_NEVER,
279
285
my_config.signature_checking())
285
291
my_config = config.LocationConfig('http://example.com')
286
292
self.assertRaises(TypeError, config.LocationConfig)
288
def test_cached(self):
289
config_file = StringIO(sample_config_text)
290
my_config = config.LocationConfig('http://example.com')
291
parser = my_config._get_branches_config_parser(file=config_file)
292
self.failUnless(my_config._get_branches_config_parser() is parser)
294
def test_branches_from_fp(self):
295
config_file = StringIO(sample_config_text)
296
my_config = config.LocationConfig('http://example.com')
297
self.failUnless(isinstance(
298
my_config._get_branches_config_parser(file=config_file),
301
294
def test_branch_calls_read_filenames(self):
302
295
# replace the class that is constructured, to check its parameters
303
296
oldparserclass = config.ConfigParser
304
297
config.ConfigParser = InstrumentedConfigParser
305
298
my_config = config.LocationConfig('http://www.example.com')
307
parser = my_config._get_branches_config_parser()
300
parser = my_config._get_parser()
309
302
config.ConfigParser = oldparserclass
310
303
self.failUnless(isinstance(parser, InstrumentedConfigParser))
357
350
self.get_location_config('/a/foo/bar')
358
351
self.assertEqual('/a/', self.my_config._get_section())
353
def test__get_section_trailing_slash_with_children(self):
354
self.get_location_config('/a/')
355
self.assertEqual('/a/', self.my_config._get_section())
360
357
def test__get_section_explicit_over_glob(self):
361
358
self.get_location_config('/a/c')
362
359
self.assertEqual('/a/c', self.my_config._get_section())
364
def get_location_config(self, location):
365
global_file = StringIO(sample_config_text)
361
def get_location_config(self, location, global_config=None):
362
if global_config is None:
363
global_file = StringIO(sample_config_text)
365
global_file = StringIO(global_config)
366
366
branches_file = StringIO(sample_branches_text)
367
367
self.my_config = config.LocationConfig(location)
368
self.my_config._get_branches_config_parser(branches_file)
369
self.my_config._get_global_config()._get_config_parser(global_file)
368
self.my_config._get_parser(branches_file)
369
self.my_config._get_global_config()._get_parser(global_file)
371
371
def test_location_without_username(self):
372
372
self.get_location_config('http://www.example.com/useglobal')
383
383
self.assertEqual('Robert Collins <robertc@example.org>',
384
384
self.my_config.username())
386
def test_signatures_not_set(self):
387
self.get_location_config('http://www.example.com',
388
global_config=sample_ignore_signatures)
389
self.assertEqual(config.CHECK_NEVER,
390
self.my_config.signature_checking())
392
def test_signatures_never(self):
393
self.get_location_config('/a/c')
394
self.assertEqual(config.CHECK_NEVER,
395
self.my_config.signature_checking())
386
397
def test_signatures_when_available(self):
387
self.get_location_config('/a/')
398
self.get_location_config('/a/', global_config=sample_ignore_signatures)
388
399
self.assertEqual(config.CHECK_IF_POSSIBLE,
389
400
self.my_config.signature_checking())
402
def test_signatures_always(self):
403
self.get_location_config('/b')
404
self.assertEqual(config.CHECK_ALWAYS,
405
self.my_config.signature_checking())
392
408
class TestBranchConfigItems(TestConfigItems):
405
421
branch.email = None
406
422
config_file = StringIO(sample_config_text)
407
423
(my_config._get_location_config().
408
_get_global_config()._get_config_parser(config_file))
424
_get_global_config()._get_parser(config_file))
409
425
self.assertEqual("Robert Collins <robertc@example.com>",
410
426
my_config._get_user_id())
411
427
branch.email = "John"