~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-09 12:34:00 UTC
  • mfrom: (6056.2.5 option-registry)
  • Revision ID: pqm@pqm.ubuntu.com-20110809123400-x521f2j9jkxx8ze2
(vila) Introduce OptionRegistry (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2219
2219
    def setUp(self):
2220
2220
        super(TestOptionRegistry, self).setUp()
2221
2221
        # Always start with an empty registry
2222
 
        self.overrideAttr(config, 'option_registry', registry.Registry())
 
2222
        self.overrideAttr(config, 'option_registry', config.OptionRegistry())
2223
2223
        self.registry = config.option_registry
2224
2224
 
2225
2225
    def test_register(self):
2226
2226
        opt = config.Option('foo')
2227
 
        self.registry.register('foo', opt)
 
2227
        self.registry.register(opt)
2228
2228
        self.assertIs(opt, self.registry.get('foo'))
2229
2229
 
2230
 
    lazy_option = config.Option('lazy_foo')
2231
 
 
2232
 
    def test_register_lazy(self):
2233
 
        self.registry.register_lazy('foo', self.__module__,
2234
 
                                    'TestOptionRegistry.lazy_option')
2235
 
        self.assertIs(self.lazy_option, self.registry.get('foo'))
2236
 
 
2237
2230
    def test_registered_help(self):
2238
 
        opt = config.Option('foo')
2239
 
        self.registry.register('foo', opt, help='A simple option')
 
2231
        opt = config.Option('foo', help='A simple option')
 
2232
        self.registry.register(opt)
2240
2233
        self.assertEquals('A simple option', self.registry.get_help('foo'))
2241
2234
 
 
2235
    lazy_option = config.Option('lazy_foo', help='Lazy help')
 
2236
 
 
2237
    def test_register_lazy(self):
 
2238
        self.registry.register_lazy('lazy_foo', self.__module__,
 
2239
                                    'TestOptionRegistry.lazy_option')
 
2240
        self.assertIs(self.lazy_option, self.registry.get('lazy_foo'))
 
2241
 
 
2242
    def test_registered_lazy_help(self):
 
2243
        self.registry.register_lazy('lazy_foo', self.__module__,
 
2244
                                    'TestOptionRegistry.lazy_option')
 
2245
        self.assertEquals('Lazy help', self.registry.get_help('lazy_foo'))
 
2246
 
2242
2247
 
2243
2248
class TestRegisteredOptions(tests.TestCase):
2244
2249
    """All registered options should verify some constraints."""
2258
2263
    def test_help_is_set(self):
2259
2264
        option_help = self.registry.get_help(self.option_name)
2260
2265
        self.assertNotEquals(None, option_help)
2261
 
        # Come on, think about the user, he really wants to know whst the
 
2266
        # Come on, think about the user, he really wants to know what the
2262
2267
        # option is about
 
2268
        self.assertIsNot(None, option_help)
2263
2269
        self.assertNotEquals('', option_help)
2264
2270
 
2265
2271
 
2866
2872
    # FIXME: This should be parametrized for all known Stack or dedicated
2867
2873
    # paramerized tests created to avoid bloating -- vila 2011-03-31
2868
2874
 
 
2875
    def overrideOptionRegistry(self):
 
2876
        self.overrideAttr(config, 'option_registry', config.OptionRegistry())
 
2877
 
2869
2878
    def test_single_config_get(self):
2870
2879
        conf = dict(foo='bar')
2871
2880
        conf_stack = config.Stack([conf])
2874
2883
    def test_get_with_registered_default_value(self):
2875
2884
        conf_stack = config.Stack([dict()])
2876
2885
        opt = config.Option('foo', default='bar')
2877
 
        self.overrideAttr(config, 'option_registry', registry.Registry())
 
2886
        self.overrideOptionRegistry()
2878
2887
        config.option_registry.register('foo', opt)
2879
2888
        self.assertEquals('bar', conf_stack.get('foo'))
2880
2889
 
2881
2890
    def test_get_without_registered_default_value(self):
2882
2891
        conf_stack = config.Stack([dict()])
2883
2892
        opt = config.Option('foo')
2884
 
        self.overrideAttr(config, 'option_registry', registry.Registry())
 
2893
        self.overrideOptionRegistry()
2885
2894
        config.option_registry.register('foo', opt)
2886
2895
        self.assertEquals(None, conf_stack.get('foo'))
2887
2896
 
2888
2897
    def test_get_without_default_value_for_not_registered(self):
2889
2898
        conf_stack = config.Stack([dict()])
2890
2899
        opt = config.Option('foo')
2891
 
        self.overrideAttr(config, 'option_registry', registry.Registry())
 
2900
        self.overrideOptionRegistry()
2892
2901
        self.assertEquals(None, conf_stack.get('foo'))
2893
2902
 
2894
2903
    def test_get_first_definition(self):