summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ipalib/config.py38
-rw-r--r--tests/test_ipalib/test_config.py19
2 files changed, 17 insertions, 40 deletions
diff --git a/ipalib/config.py b/ipalib/config.py
index 06ecb13f..8a23cde6 100644
--- a/ipalib/config.py
+++ b/ipalib/config.py
@@ -176,16 +176,6 @@ class Env(object):
def __islocked__(self):
return self.__locked
- def __getattr__(self, name):
- """
- Return the attribute named ``name``.
- """
- if name in self.__d:
- return self[name]
- raise AttributeError('%s.%s' %
- (self.__class__.__name__, name)
- )
-
def __setattr__(self, name, value):
"""
Set the attribute named ``name`` to ``value``.
@@ -204,12 +194,7 @@ class Env(object):
"""
Return the value corresponding to ``key``.
"""
- if key not in self.__d:
- raise KeyError(key)
- value = self.__d[key]
- if callable(value):
- return value()
- return value
+ return self.__d[key]
def __setitem__(self, key, value):
"""
@@ -224,17 +209,16 @@ class Env(object):
raise AttributeError('cannot overwrite %s.%s with %r' %
(self.__class__.__name__, key, value)
)
- if not callable(value):
- if isinstance(value, basestring):
- value = str(value.strip())
- if value.lower() == 'true':
- value = True
- elif value.lower() == 'false':
- value = False
- elif value.isdigit():
- value = int(value)
- assert type(value) in (str, int, bool)
- object.__setattr__(self, key, value)
+ if isinstance(value, basestring):
+ value = str(value.strip())
+ if value.lower() == 'true':
+ value = True
+ elif value.lower() == 'false':
+ value = False
+ elif value.isdigit():
+ value = int(value)
+ assert type(value) in (str, int, bool)
+ object.__setattr__(self, key, value)
self.__d[key] = value
def __contains__(self, key):
diff --git a/tests/test_ipalib/test_config.py b/tests/test_ipalib/test_config.py
index e17c4799..6c70aeb9 100644
--- a/tests/test_ipalib/test_config.py
+++ b/tests/test_ipalib/test_config.py
@@ -374,23 +374,16 @@ class test_Env(ClassChecker):
e = raises(StandardError, o.__lock__)
assert str(e) == 'Env.__lock__() already called'
- def test_getattr(self):
+ def test_getitem(self):
"""
- Test the `ipalib.config.Env.__getattr__` method.
-
- Also tests the `ipalib.config.Env.__getitem__` method.
+ Test the `ipalib.config.Env.__getitem__` method.
"""
o = self.cls()
value = 'some value'
o.key = value
assert o.key is value
assert o['key'] is value
- o.call = lambda: 'whatever'
- assert o.call == 'whatever'
- assert o['call'] == 'whatever'
for name in ('one', 'two'):
- e = raises(AttributeError, getattr, o, name)
- assert str(e) == 'Env.%s' % name
e = raises(KeyError, getitem, o, name)
assert str(e) == repr(name)
@@ -402,9 +395,9 @@ class test_Env(ClassChecker):
"""
items = [
('one', 1),
- ('two', lambda: 2),
+ ('two', 2),
('three', 3),
- ('four', lambda: 4),
+ ('four', 4),
]
for setvar in (setattr, setitem):
o = self.cls()
@@ -457,9 +450,9 @@ class test_Env(ClassChecker):
o = self.cls()
items = [
('one', 1),
- ('two', lambda: 2),
+ ('two', 2),
('three', 3),
- ('four', lambda: 4),
+ ('four', 4),
]
for (key, value) in items:
assert key not in o