~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

(vila) Allow callables to be used to specify config option default values
 (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2275
2275
        opt = config.Option('foo', default='bar')
2276
2276
        self.assertEquals('bar', opt.get_default())
2277
2277
 
 
2278
    def test_callable_default_value(self):
 
2279
        def bar_as_unicode():
 
2280
            return u'bar'
 
2281
        opt = config.Option('foo', default=bar_as_unicode)
 
2282
        self.assertEquals('bar', opt.get_default())
 
2283
 
2278
2284
    def test_default_value_from_env(self):
2279
2285
        opt = config.Option('foo', default='bar', default_from_env=['FOO'])
2280
2286
        self.overrideEnv('FOO', 'quux')
2296
2302
        self.assertRaises(AssertionError, config.Option, 'foo',
2297
2303
                          default=object())
2298
2304
 
 
2305
    def test_not_supported_callable_default_value_not_unicode(self):
 
2306
        def bar_not_unicode():
 
2307
            return 'bar'
 
2308
        opt = config.Option('foo', default=bar_not_unicode)
 
2309
        self.assertRaises(AssertionError, opt.get_default)
 
2310
 
2299
2311
 
2300
2312
class TestOptionConverterMixin(object):
2301
2313
 
2363
2375
        opt = self.get_option()
2364
2376
        self.assertConverted(16, opt, u'16')
2365
2377
 
 
2378
 
2366
2379
class TestOptionWithListConverter(tests.TestCase, TestOptionConverterMixin):
2367
2380
 
2368
2381
    def get_option(self):