]> mj.ucw.cz Git - moe.git/commitdiff
Made ConfigTree.fix take list os well, added test
authorTomas Gavenciak <gavento@ucw.cz>
Sat, 11 Sep 2010 16:35:09 +0000 (18:35 +0200)
committerTomas Gavenciak <gavento@ucw.cz>
Sat, 11 Sep 2010 16:35:09 +0000 (18:35 +0200)
t/moe/config.py
t/moe/config_test.py

index d17d1c8af7e7ccf75d236f3f120ac169230ffd3f..1de679904a3b8a92f1ed3fdf19ffdb02408042dd 100644 (file)
@@ -94,9 +94,12 @@ class ConfigTree(object):
       self.variables[k].dump(prefix) for k in sorted(self.variables.keys())
       ])
 
-  def fix(self, key):
-    "Fix variable value. Fixing undefined variable raises `UndefinedError`."
-    self.lookup(key, create=True).fix()
+  def fix(self, keys):
+    "Fix value of variable or list of variables. Fixing undefined variable raises `UndefinedError`."
+    if isinstance(keys, types.StringTypes):
+      keys = [keys]
+    for key in keys:
+      self.lookup(key, create=True).fix()
 
   def parse(self, s, source=None, level=0):
     """Parse `s` (stream/string) into the tree, see `moe.confparser.ConfigParser` for details."""
index 573934f11c6482f243f2e467d679fe3b67d8e669..b0ba61254a730b0c17ca7d150f17138f19bda33c 100644 (file)
@@ -188,6 +188,13 @@ class TestConfigEval(TestConfig):
     assert s.val('E') == '41'
     s.var('D').remove_operation(l[0][1])
     assert s.val('D') == '42'
+    # Fixing via ConfigTree.fix
+    s.t.fix('D')
+    s.t.fix(['E','A'])
+    s.parse('D=""; E=""; A=""; ')
+    s.assertRaises(cf.VariableFixedError, s.val, "D")
+    s.assertRaises(cf.VariableFixedError, s.val, "E")
+    s.assertRaises(cf.VariableFixedError, s.val, "A")
 
   def test_unicode(s):
     # Ascii (1b) and unicode (2b)