~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
2940
2940
 
2941
2941
class TestStackGet(TestStackWithTransport):
2942
2942
 
 
2943
    def setUp(self):
 
2944
        super(TestStackGet, self).setUp()
 
2945
        self.conf = self.get_stack(self)
 
2946
 
2943
2947
    def test_get_for_empty_stack(self):
2944
 
        conf = self.get_stack(self)
2945
 
        self.assertEquals(None, conf.get('foo'))
 
2948
        self.assertEquals(None, self.conf.get('foo'))
2946
2949
 
2947
2950
    def test_get_hook(self):
2948
 
        conf = self.get_stack(self)
2949
 
        conf.store._load_from_string('foo=bar')
 
2951
        self.conf.store._load_from_string('foo=bar')
2950
2952
        calls = []
2951
2953
        def hook(*args):
2952
2954
            calls.append(args)
2953
2955
        config.ConfigHooks.install_named_hook('get', hook, None)
2954
2956
        self.assertLength(0, calls)
2955
 
        value = conf.get('foo')
 
2957
        value = self.conf.get('foo')
2956
2958
        self.assertEquals('bar', value)
2957
2959
        self.assertLength(1, calls)
2958
 
        self.assertEquals((conf, 'foo', 'bar'), calls[0])
2959
 
 
 
2960
        self.assertEquals((self.conf, 'foo', 'bar'), calls[0])
 
2961
 
 
2962
 
 
2963
class TestStackGetWithConverter(TestStackGet):
 
2964
 
 
2965
    def setUp(self):
 
2966
        super(TestStackGetWithConverter, self).setUp()
 
2967
        self.overrideAttr(config, 'option_registry', registry.Registry())
 
2968
        self.registry = config.option_registry
 
2969
 
 
2970
    def register_bool_option(self, name, default):
 
2971
        b = config.Option(name, default=default,
 
2972
                          from_unicode=config.bool_from_store)
 
2973
        self.registry.register(b.name, b,  help='A boolean.')
 
2974
 
 
2975
    def test_get_with_bool_not_defined_default_true(self):
 
2976
        self.register_bool_option('foo', True)
 
2977
        self.assertEquals(True, self.conf.get('foo'))
 
2978
 
 
2979
    def test_get_with_bool_not_defined_default_false(self):
 
2980
        self.register_bool_option('foo', False)
 
2981
        self.assertEquals(False, self.conf.get('foo'))
 
2982
 
 
2983
    def test_get_with_bool_converter_not_default(self):
 
2984
        self.register_bool_option('foo', False)
 
2985
        self.conf.store._load_from_string('foo=yes')
 
2986
        self.assertEquals(True, self.conf.get('foo'))
 
2987
 
 
2988
    def test_get_with_bool_converter_invalid_string(self):
 
2989
        self.register_bool_option('foo', False)
 
2990
        self.conf.store._load_from_string('foo=not-a-boolean')
 
2991
        self.assertEquals(False, self.conf.get('foo'))
 
2992
 
 
2993
    def test_get_with_bool_converter_invalid_list(self):
 
2994
        self.register_bool_option('foo', False)
 
2995
        self.conf.store._load_from_string('foo=not,a,boolean')
 
2996
        self.assertEquals(False, self.conf.get('foo'))
2960
2997
 
2961
2998
class TestStackSet(TestStackWithTransport):
2962
2999