1471
1471
self.assertIs(None, bzrdir_config.get_default_stack_on())
1474
class TestConfigGetOptions(tests.TestCaseWithTransport):
1474
class TestWithConfigs(tests.TestCaseWithTransport):
1476
1476
def setUp(self):
1477
super(TestConfigGetOptions, self).setUp()
1477
super(TestWithConfigs, self).setUp()
1478
1478
self.global_config = config.GlobalConfig()
1479
self.tree = self.make_branch_and_tree('.')
1479
self.tree = self.make_branch_and_tree('tree')
1480
1480
self.branch_config = config.BranchConfig(self.tree.branch)
1481
1481
self.locations_config = config.LocationConfig(self.tree.basedir)
1484
class TestConfigGetOptions(TestWithConfigs):
1483
1486
def assertOptions(self, expected, conf):
1484
1487
actual = list(conf.get_options())
1485
1488
self.assertEqual(expected, actual)
1532
1535
self.branch_config)
1538
class TestConfigGetSections(TestWithConfigs):
1540
def assertSectionNames(self, expected, conf, name=None):
1541
"""Check which sections are returned for a given config.
1543
If fallback configurations exist their sections can be included.
1545
:param expected: A list of section names.
1547
:param conf: The configuration that will be queried.
1549
:param name: An optional section name that will be passed to
1552
sections = list(conf.get_sections(name))
1553
self.assertLength(len(expected), sections)
1554
self.assertEqual(expected, [name for name, section in sections])
1556
def test_global_default_section(self):
1557
self.assertSectionNames(['DEFAULT'], self.global_config)
1559
def test_locations_default_section(self):
1560
# No sections are defined in an empty file
1561
self.assertSectionNames([], self.locations_config)
1563
def test_locations_named_section(self):
1564
self.locations_config.set_user_option('file', 'locations')
1565
self.assertSectionNames([self.tree.basedir], self.locations_config)
1567
def test_locations_matching_sections(self):
1568
loc_config = self.locations_config
1569
loc_config.set_user_option('file', 'locations')
1570
# We need to cheat a bit here to create an option in sections above and
1571
# below the 'location' one.
1572
parser = loc_config._get_parser()
1573
# locations.cong deals with '/' ignoring native os.sep
1574
location_names = self.tree.basedir.split('/')
1575
parent = '/'.join(location_names[:-1])
1576
child = '/'.join(location_names + ['child'])
1578
parser[parent]['file'] = 'parent'
1580
parser[child]['file'] = 'child'
1581
self.assertSectionNames([self.tree.basedir, parent], loc_config)
1583
def test_branch_data_default_section(self):
1584
self.assertSectionNames([None],
1585
self.branch_config._get_branch_data_config())
1587
def test_branch_default_sections(self):
1588
# No sections are defined in an empty locations file
1589
self.assertSectionNames([None, 'DEFAULT'],
1591
# Unless we define an option
1592
self.branch_config._get_location_config().set_user_option(
1593
'file', 'locations')
1594
self.assertSectionNames([self.tree.basedir, None, 'DEFAULT'],
1597
def test_global_named_section(self):
1598
# We need to cheat as the API doesn't give direct access to sections
1599
# other than DEFAULT.
1600
self.global_config.set_alias('bazaar', 'bzr')
1601
self.assertSectionNames(['ALIASES'], self.global_config, 'ALIASES')
1535
1604
class TestAuthenticationConfigFile(tests.TestCase):
1536
1605
"""Test the authentication.conf file matching"""