3453
3453
self.assertEquals(['bar', 'baz'], self.conf.get('foo'))
3456
class TestIterOptionRefs(tests.TestCase):
3457
"""iter_option_refs is a bit unusual, document some cases."""
3459
def assertRefs(self, expected, string):
3460
self.assertEquals(expected, list(config.iter_option_refs(string)))
3462
def test_empty(self):
3463
self.assertRefs([(False, '')], '')
3465
def test_no_refs(self):
3466
self.assertRefs([(False, 'foo bar')], 'foo bar')
3468
def test_single_ref(self):
3469
self.assertRefs([(False, ''), (True, '{foo}'), (False, '')], '{foo}')
3471
def test_broken_ref(self):
3472
self.assertRefs([(False, '{foo')], '{foo')
3474
def test_embedded_ref(self):
3475
self.assertRefs([(False, '{'), (True, '{foo}'), (False, '}')],
3478
def test_two_refs(self):
3479
self.assertRefs([(False, ''), (True, '{foo}'),
3480
(False, ''), (True, '{bar}'),
3456
3485
class TestStackExpandOptions(tests.TestCaseWithTransport):
3458
3487
def setUp(self):
3607
3636
self.assertEquals('quux', c.get('bar', expand=True))
3639
class TestStackCrossStoresExpand(tests.TestCaseWithTransport):
3641
def test_cross_global_locations(self):
3642
l_store = config.LocationStore()
3643
l_store._load_from_string('''
3649
g_store = config.GlobalStore()
3650
g_store._load_from_string('''
3656
stack = config.LocationStack('/branch')
3657
self.assertEquals('glob-bar', stack.get('lbar', expand=True))
3658
self.assertEquals('loc-foo', stack.get('gfoo', expand=True))
3661
class TestStackExpandSectionLocals(tests.TestCaseWithTransport):
3663
def test_expand_relpath_locally(self):
3664
l_store = config.LocationStore()
3665
l_store._load_from_string('''
3666
[/home/user/project]
3667
lfoo = loc-foo/{relpath}
3670
stack = config.LocationStack('/home/user/project/branch')
3671
self.assertEquals('loc-foo/branch', stack.get('lfoo', expand=True))
3673
def test_expand_relpath_unknonw_in_global(self):
3674
g_store = config.GlobalStore()
3675
g_store._load_from_string('''
3680
stack = config.LocationStack('/home/user/project/branch')
3681
self.assertRaises(errors.ExpandingUnknownOption,
3682
stack.get, 'gfoo', expand=True)
3684
def test_expand_local_option_locally(self):
3685
l_store = config.LocationStore()
3686
l_store._load_from_string('''
3687
[/home/user/project]
3688
lfoo = loc-foo/{relpath}
3692
g_store = config.GlobalStore()
3693
g_store._load_from_string('''
3699
stack = config.LocationStack('/home/user/project/branch')
3700
self.assertEquals('glob-bar', stack.get('lbar', expand=True))
3701
self.assertEquals('loc-foo/branch', stack.get('gfoo', expand=True))
3703
def test_locals_dont_leak(self):
3704
"""Make sure we chose the right local in presence of several sections.
3706
l_store = config.LocationStore()
3707
l_store._load_from_string('''
3709
lfoo = loc-foo/{relpath}
3710
[/home/user/project]
3711
lfoo = loc-foo/{relpath}
3714
stack = config.LocationStack('/home/user/project/branch')
3715
self.assertEquals('loc-foo/branch', stack.get('lfoo', expand=True))
3716
stack = config.LocationStack('/home/user/bar/baz')
3717
self.assertEquals('loc-foo/bar/baz', stack.get('lfoo', expand=True))
3610
3721
class TestStackSet(TestStackWithTransport):
3612
3723
def test_simple_set(self):