~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-08-12 04:58:46 UTC
  • mfrom: (6059.1.3 boolean-option)
  • Revision ID: pqm@pqm.ubuntu.com-20110812045846-15hlipqj7f69wn7f
(vila) Implement boolean options. (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2937
2937
 
2938
2938
class TestStackGet(TestStackWithTransport):
2939
2939
 
 
2940
    def setUp(self):
 
2941
        super(TestStackGet, self).setUp()
 
2942
        self.conf = self.get_stack(self)
 
2943
 
2940
2944
    def test_get_for_empty_stack(self):
2941
 
        conf = self.get_stack(self)
2942
 
        self.assertEquals(None, conf.get('foo'))
 
2945
        self.assertEquals(None, self.conf.get('foo'))
2943
2946
 
2944
2947
    def test_get_hook(self):
2945
 
        conf = self.get_stack(self)
2946
 
        conf.store._load_from_string('foo=bar')
 
2948
        self.conf.store._load_from_string('foo=bar')
2947
2949
        calls = []
2948
2950
        def hook(*args):
2949
2951
            calls.append(args)
2950
2952
        config.ConfigHooks.install_named_hook('get', hook, None)
2951
2953
        self.assertLength(0, calls)
2952
 
        value = conf.get('foo')
 
2954
        value = self.conf.get('foo')
2953
2955
        self.assertEquals('bar', value)
2954
2956
        self.assertLength(1, calls)
2955
 
        self.assertEquals((conf, 'foo', 'bar'), calls[0])
 
2957
        self.assertEquals((self.conf, 'foo', 'bar'), calls[0])
 
2958
 
 
2959
 
 
2960
class TestStackGetWithConverter(TestStackGet):
 
2961
 
 
2962
    def setUp(self):
 
2963
        super(TestStackGetWithConverter, self).setUp()
 
2964
        self.overrideAttr(config, 'option_registry', config.OptionRegistry())
 
2965
        self.registry = config.option_registry
 
2966
 
 
2967
    def register_bool_option(self, name, default):
 
2968
        b = config.Option(name, default=default, help='A boolean.',
 
2969
                          from_unicode=config.bool_from_store)
 
2970
        self.registry.register(b)
 
2971
 
 
2972
    def test_get_with_bool_not_defined_default_true(self):
 
2973
        self.register_bool_option('foo', True)
 
2974
        self.assertEquals(True, self.conf.get('foo'))
 
2975
 
 
2976
    def test_get_with_bool_not_defined_default_false(self):
 
2977
        self.register_bool_option('foo', False)
 
2978
        self.assertEquals(False, self.conf.get('foo'))
 
2979
 
 
2980
    def test_get_with_bool_converter_not_default(self):
 
2981
        self.register_bool_option('foo', False)
 
2982
        self.conf.store._load_from_string('foo=yes')
 
2983
        self.assertEquals(True, self.conf.get('foo'))
 
2984
 
 
2985
    def test_get_with_bool_converter_invalid(self):
 
2986
        self.register_bool_option('foo', False)
 
2987
        self.conf.store._load_from_string('foo=not-a-boolean')
 
2988
        self.assertEquals(False, self.conf.get('foo'))
2956
2989
 
2957
2990
 
2958
2991
class TestStackSet(TestStackWithTransport):
3184
3217
        conf = config.AuthenticationConfig(_file=StringIO(
3185
3218
                'foo = bar\xff'))
3186
3219
        self.assertRaises(errors.ConfigContentError, conf._get_config)
3187
 
        
 
3220
 
3188
3221
    def test_missing_auth_section_header(self):
3189
3222
        conf = config.AuthenticationConfig(_file=StringIO('foo = bar'))
3190
3223
        self.assertRaises(ValueError, conf.get_credentials, 'ftp', 'foo.net')