[kernel] r9407 - in people/waldi/dkt/lib/dkt/config: . test
Bastian Blank
waldi at alioth.debian.org
Wed Aug 29 09:32:08 UTC 2007
Author: waldi
Date: Wed Aug 29 09:32:08 2007
New Revision: 9407
Log:
* lib/dkt/config/base.py: Support initialization.
* lib/dkt/config/test/test_base.py: Update.
Modified:
people/waldi/dkt/lib/dkt/config/base.py
people/waldi/dkt/lib/dkt/config/test/test_base.py
Modified: people/waldi/dkt/lib/dkt/config/base.py
==============================================================================
--- people/waldi/dkt/lib/dkt/config/base.py (original)
+++ people/waldi/dkt/lib/dkt/config/base.py Wed Aug 29 09:32:08 2007
@@ -10,10 +10,13 @@
__slots__ = '_sections'
- def __init__(self):
+ def __init__(self, default = {}):
from dkt.support.ordered_dict import OrderedDict
self._sections = OrderedDict()
+ for section, options in default.iteritems():
+ self._sections[section] = dict(options)
+
def __iter__(self):
return self._sections.iterkeys()
Modified: people/waldi/dkt/lib/dkt/config/test/test_base.py
==============================================================================
--- people/waldi/dkt/lib/dkt/config/test/test_base.py (original)
+++ people/waldi/dkt/lib/dkt/config/test/test_base.py Wed Aug 29 09:32:08 2007
@@ -2,8 +2,7 @@
from dkt.config.base import *
def test_get():
- c = Config()
- c._sections = {'a': {'a': 'a'}}
+ c = Config({'a': {'a': 'a'}})
assert c.get('a', 'a') == 'a'
@@ -14,8 +13,7 @@
assert c.get('b', 'b', 'b') == 'b'
def test_get_section():
- c = Config()
- c._sections = {'a': {'a': 'a'}}
+ c = Config({'a': {'a': 'a'}})
assert c.get_section('a') == {'a': 'a'}
@@ -23,43 +21,37 @@
assert c.get_section('b', 'b') == 'b'
def test_options():
- c = Config()
- c._sections = {'a': {'a': 'a'}}
+ c = Config({'a': {'a': 'a'}})
assert c.options('a') == ['a']
py.test.raises(KeyError, c.options, 'b')
def test_sections():
- c = Config()
- c._sections = {'a': {'a': 'a'}}
+ c = Config({'a': {'a': 'a'}})
assert c.sections() == ['a']
def test_add_section():
c = MutableConfig()
- c._sections = {}
c.add_section('a')
assert c.get_section('a') == {}
def test_delete():
- c = MutableConfig()
- c._sections = {'a': {'a': 'a'}}
+ c = MutableConfig({'a': {'a': 'a'}})
c.delete('a', 'a')
assert c.get_section('a') == {}
py.test.raises(KeyError, c.get, 'a', 'a')
def test_delete_section():
- c = MutableConfig()
- c._sections = {'a': {}}
+ c = MutableConfig({'a': {}})
c.delete_section('a')
py.test.raises(KeyError, c.get_section, 'a')
def test_set():
- c = MutableConfig()
- c._sections = {'a': {}}
+ c = MutableConfig({'a': {}})
c.set('a', 'a', 'a')
assert c.get('a', 'a') == 'a'
More information about the Kernel-svn-changes
mailing list