~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Vincent Ladeuil
  • Date: 2012-01-05 14:26:58 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120105142658-vek3v6pzlxb751s2
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made. 

@only_raises is evil and gave a hard time since any exception during
save_changes() was swallowed.

Possible improvements: 

- add some needs_write_lock decorators to crucial
  methods (_set_config_location ?) but keep locking the branch at higher levels

- decorate branch.unlock to call stack.save if last_lock() it True
  outside of @only_raises scope (evil decorator)

- add @needs_write_lock to stack.set and stack.remove (will probably get
  rid of most testing issues) we probably need a specialized decorator
  that can relay to the store and from there to the branch or whatever is
  needed. This will also helps bzr config to get it right. The
  get_mutable_section trick should not be needed anymore either.

- decorate branch.unlock to call stack.save if last_lock() it True outside
  of @only_raises scope (evil decorator)

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
2884
2884
    def test_save_emptied_succeeds(self):
2885
2885
        store = self.get_store(self)
2886
2886
        store._load_from_string('foo=bar\n')
 
2887
        # FIXME: There should be a better way than relying on the test
 
2888
        # parametrization to identify branch.conf -- vila 2011-0526
 
2889
        if self.store_id in ('branch', 'remote_branch'):
 
2890
            # branch stores requires write locked branches
 
2891
            self.addCleanup(store.branch.lock_write().unlock)
2887
2892
        section = store.get_mutable_section(None)
2888
2893
        section.remove('foo')
2889
2894
        store.save()
2910
2915
 
2911
2916
    def test_set_option_in_empty_store(self):
2912
2917
        store = self.get_store(self)
 
2918
        # FIXME: There should be a better way than relying on the test
 
2919
        # parametrization to identify branch.conf -- vila 2011-0526
 
2920
        if self.store_id in ('branch', 'remote_branch'):
 
2921
            # branch stores requires write locked branches
 
2922
            self.addCleanup(store.branch.lock_write().unlock)
2913
2923
        section = store.get_mutable_section(None)
2914
2924
        section.set('foo', 'bar')
2915
2925
        store.save()
2921
2931
    def test_set_option_in_default_section(self):
2922
2932
        store = self.get_store(self)
2923
2933
        store._load_from_string('')
 
2934
        # FIXME: There should be a better way than relying on the test
 
2935
        # parametrization to identify branch.conf -- vila 2011-0526
 
2936
        if self.store_id in ('branch', 'remote_branch'):
 
2937
            # branch stores requires write locked branches
 
2938
            self.addCleanup(store.branch.lock_write().unlock)
2924
2939
        section = store.get_mutable_section(None)
2925
2940
        section.set('foo', 'bar')
2926
2941
        store.save()
2932
2947
    def test_set_option_in_named_section(self):
2933
2948
        store = self.get_store(self)
2934
2949
        store._load_from_string('')
 
2950
        # FIXME: There should be a better way than relying on the test
 
2951
        # parametrization to identify branch.conf -- vila 2011-0526
 
2952
        if self.store_id in ('branch', 'remote_branch'):
 
2953
            # branch stores requires write locked branches
 
2954
            self.addCleanup(store.branch.lock_write().unlock)
2935
2955
        section = store.get_mutable_section('baz')
2936
2956
        section.set('foo', 'bar')
2937
2957
        store.save()
2941
2961
        self.assertSectionContent(('baz', {'foo': 'bar'}), sections[0])
2942
2962
 
2943
2963
    def test_load_hook(self):
2944
 
        # We first needs to ensure that the store exists
 
2964
        # First, we need to ensure that the store exists
2945
2965
        store = self.get_store(self)
 
2966
        # FIXME: There should be a better way than relying on the test
 
2967
        # parametrization to identify branch.conf -- vila 2011-0526
 
2968
        if self.store_id in ('branch', 'remote_branch'):
 
2969
            # branch stores requires write locked branches
 
2970
            self.addCleanup(store.branch.lock_write().unlock)
2946
2971
        section = store.get_mutable_section('baz')
2947
2972
        section.set('foo', 'bar')
2948
2973
        store.save()
2964
2989
        config.ConfigHooks.install_named_hook('save', hook, None)
2965
2990
        self.assertLength(0, calls)
2966
2991
        store = self.get_store(self)
 
2992
        # FIXME: There should be a better way than relying on the test
 
2993
        # parametrization to identify branch.conf -- vila 2011-0526
 
2994
        if self.store_id in ('branch', 'remote_branch'):
 
2995
            # branch stores requires write locked branches
 
2996
            self.addCleanup(store.branch.lock_write().unlock)
2967
2997
        section = store.get_mutable_section('baz')
2968
2998
        section.set('foo', 'bar')
2969
2999
        store.save()
3687
3717
        super(TestStackExpandOptions, self).setUp()
3688
3718
        self.overrideAttr(config, 'option_registry', config.OptionRegistry())
3689
3719
        self.registry = config.option_registry
3690
 
        self.conf = build_branch_stack(self)
 
3720
        store = config.TransportIniFileStore(self.get_transport(), 'foo.conf')
 
3721
        self.conf = config.Stack([store.get_sections], store)
3691
3722
 
3692
3723
    def assertExpansion(self, expected, string, env=None):
3693
3724
        self.assertEquals(expected, self.conf.expand_options(string, env))