1
# Copyright (C) 2005 by Canonical Ltd
1
# Copyright (C) 2005, 2006 by Canonical Ltd
2
2
# Authors: Robert Collins <robert.collins@canonical.com>
4
4
# This program is free software; you can redistribute it and/or modify
396
396
my_config = self._get_sample_config()
397
397
self.assertEqual(sample_long_alias, my_config.get_alias('ll'))
399
class TestLocationConfig(TestCase):
400
class TestLocationConfig(TestCaseInTempDir):
401
402
def test_constructs(self):
402
403
my_config = config.LocationConfig('http://example.com')
416
417
config.ConfigObj = oldparserclass
417
418
self.failUnless(isinstance(parser, InstrumentedConfigObj))
418
419
self.assertEqual(parser._calls,
419
[('__init__', config.branches_config_filename())])
420
[('__init__', config.branches_config_filename(),
421
423
def test_get_global_config(self):
422
424
my_config = config.LocationConfig('http://example.com')
473
475
self.get_location_config('/a/c')
474
476
self.assertEqual('/a/c', self.my_config._get_section())
476
def get_location_config(self, location, global_config=None):
477
if global_config is None:
478
global_file = StringIO(sample_config_text)
480
global_file = StringIO(global_config)
481
branches_file = StringIO(sample_branches_text)
482
self.my_config = config.LocationConfig(location)
483
self.my_config._get_parser(branches_file)
484
self.my_config._get_global_config()._get_parser(global_file)
486
479
def test_location_without_username(self):
487
480
self.get_location_config('http://www.example.com/useglobal')
488
self.assertEqual('Robert Collins <robertc@example.com>',
481
self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>',
489
482
self.my_config.username())
491
484
def test_location_not_listed(self):
485
"""Test that the global username is used when no location matches"""
492
486
self.get_location_config('/home/robertc/sources')
493
self.assertEqual('Robert Collins <robertc@example.com>',
487
self.assertEqual(u'Erik B\u00e5gfors <erik@bagfors.nu>',
494
488
self.my_config.username())
496
490
def test_overriding_location(self):
542
536
self.assertEqual('bzrlib.tests.test_config.post_commit',
543
537
self.my_config.post_commit())
546
class TestLocationConfig(TestCaseInTempDir):
548
539
def get_location_config(self, location, global_config=None):
549
540
if global_config is None:
550
541
global_file = StringIO(sample_config_text.encode('utf-8'))