~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Patch Queue Manager
  • Date: 2012-02-14 18:29:43 UTC
  • mfrom: (6404.6.11 cached-branch-store)
  • Revision ID: pqm@pqm.ubuntu.com-20120214182943-vso6j0mqdnxfkp7s
(vila) Cache the branch config store to avoid useless IOs. (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2005-2012 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
2924
2924
    def test_save_emptied_succeeds(self):
2925
2925
        store = self.get_store(self)
2926
2926
        store._load_from_string('foo=bar\n')
 
2927
        # FIXME: There should be a better way than relying on the test
 
2928
        # parametrization to identify branch.conf -- vila 2011-0526
 
2929
        if self.store_id in ('branch', 'remote_branch'):
 
2930
            # branch stores requires write locked branches
 
2931
            self.addCleanup(store.branch.lock_write().unlock)
2927
2932
        section = store.get_mutable_section(None)
2928
2933
        section.remove('foo')
2929
2934
        store.save()
2950
2955
 
2951
2956
    def test_set_option_in_empty_store(self):
2952
2957
        store = self.get_store(self)
 
2958
        # FIXME: There should be a better way than relying on the test
 
2959
        # parametrization to identify branch.conf -- vila 2011-0526
 
2960
        if self.store_id in ('branch', 'remote_branch'):
 
2961
            # branch stores requires write locked branches
 
2962
            self.addCleanup(store.branch.lock_write().unlock)
2953
2963
        section = store.get_mutable_section(None)
2954
2964
        section.set('foo', 'bar')
2955
2965
        store.save()
2961
2971
    def test_set_option_in_default_section(self):
2962
2972
        store = self.get_store(self)
2963
2973
        store._load_from_string('')
 
2974
        # FIXME: There should be a better way than relying on the test
 
2975
        # parametrization to identify branch.conf -- vila 2011-0526
 
2976
        if self.store_id in ('branch', 'remote_branch'):
 
2977
            # branch stores requires write locked branches
 
2978
            self.addCleanup(store.branch.lock_write().unlock)
2964
2979
        section = store.get_mutable_section(None)
2965
2980
        section.set('foo', 'bar')
2966
2981
        store.save()
2972
2987
    def test_set_option_in_named_section(self):
2973
2988
        store = self.get_store(self)
2974
2989
        store._load_from_string('')
 
2990
        # FIXME: There should be a better way than relying on the test
 
2991
        # parametrization to identify branch.conf -- vila 2011-0526
 
2992
        if self.store_id in ('branch', 'remote_branch'):
 
2993
            # branch stores requires write locked branches
 
2994
            self.addCleanup(store.branch.lock_write().unlock)
2975
2995
        section = store.get_mutable_section('baz')
2976
2996
        section.set('foo', 'bar')
2977
2997
        store.save()
2981
3001
        self.assertSectionContent(('baz', {'foo': 'bar'}), sections[0])
2982
3002
 
2983
3003
    def test_load_hook(self):
2984
 
        # We first needs to ensure that the store exists
 
3004
        # First, we need to ensure that the store exists
2985
3005
        store = self.get_store(self)
 
3006
        # FIXME: There should be a better way than relying on the test
 
3007
        # parametrization to identify branch.conf -- vila 2011-0526
 
3008
        if self.store_id in ('branch', 'remote_branch'):
 
3009
            # branch stores requires write locked branches
 
3010
            self.addCleanup(store.branch.lock_write().unlock)
2986
3011
        section = store.get_mutable_section('baz')
2987
3012
        section.set('foo', 'bar')
2988
3013
        store.save()
3004
3029
        config.ConfigHooks.install_named_hook('save', hook, None)
3005
3030
        self.assertLength(0, calls)
3006
3031
        store = self.get_store(self)
 
3032
        # FIXME: There should be a better way than relying on the test
 
3033
        # parametrization to identify branch.conf -- vila 2011-0526
 
3034
        if self.store_id in ('branch', 'remote_branch'):
 
3035
            # branch stores requires write locked branches
 
3036
            self.addCleanup(store.branch.lock_write().unlock)
3007
3037
        section = store.get_mutable_section('baz')
3008
3038
        section.set('foo', 'bar')
3009
3039
        store.save()
3835
3865
        super(TestStackExpandOptions, self).setUp()
3836
3866
        self.overrideAttr(config, 'option_registry', config.OptionRegistry())
3837
3867
        self.registry = config.option_registry
3838
 
        self.conf = build_branch_stack(self)
 
3868
        store = config.TransportIniFileStore(self.get_transport(), 'foo.conf')
 
3869
        self.conf = config.Stack([store.get_sections], store)
3839
3870
 
3840
3871
    def assertExpansion(self, expected, string, env=None):
3841
3872
        self.assertEquals(expected, self.conf.expand_options(string, env))