2938
2938
class TestStackGet(TestStackWithTransport):
2941
super(TestStackGet, self).setUp()
2942
self.conf = self.get_stack(self)
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'))
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')
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])
2960
class TestStackGetWithConverter(TestStackGet):
2963
super(TestStackGetWithConverter, self).setUp()
2964
self.overrideAttr(config, 'option_registry', config.OptionRegistry())
2965
self.registry = config.option_registry
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)
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'))
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'))
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'))
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'))
2958
2991
class TestStackSet(TestStackWithTransport):