summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-10-24 20:21:27 -0600
committerJason Gerard DeRose <jderose@redhat.com>2008-10-24 20:21:27 -0600
commit759734864e72c209d62c970d2e325e96ae02fcb7 (patch)
tree1ae0f515d87ef62a0e85eb2de1f1e98b1a064cf8
parentac4efac3944d180cffd0ad9d63f631dc928e1d28 (diff)
downloadfreeipa-759734864e72c209d62c970d2e325e96ae02fcb7.tar.gz
freeipa-759734864e72c209d62c970d2e325e96ae02fcb7.tar.xz
freeipa-759734864e72c209d62c970d2e325e96ae02fcb7.zip
Finished Env._finalize() and corresponding unit tests
-rw-r--r--ipalib/config.py14
-rw-r--r--tests/test_ipalib/test_config.py23
2 files changed, 31 insertions, 6 deletions
diff --git a/ipalib/config.py b/ipalib/config.py
index bced62fda..71d3024cd 100644
--- a/ipalib/config.py
+++ b/ipalib/config.py
@@ -168,7 +168,7 @@ class Env(object):
and the location of the configuration file.
"""
self.__doing('_bootstrap')
- for (key, value) in overrides.items():
+ for (key, value) in overrides.iteritems():
self[key] = value
if 'in_tree' not in self:
if self.bin == self.site_packages and \
@@ -209,11 +209,11 @@ class Env(object):
self.log = path.join(self.dot_ipa, 'log', name)
else:
self.log = path.join('/', 'var', 'log', 'ipa', name)
- for (key, value) in defaults.items():
+ for (key, value) in defaults.iteritems():
if key not in self:
self[key] = value
- def _finalize(self):
+ def _finalize(self, **lastchance):
"""
Finalize and lock environment.
@@ -222,11 +222,14 @@ class Env(object):
"""
self.__doing('_finalize')
self.__do_if_not_done('_finalize_core')
+ for (key, value) in lastchance.iteritems():
+ if key not in self:
+ self[key] = value
self.__lock__()
def _merge_config(self, conf_file):
"""
- Merge in values from ``conf_file`` into this `Env`.
+ Merge values from ``conf_file`` into this `Env`.
"""
section = constants.CONFIG_SECTION
if not path.isfile(conf_file):
@@ -258,6 +261,9 @@ class Env(object):
)
object.__setattr__(self, '_Env__locked', True)
+ def __islocked__(self):
+ return self.__locked
+
def __getattr__(self, name):
"""
Return the attribute named ``name``.
diff --git a/tests/test_ipalib/test_config.py b/tests/test_ipalib/test_config.py
index b4c86319f..6136bdf0b 100644
--- a/tests/test_ipalib/test_config.py
+++ b/tests/test_ipalib/test_config.py
@@ -170,8 +170,8 @@ key3 = var3
config_good = """
[global]
-yes = TRUE
-no = False
+yes = tRUE
+no = fALse
number = 42
"""
@@ -357,6 +357,25 @@ class test_Env(ClassChecker):
e = raises(StandardError, o._finalize)
assert str(e) == 'Env._finalize() already called'
+ # Check that _finalize() calls __lock__()
+ (o, home) = self.new()
+ assert o.__islocked__() is False
+ o._finalize()
+ assert o.__islocked__() is True
+ e = raises(StandardError, o.__lock__)
+ assert str(e) == 'Env.__lock__() already called'
+
+ # Check that **lastchance works
+ (o, home) = self.finalize_core()
+ key = 'just_one_more_key'
+ value = 'with one more value'
+ lastchance = {key: value}
+ assert key not in o
+ assert o._isdone('_finalize') is False
+ o._finalize(**lastchance)
+ assert key in o
+ assert o[key] is value
+
def test_merge_config(self):
"""
Test the `ipalib.config.Env._merge_config` method.