[kernel] r13239 - in people/waldi/dkt/lib/dkt/config: . test
Bastian Blank
waldi at alioth.debian.org
Tue Mar 24 10:32:18 UTC 2009
Author: waldi
Date: Tue Mar 24 10:32:15 2009
New Revision: 13239
Log:
* lib/dkt/config/base.py
- Cleanup.
- Never raise exception in get methods.
* lib/dkt/config/test/test_base.py: Adopt to reality.
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 Tue Mar 24 10:32:15 2009
@@ -1,18 +1,17 @@
-#from __future__ import absolute_import
+from __future__ import absolute_import
-#from . import interfaces
-import interfaces
-from dkt.interface import implements
+from .interfaces import IConfig, IMutableConfig
+from ..interface import implements
+from ..support.ordered_dict import OrderedDict
_marker = object()
class Config(object):
- implements(interfaces.IConfig)
+ implements(IConfig)
__slots__ = '_sections'
- def __init__(self, default = {}):
- from dkt.support.ordered_dict import OrderedDict
+ def __init__(self, default={}):
self._sections = OrderedDict()
for section, options in default.iteritems():
@@ -30,19 +29,15 @@
return _marker
return o
- def get(self, section, option, default = _marker):
+ def get(self, section, option, default=None):
ret = self._get(section, option)
if ret is _marker:
- if default is _marker:
- raise KeyError(section + ':' + option)
return default
return ret
- def get_parse_boolean(self, section, option, default = _marker):
+ def get_parse_boolean(self, section, option, default=None):
s = self._get(section, option)
if s is _marker:
- if default is _marker:
- raise KeyError(section + ':' + option)
return default
s = s.lower()
if s in ('true', 'yes', '1'):
@@ -51,11 +46,9 @@
return False
raise ValueError(section + ':' + option)
- def get_section(self, section, default = _marker):
+ def get_section(self, section, default=None):
s = self._sections.get(section, _marker)
if s is _marker:
- if default is _marker:
- raise KeyError(section)
return default
ret = s.copy()
for key in s.iterkeys():
@@ -76,7 +69,7 @@
return self._sections.keys()
class MutableConfig(Config):
- implements(interfaces.IMutableConfig)
+ implements(IMutableConfig)
def add_section(self, section):
s = self._sections.get(section, _marker)
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 Tue Mar 24 10:32:15 2009
@@ -6,10 +6,10 @@
assert c.get('a', 'a') == 'a'
- py.test.raises(KeyError, c.get, 'a', 'b')
+ assert c.get('a', 'b') is None
assert c.get('a', 'b', 'b') == 'b'
- py.test.raises(KeyError, c.get, 'b', 'b')
+ assert c.get('b', 'b') is None
assert c.get('b', 'b', 'b') == 'b'
def test_get_section():
@@ -17,7 +17,7 @@
assert c.get_section('a') == {'a': 'a'}
- py.test.raises(KeyError, c.get_section, 'b')
+ assert c.get_section('b') is None
assert c.get_section('b', 'b') == 'b'
def test_options():
@@ -42,13 +42,13 @@
c.delete('a', 'a')
assert c.get_section('a') == {}
- py.test.raises(KeyError, c.get, 'a', 'a')
+ assert c.get('a', 'a') is None
def test_delete_section():
c = MutableConfig({'a': {}})
c.delete_section('a')
- py.test.raises(KeyError, c.get_section, 'a')
+ assert c.get_section('a') is None
def test_set():
c = MutableConfig({'a': {}})
More information about the Kernel-svn-changes
mailing list