Beispiel #1
0
    def configurable(self):
        Config.clear()
        Config.register_config('test', 'sec1', key1='val1',
                                       key2=ListConfigOption(['asdf', 'jkl;']))
        Config.register_config('test', 'sec2', key3='val3')

        @configurable(sec1=['key1', 'key2'], sec2=['key3'])
        class Lazy(object):
            pass
        lazy = Lazy()
        lazy._key1.should.equal('val1')
        lazy._sec1__key2.should.equal(['asdf', 'jkl;'])
        lazy._key3.should.equal('val3')
        noattr = lambda: lazy._noattr
        noattr.should.throw(AttributeError)
Beispiel #2
0
    def dict(self):
        class MyClass(object):

            def __init__(self, arg):
                self._arg = arg

            def __eq__(self, other):
                return self._arg == other._arg

        Config.clear()
        value = DictConfigOption('1:foo,2:boo', key_type=int,
                                 dictvalue_type=MyClass)
        Config.register_config('test', 'sec1', key1=value)
        conf = ConfigClient('sec1')
        conf('key1').should.equal({1: MyClass('foo'), 2: MyClass('boo')})
        conf('key1').should_not.equal({1: MyClass('afoo'), 2: MyClass('boo')})
Beispiel #3
0
 def dict_escape(self):
     Config.clear()
     value = DictConfigOption('a\:b:foo\:moo,a\,b:boo\,zoo')
     Config.register_config('test', 'sec1', key1=value)
     conf = ConfigClient('sec1')
     conf('key1').should.equal({'a:b': 'foo:moo', 'a,b': 'boo,zoo'})
Beispiel #4
0
 def file_size(self):
     Config.clear()
     Config.register_config('test', 'sec1',
                                    key1=FileSizeConfigOption('5.54G'))
     conf = ConfigClient('sec1')
     conf('key1').should.equal(5540000000)