~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Jelmer Vernooij
  • Date: 2011-11-15 17:27:46 UTC
  • mfrom: (6260 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6263.
  • Revision ID: jelmer@samba.org-20111115172746-bznns2ohiexp2g5q
merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3453
3453
        self.assertEquals(['bar', 'baz'], self.conf.get('foo'))
3454
3454
 
3455
3455
 
 
3456
class TestIterOptionRefs(tests.TestCase):
 
3457
    """iter_option_refs is a bit unusual, document some cases."""
 
3458
 
 
3459
    def assertRefs(self, expected, string):
 
3460
        self.assertEquals(expected, list(config.iter_option_refs(string)))
 
3461
 
 
3462
    def test_empty(self):
 
3463
        self.assertRefs([(False, '')], '')
 
3464
 
 
3465
    def test_no_refs(self):
 
3466
        self.assertRefs([(False, 'foo bar')], 'foo bar')
 
3467
 
 
3468
    def test_single_ref(self):
 
3469
        self.assertRefs([(False, ''), (True, '{foo}'), (False, '')], '{foo}')
 
3470
 
 
3471
    def test_broken_ref(self):
 
3472
        self.assertRefs([(False, '{foo')], '{foo')
 
3473
 
 
3474
    def test_embedded_ref(self):
 
3475
        self.assertRefs([(False, '{'), (True, '{foo}'), (False, '}')],
 
3476
                        '{{foo}}')
 
3477
 
 
3478
    def test_two_refs(self):
 
3479
        self.assertRefs([(False, ''), (True, '{foo}'),
 
3480
                         (False, ''), (True, '{bar}'),
 
3481
                         (False, ''),],
 
3482
                        '{foo}{bar}')
 
3483
 
 
3484
 
3456
3485
class TestStackExpandOptions(tests.TestCaseWithTransport):
3457
3486
 
3458
3487
    def setUp(self):
3607
3636
        self.assertEquals('quux', c.get('bar', expand=True))
3608
3637
 
3609
3638
 
 
3639
class TestStackCrossStoresExpand(tests.TestCaseWithTransport):
 
3640
 
 
3641
    def test_cross_global_locations(self):
 
3642
        l_store = config.LocationStore()
 
3643
        l_store._load_from_string('''
 
3644
[/branch]
 
3645
lfoo = loc-foo
 
3646
lbar = {gbar}
 
3647
''')
 
3648
        l_store.save()
 
3649
        g_store = config.GlobalStore()
 
3650
        g_store._load_from_string('''
 
3651
[DEFAULT]
 
3652
gfoo = {lfoo}
 
3653
gbar = glob-bar
 
3654
''')
 
3655
        g_store.save()
 
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))
 
3659
 
 
3660
 
 
3661
class TestStackExpandSectionLocals(tests.TestCaseWithTransport):
 
3662
 
 
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}
 
3668
''')
 
3669
        l_store.save()
 
3670
        stack = config.LocationStack('/home/user/project/branch')
 
3671
        self.assertEquals('loc-foo/branch', stack.get('lfoo', expand=True))
 
3672
 
 
3673
    def test_expand_relpath_unknonw_in_global(self):
 
3674
        g_store = config.GlobalStore()
 
3675
        g_store._load_from_string('''
 
3676
[DEFAULT]
 
3677
gfoo = {relpath}
 
3678
''')
 
3679
        g_store.save()
 
3680
        stack = config.LocationStack('/home/user/project/branch')
 
3681
        self.assertRaises(errors.ExpandingUnknownOption,
 
3682
                          stack.get, 'gfoo', expand=True)
 
3683
 
 
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}
 
3689
lbar = {gbar}
 
3690
''')
 
3691
        l_store.save()
 
3692
        g_store = config.GlobalStore()
 
3693
        g_store._load_from_string('''
 
3694
[DEFAULT]
 
3695
gfoo = {lfoo}
 
3696
gbar = glob-bar
 
3697
''')
 
3698
        g_store.save()
 
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))
 
3702
 
 
3703
    def test_locals_dont_leak(self):
 
3704
        """Make sure we chose the right local in presence of several sections.
 
3705
        """
 
3706
        l_store = config.LocationStore()
 
3707
        l_store._load_from_string('''
 
3708
[/home/user]
 
3709
lfoo = loc-foo/{relpath}
 
3710
[/home/user/project]
 
3711
lfoo = loc-foo/{relpath}
 
3712
''')
 
3713
        l_store.save()
 
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))
 
3718
 
 
3719
 
 
3720
 
3610
3721
class TestStackSet(TestStackWithTransport):
3611
3722
 
3612
3723
    def test_simple_set(self):