2941
2941
class TestStackGet(TestStackWithTransport):
2944
super(TestStackGet, self).setUp()
2945
self.conf = self.get_stack(self)
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'))
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')
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])
2960
self.assertEquals((self.conf, 'foo', 'bar'), calls[0])
2963
class TestStackGetWithConverter(TestStackGet):
2966
super(TestStackGetWithConverter, self).setUp()
2967
self.overrideAttr(config, 'option_registry', registry.Registry())
2968
self.registry = config.option_registry
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.')
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'))
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'))
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'))
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'))
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'))
2961
2998
class TestStackSet(TestStackWithTransport):