~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Vincent Ladeuil
  • Date: 2011-08-09 09:27:46 UTC
  • mto: This revision was merged to the branch mainline in revision 6059.
  • Revision ID: v.ladeuil+lp@free.fr-20110809092746-ly54u54pnykkes8p
Option help is now part of the object itself.

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."""
2866
2871
    # FIXME: This should be parametrized for all known Stack or dedicated
2867
2872
    # paramerized tests created to avoid bloating -- vila 2011-03-31
2868
2873
 
 
2874
    def overrideOptionRegistry(self):
 
2875
        self.overrideAttr(config, 'option_registry', config.OptionRegistry())
 
2876
 
2869
2877
    def test_single_config_get(self):
2870
2878
        conf = dict(foo='bar')
2871
2879
        conf_stack = config.Stack([conf])
2874
2882
    def test_get_with_registered_default_value(self):
2875
2883
        conf_stack = config.Stack([dict()])
2876
2884
        opt = config.Option('foo', default='bar')
2877
 
        self.overrideAttr(config, 'option_registry', registry.Registry())
 
2885
        self.overrideOptionRegistry()
2878
2886
        config.option_registry.register('foo', opt)
2879
2887
        self.assertEquals('bar', conf_stack.get('foo'))
2880
2888
 
2881
2889
    def test_get_without_registered_default_value(self):
2882
2890
        conf_stack = config.Stack([dict()])
2883
2891
        opt = config.Option('foo')
2884
 
        self.overrideAttr(config, 'option_registry', registry.Registry())
 
2892
        self.overrideOptionRegistry()
2885
2893
        config.option_registry.register('foo', opt)
2886
2894
        self.assertEquals(None, conf_stack.get('foo'))
2887
2895
 
2888
2896
    def test_get_without_default_value_for_not_registered(self):
2889
2897
        conf_stack = config.Stack([dict()])
2890
2898
        opt = config.Option('foo')
2891
 
        self.overrideAttr(config, 'option_registry', registry.Registry())
 
2899
        self.overrideOptionRegistry()
2892
2900
        self.assertEquals(None, conf_stack.get('foo'))
2893
2901
 
2894
2902
    def test_get_first_definition(self):